Skip to content

Commit

Permalink
use correct section index when scrolling to current event card
Browse files Browse the repository at this point in the history
  • Loading branch information
joewalsh authored and Natalia Harateh committed Oct 12, 2018
1 parent 0b032ec commit 211fed9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Wikipedia/Code/OnThisDayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ class OnThisDayViewController: ColumnarCollectionViewController, ReadingListHint
}

func scrollToInitialEvent() {
guard let event = initialEvent, let index = events.index(of: event), events.indices.contains(index) else {
guard let event = initialEvent, let eventIndex = events.index(of: event), events.indices.contains(eventIndex) else {
return
}
collectionView.scrollToItem(at: IndexPath(item: 0, section: index), at: index < 1 ? .top : .centeredVertically, animated: false)
let sectionIndex = eventIndex + 1 // index + 1 because section 0 is the header
collectionView.scrollToItem(at: IndexPath(item: 0, section: sectionIndex), at: sectionIndex < 1 ? .top : .centeredVertically, animated: false)
}

override func scrollViewInsetsDidChange() {
Expand Down

0 comments on commit 211fed9

Please sign in to comment.