Skip to content

Commit

Permalink
[iOS] Fix crash when dismissing news opt-in on NTP (uplift to 1.71.x) (
Browse files Browse the repository at this point in the history
…#26237)

Uplift of #26228 (squashed) to release
  • Loading branch information
brave-builds authored Oct 26, 2024
1 parent fab758f commit ae30f5b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
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

0 comments on commit ae30f5b

Please sign in to comment.