Skip to content
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

iOS] Fix crash when dismissing news opt-in on NTP (uplift to 1.70.x) #26234

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class NewTabPageFlowLayout: UICollectionViewFlowLayout {

lastSizedElementMinY = nil
lastSizedElementPreferredHeight = nil
} else {
gapLength = 0
extraHeight = 0
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,26 +772,9 @@ class NewTabPageViewController: UIViewController {
collectionView.deleteItems(at: [IndexPath(item: 0, section: section)])
}

// We check if first item exists before scrolling up to it.
// This should never happen since first item is our shields stats view.
// However we saw it crashing in XCode logs, see #4202.
let firstItemIndexPath = IndexPath(item: 0, section: 0)
if let itemCount = collectionView.dataSource?.collectionView(
collectionView,
numberOfItemsInSection: 0
),
itemCount > 0, // Only scroll if the section has items, otherwise it will crash.
collectionView.dataSource?
.collectionView(collectionView, cellForItemAt: firstItemIndexPath) != nil
{
collectionView.scrollToItem(at: firstItemIndexPath, at: .top, animated: true)
} else {
// Cannot scorll to deleted item index.
// Collection-View datasource never changes or updates
// Therefore we need to scroll to offset 0.
// See: #4575.
collectionView.setContentOffset(.zero, animated: true)
}
// scroll to offset .zero to preserve padding above section
collectionView.setContentOffset(.zero, animated: true)
backgroundButtonsView.setNeedsLayout()
collectionView.verticalScrollIndicatorInsets = .zero
UIView.animate(withDuration: 0.25) {
self.feedOverlayView.headerView.alpha = 0.0
Expand Down
Loading