Skip to content

Commit

Permalink
scroll to month can now be not animated
Browse files Browse the repository at this point in the history
  • Loading branch information
ThasianX committed Jul 3, 2020
1 parent 631fea7 commit 3c4b9f4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/ThasianX/ElegantPages",
"state": {
"branch": null,
"revision": "890aa0e01dcd04bf77ae8250dd6fc6c9228f54bf",
"version": "1.0.0"
"revision": "450ed57eed98174448929918342889b255c664d1",
"version": "1.1.0"
}
}
]
Expand Down
13 changes: 13 additions & 0 deletions Example/Example/Individual Views/ExampleMonthlyCalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct ExampleMonthlyCalendarView: View {
initialMonth: .daysFromToday(30))
visitsByDay = Dictionary(grouping: ascVisits, by: { currentCalendar.startOfDay(for: $0.arrivalDate) })
calendarManager.datasource = self
calendarManager.delegate = self
}

var body: some View {
Expand Down Expand Up @@ -44,6 +45,18 @@ extension ExampleMonthlyCalendarView: ElegantCalendarDataSource {

}

extension ExampleMonthlyCalendarView: ElegantCalendarDelegate {

func calendar(willDisplayMonth date: Date) {
print("Will show month: \(date)")
}

func calendar(didSelectDate date: Date) {
print("Selected date: \(date)")
}

}

struct ExampleMonthlyCalendarView_Previews: PreviewProvider {
static var previews: some View {
ExampleYearlyCalendarView(ascVisits: Visit.mocks(start: .daysFromToday(-365*2), end: .daysFromToday(365*2)))
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/ThasianX/ElegantPages",
"state": {
"branch": null,
"revision": "bf870757cb2f886ef0697d75111a3e99d39fe5f5",
"version": "1.0.1"
"revision": "450ed57eed98174448929918342889b255c664d1",
"version": "1.1.0"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public class ElegantCalendarManager: ObservableObject {
}.store(in: &anyCancellable)
}

public func scrollToMonth(_ month: Date) {
monthlyManager.scrollToMonth(month)
public func scrollToMonth(_ month: Date, animated: Bool = true) {
monthlyManager.scrollToMonth(month, animated: animated)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ extension MonthlyCalendarManager {
delegate?.calendar(didSelectDate: day)
}

public func scrollToMonth(_ month: Date) {
func scrollToMonth(_ month: Date, animated: Bool = true) {
if !calendar.isDate(currentMonth, equalTo: month, toGranularities: [.month, .year]) {
let page = calendar.monthsBetween(startDate, and: month)
pagerManager.scroll(to: page)
pagerManager.scroll(to: page, animated: animated)
}
}

Expand Down

0 comments on commit 3c4b9f4

Please sign in to comment.