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
47 changes: 43 additions & 4 deletions JZCalendarWeekView/JZLongPressWeekView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ open class JZLongPressWeekView: JZBaseWeekView {
/// Get this value when long press began and save the current relative X and Y value until it ended or cancelled
private var pressPosition: (xToViewLeft: CGFloat, yToViewTop: CGFloat)?

private var isPreparingToScrollLeft = false
private var isPreparingToScrollRight = false
private var performScrollLeft = true
private var performScrollRight = true
private var lastPointInSelfView: CGPoint!

public weak var longPressDelegate: JZLongPressViewDelegate?
public weak var longPressDataSource: JZLongPressViewDataSource?

Expand Down Expand Up @@ -177,26 +183,57 @@ open class JZLongPressWeekView: JZBaseWeekView {
/// - The logic of vertical scroll is top scroll depending on **longPressView top** to longPressTopMarginY, bottom scroll denpending on **finger point** to LongPressBottomMarginY.
/// - The logic of horizontal scroll is left scroll depending on **finger point** to longPressLeftMarginY, bottom scroll denpending on **finger point** to LongPressRightMarginY.
private func updateScroll(pointInSelfView: CGPoint) {
self.lastPointInSelfView = pointInSelfView
if isScrolling { return }

// vertical
if pointInSelfView.y - pressPosition!.yToViewTop < longPressTopMarginY + 10 {
isScrolling = true
scrollingTo(direction: .up)

return
} else if pointInSelfView.y > longPressBottomMarginY - 40 {
isScrolling = true
scrollingTo(direction: .down)

return
}
// horizontal
if pointInSelfView.x < longPressLeftMarginX + 10 {
isScrolling = true
scrollingTo(direction: .right)
if self.isPreparingToScrollRight == false {
self.isPreparingToScrollRight = true
self.performScrollRight = true

DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
self.isScrolling = true

if self.performScrollRight && self.lastPointInSelfView.x < self.longPressLeftMarginX + 10 {
self.scrollingTo(direction: .right)
}

self.isScrolling = false
self.isPreparingToScrollRight = false
}
}

return
} else if pointInSelfView.x > longPressRightMarginX - 20 {
isScrolling = true
scrollingTo(direction: .left)
if self.isPreparingToScrollLeft == false {
self.isPreparingToScrollLeft = true
self.performScrollLeft = true

DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
self.isScrolling = true

if self.performScrollLeft && self.lastPointInSelfView.x > self.longPressRightMarginX - 20 {
self.scrollingTo(direction: .left)
}

self.isScrolling = false
self.isPreparingToScrollLeft = false
}
}

return
}
}
Expand Down Expand Up @@ -460,6 +497,8 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate {
longPressDelegate?.weekView(self, longPressType: currentLongPressType, didCancelLongPressAt: longPressViewStartDate)

} else if state == .ended {
self.performScrollRight = false
self.performScrollLeft = false

self.longPressView.removeFromSuperview()
if currentLongPressType == .addNew {
Expand Down