Skip to content

Commit

Permalink
Add ability to set custom offset in to the stopEachSection scroll mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Leta0n committed Mar 5, 2018
1 parent e5f7945 commit 607a4a2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ViewController: UIViewController {
}

@IBAction func scrollFixed(_ sender: Any) {
calendarView.scrollingMode = .stopAtEachSection
calendarView.scrollingMode = .stopAtEachSection(customOffset: 0)
}
@IBAction func showPrepost(_ sender: UIButton) {
prePostVisibility = {state, cell in
Expand Down
4 changes: 2 additions & 2 deletions Sources/CalendarEnums.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public enum ReadingOrientation {
public enum ScrollingMode: Equatable {
/// stopAtEachCalendarFrame - non-continuous scrolling that will stop at each frame
case stopAtEachCalendarFrame
/// stopAtEachSection - non-continuous scrolling that will stop at each section
case stopAtEachSection
/// stopAtEachSection - non-continuous scrolling that will stop at each section with custom offset
case stopAtEachSection(customOffset: CGFloat)
/// stopAtEach - non-continuous scrolling that will stop at each custom interval
case stopAtEach(customInterval: CGFloat)
/// nonStopToSection - continuous scrolling that will stop at a section
Expand Down
4 changes: 2 additions & 2 deletions Sources/UIScrollViewDelegates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ extension JTAppleCalendarView: UIScrollViewDelegate {
setTargetContentOffset(scrollDirection == .horizontal ? targetContentOffset.pointee.x : targetContentOffset.pointee.y)
#endif
break
case .stopAtEachSection:
case .stopAtEachSection(let offset):
var calculatedOffSet: CGFloat = 0
if scrollDirection == .horizontal ||
(scrollDirection == .vertical && !calendarViewLayout.thereAreHeaders && cachedConfiguration.generateOutDates == .tillEndOfGrid) {
Expand All @@ -148,7 +148,7 @@ extension JTAppleCalendarView: UIScrollViewDelegate {
}
}
}
setTargetContentOffset(calculatedOffSet)
setTargetContentOffset(calculatedOffSet + offset)
case .nonStopToSection, .nonStopToCell, .nonStopTo:
let diff = abs(theTargetContentOffset - contentOffset)
let targetSection = calendarLayout.sectionFromOffset(theTargetContentOffset)
Expand Down

0 comments on commit 607a4a2

Please sign in to comment.