Skip to content

Commit

Permalink
Merge pull request #135 from joeljfischer/bug/issue_127_overscroll
Browse files Browse the repository at this point in the history
Fix overscroll on TimelineContainer
  • Loading branch information
richardtop authored Feb 7, 2018
2 parents 641b437 + 01f9a1a commit a4269ba
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Source/Timeline/TimelineContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ public class TimelineContainer: UIScrollView, ReusableView {

public func scrollToFirstEvent() {
if let yToScroll = timeline.firstEventYPosition {
setContentOffset(CGPoint(x: contentOffset.x, y: yToScroll - 15), animated: true)
setTimelineOffset(CGPoint(x: contentOffset.x, y: yToScroll - 15), animated: true)
}
}

public func scrollTo(hour24: Float) {
let percentToScroll = CGFloat(hour24 / 24)
let yToScroll = contentSize.height * percentToScroll
let padding: CGFloat = 8
setContentOffset(CGPoint(x: contentOffset.x, y: yToScroll - padding), animated: true)
setTimelineOffset(CGPoint(x: contentOffset.x, y: yToScroll - padding), animated: true)
}

private func setTimelineOffset(_ offset: CGPoint, animated: Bool) {
let yToScroll = offset.y
let bottomOfScrollView = contentSize.height - bounds.size.height
let newContentY = (yToScroll < bottomOfScrollView) ? yToScroll : bottomOfScrollView
setContentOffset(CGPoint(x: offset.x, y: newContentY), animated: animated)
}
}

0 comments on commit a4269ba

Please sign in to comment.