Skip to content

Commit

Permalink
added haptic in configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ThasianX committed Jul 10, 2020
1 parent ca2f066 commit be23298
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ public struct CalendarConfiguration: Equatable {

public let calendar: Calendar
public let ascending: Bool
public let allowHaptics: Bool
public let startDate: Date
public let endDate: Date
public let themeColor: Color

public init(calendar: Calendar = .current, ascending: Bool = true, startDate: Date, endDate: Date, themeColor: Color) {
public init(calendar: Calendar = .current, ascending: Bool = true, allowHaptics: Bool = true, startDate: Date, endDate: Date, themeColor: Color) {
self.calendar = calendar
self.ascending = ascending
self.allowHaptics = allowHaptics
self.startDate = startDate
self.endDate = endDate
self.themeColor = themeColor
Expand Down Expand Up @@ -45,6 +47,10 @@ extension ConfigurationDirectAccess {
configuration.calendar
}

var allowHaptics: Bool {
configuration.allowHaptics
}

var startDate: Date {
configuration.startDate
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension MonthlyCalendarManager: ElegantPagesDelegate {

delegate?.calendar(willDisplayMonth: currentMonth)

if isHapticActive {
if allowHaptics && isHapticActive {
UIImpactFeedbackGenerator.generateSelectionHaptic()
} else {
isHapticActive = true
Expand Down
6 changes: 4 additions & 2 deletions Sources/ElegantCalendar/Views/Monthly/DayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ struct DayView: View, MonthlyCalendarManagerDirectAccess {
private func notifyManager() {
guard isDayWithinDateRange else { return }

UIImpactFeedbackGenerator.generateSelectionHaptic()

if isDayToday || isDayWithinWeekMonthAndYear {
if configuration.allowHaptics {
UIImpactFeedbackGenerator.generateSelectionHaptic()
}

calendarManager.dayTapped(day: day)
}
}
Expand Down

0 comments on commit be23298

Please sign in to comment.