Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions JZCalendarWeekView/JZLongPressWeekView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public protocol JZLongPressViewDelegate: class {
/// - longPressType: the long press type when gusture cancels
/// - startDate: the startDate of the event when gesture cancels
func weekView(_ weekView: JZLongPressWeekView, longPressType: JZLongPressWeekView.LongPressType, didCancelLongPressAt startDate: Date)

/// When long press is begining, this function will be called.
/// Normally this function no need to be implemented.
/// - Parameters:
/// - weekView: current long pressed JZLongPressWeekView
/// - longPressType: the long press type when gusture cancels
/// - startDate: the startDate of the event when gesture cancels
func weekView(_ weekView: JZLongPressWeekView, editingEvent: JZBaseEvent?, didBeganLongPressAt startDate: Date) -> Bool
}

public protocol JZLongPressViewDataSource: class {
Expand All @@ -57,6 +65,7 @@ extension JZLongPressViewDelegate {
public func weekView(_ weekView: JZLongPressWeekView, longPressType: JZLongPressWeekView.LongPressType, didCancelLongPressAt startDate: Date) {}
public func weekView(_ weekView: JZLongPressWeekView, didEndAddNewLongPressAt startDate: Date) {}
public func weekView(_ weekView: JZLongPressWeekView, editingEvent: JZBaseEvent, didEndMoveLongPressAt startDate: Date) {}
public func weekView(_ weekView: JZLongPressWeekView, editingEvent: JZBaseEvent?, didBeganLongPressAt startDate: Date) -> Bool{return true}
}

extension JZLongPressViewDataSource {
Expand Down Expand Up @@ -444,6 +453,12 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate {

UIView.animate(withDuration: 0.2, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 5, options: .curveEaseOut,
animations: { self.longPressView.transform = CGAffineTransform.identity }, completion: nil)

let isAllowed = longPressDelegate?.weekView(self, editingEvent: currentLongPressType == .addNew ? nil : currentEditingInfo.event, didBeganLongPressAt: longPressViewStartDate)

if isAllowed == false{
gestureRecognizer.state = .cancelled
}

} else if state == .changed {
let topYPoint = max(pointInSelfView.y - pressPosition!.yToViewTop, longPressTopMarginY)
Expand Down