-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Stats: Improve scrolling performance #22847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
staskus
merged 15 commits into
trunk
from
task/22721-stats-traffic-improve-scrolling-performance
Jun 21, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
98d5b77
Optimize TopTotalsCell to add rows only when the cell loads
staskus 9880cb7
Optimize CountriesCell to add rows only when the cell loads
staskus 9252c6f
Do not track StatsTraffic tableView scrolling
staskus 8fb2eb4
Merge branch 'trunk' into task/22721-stats-traffic-improve-scrolling-…
staskus d0af997
Update RELEASE-NOTES.txt
staskus eb7c142
Update TopTotalsCell to use setNeedsLayout for more efficiency
staskus 2674401
Update CountriesCell to use setNeedsLayout for more efficiency
staskus 8884f81
Merge branch 'trunk' into task/22721-stats-traffic-improve-scrolling-…
staskus 25bf46d
Update RELEASE-NOTES
staskus 7684a35
Move additional checks for adding default rows into the extension
staskus 51992ab
Remove force layout calls when setting subtitle visibility
staskus 89fd816
Make maximum content size category smaller for stats cell subtitles
staskus 1b8bc1c
Create StatsRowsCell with default child stack view rows and ability t…
staskus bc88b72
Put analyticsTracker back since it's used by JetpackBanner
staskus 465047a
Merge branch 'trunk' into task/22721-stats-traffic-improve-scrolling-…
staskus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
WordPress/Classes/ViewRelated/Stats/Shared Views/Stats Detail/StatsRowsCell.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import Foundation | ||
|
|
||
| class StatsRowsCell: StatsBaseCell { | ||
| struct StatsTotalRowConfiguration { | ||
| let limitRowsDisplayed: Bool | ||
| let rowDelegate: StatsTotalRowDelegate? | ||
| let referrerDelegate: StatsTotalRowReferrerDelegate? | ||
| let viewMoreDelegate: ViewMoreRowDelegate? | ||
| } | ||
|
|
||
| @IBOutlet weak var rowsStackView: UIStackView! | ||
|
|
||
| override func awakeFromNib() { | ||
| super.awakeFromNib() | ||
|
|
||
| addDefaultTotalRows(toStackView: rowsStackView) | ||
| } | ||
|
|
||
| func configureTotalRows(_ dataRows: [StatsTotalRowData], | ||
| inStackView rowsStackView: UIStackView, | ||
| forType statType: StatType, | ||
| configuration: StatsTotalRowConfiguration) { | ||
| if rowsStackView.arrangedSubviews.isEmpty { | ||
| addDefaultTotalRows(toStackView: rowsStackView) | ||
| } | ||
|
|
||
| guard !dataRows.isEmpty else { | ||
| configureForNoData(inStackView: rowsStackView, forType: statType) | ||
| return | ||
| } | ||
|
|
||
| let numberOfRowsToAdd = calculateNumberOfRowsToAdd(from: dataRows, withConfiguration: configuration) | ||
|
|
||
| rowsStackView.arrangedSubviews.enumerated().forEach { index, view in | ||
| configure(view: view, at: index, in: dataRows, numberOfRowsToAdd: numberOfRowsToAdd, configuration: configuration) | ||
| } | ||
| } | ||
|
|
||
| private func addDefaultTotalRows(toStackView rowsStackView: UIStackView) { | ||
| for _ in 0..<StatsDataHelper.maxRowsToDisplay { | ||
| let row = StatsTotalRow.loadFromNib() | ||
| rowsStackView.addArrangedSubview(row) | ||
| } | ||
|
|
||
| let emptyRow = StatsNoDataRow.loadFromNib() | ||
| rowsStackView.addArrangedSubview(emptyRow) | ||
|
|
||
| let viewMoreRow = ViewMoreRow.loadFromNib() | ||
| rowsStackView.addArrangedSubview(viewMoreRow) | ||
| } | ||
|
|
||
| private func configureForNoData(inStackView rowsStackView: UIStackView, forType statType: StatType) { | ||
| rowsStackView.arrangedSubviews.forEach { view in | ||
| if let emptyRow = view as? StatsNoDataRow { | ||
| emptyRow.isHidden = false | ||
| emptyRow.configure(forType: statType) | ||
| } else { | ||
| view.isHidden = true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private func calculateNumberOfRowsToAdd(from dataRows: [StatsTotalRowData], withConfiguration configuration: StatsTotalRowConfiguration) -> Int { | ||
| if configuration.limitRowsDisplayed { | ||
| return min(dataRows.count, StatsDataHelper.maxRowsToDisplay) | ||
| } | ||
| return dataRows.count | ||
| } | ||
|
|
||
| private func configure(view: UIView, at index: Int, in dataRows: [StatsTotalRowData], numberOfRowsToAdd: Int, configuration: StatsTotalRowConfiguration) { | ||
| switch view { | ||
| case let view as StatsNoDataRow: | ||
| view.isHidden = true | ||
| case let view as ViewMoreRow: | ||
| configureViewMoreRow(view, at: index, in: dataRows, withConfiguration: configuration) | ||
| case let view as StatsTotalRow where index < dataRows.count: | ||
| view.isHidden = false | ||
| let dataRow = dataRows[index] | ||
| view.configure(rowData: dataRow, delegate: configuration.rowDelegate, referrerDelegate: configuration.referrerDelegate) | ||
| view.showSeparator = index != (numberOfRowsToAdd - 1) | ||
| default: | ||
| view.isHidden = true | ||
| } | ||
| } | ||
|
|
||
| private func configureViewMoreRow(_ viewMoreRow: ViewMoreRow, at index: Int, in dataRows: [StatsTotalRowData], withConfiguration configuration: StatsTotalRowConfiguration) { | ||
| let shouldShowViewMore = configuration.limitRowsDisplayed && dataRows.count > StatsDataHelper.maxRowsToDisplay | ||
| viewMoreRow.isHidden = !shouldShowViewMore | ||
| if shouldShowViewMore { | ||
| viewMoreRow.configure(statSection: dataRows.first?.statSection, delegate: configuration.viewMoreDelegate) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.