diff --git a/iOS/MainTimeline/MainTimelineViewController.swift b/iOS/MainTimeline/MainTimelineViewController.swift index 31103833a..7e9bb185e 100644 --- a/iOS/MainTimeline/MainTimelineViewController.swift +++ b/iOS/MainTimeline/MainTimelineViewController.swift @@ -29,6 +29,7 @@ final class MainTimelineViewController: UIViewController, UndoableCommandRunner private var markReadBehavior = AppDefaults.markReadBehavior { didSet { if markReadBehavior != oldValue { + updateBottomPaddingForMarkReadOnScroll() noteRowsScrolledPast() } } @@ -244,6 +245,7 @@ final class MainTimelineViewController: UIViewController, UndoableCommandRunner override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() updateToolbarProgressView() + updateBottomPaddingForMarkReadOnScroll() coordinator?.timelineDidLayout() } @@ -611,6 +613,11 @@ extension MainTimelineViewController: UICollectionViewDelegate { } } + /// The navigation bar’s height changes as the search bar collapses and expands. + func scrollViewDidChangeAdjustedContentInset(_ scrollView: UIScrollView) { + updateBottomPaddingForMarkReadOnScroll() + } + func scrollViewDidScroll(_ scrollView: UIScrollView) { guard markReadBehavior == .selectionAndScrolledPast else { return @@ -1154,6 +1161,21 @@ private extension MainTimelineViewController { private extension MainTimelineViewController { + /// Adds empty space after the last row, the height of the area between the navigation bar and the toolbar, so every row can scroll under the navigation bar. + func updateBottomPaddingForMarkReadOnScroll() { + guard let collectionView else { + return + } + var bottomPadding: CGFloat = 0 + if markReadBehavior == .selectionAndScrolledPast { + let systemBottomInset = collectionView.adjustedContentInset.bottom - collectionView.contentInset.bottom + bottomPadding = max(0, collectionView.bounds.height - collectionView.adjustedContentInset.top - systemBottomInset) + } + if collectionView.contentInset.bottom != bottomPadding { + collectionView.contentInset.bottom = bottomPadding + } + } + /// Rows at least `scrolledPastFraction` under the navigation bar or above it. func numberOfRowsScrolledPast() -> Int { guard let collectionView else {