From e861ccb98fe34b13e2f879b82bd3037768562e95 Mon Sep 17 00:00:00 2001 From: Chris Byatt Date: Tue, 16 Oct 2018 15:38:59 +0100 Subject: [PATCH 01/14] Add check for long press type --- JZCalendarWeekView/JZLongPressWeekView.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/JZCalendarWeekView/JZLongPressWeekView.swift b/JZCalendarWeekView/JZLongPressWeekView.swift index ed9d145..e4ef910 100644 --- a/JZCalendarWeekView/JZLongPressWeekView.swift +++ b/JZCalendarWeekView/JZLongPressWeekView.swift @@ -378,6 +378,12 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { isLongPressing = true } + // Check whether we should be doing this long press type + if !longPressTypes.contains(currentLongPressType) { + isLongPressing = false + return + } + // The startDate of the longPressView (the date of top Y in longPressView) var longPressViewStartDate: Date! From b7fdf4ca88ea8c41af9af836412c698000dcf0f4 Mon Sep 17 00:00:00 2001 From: Chris Byatt Date: Tue, 16 Oct 2018 15:48:41 +0100 Subject: [PATCH 02/14] Check types in a better place --- JZCalendarWeekView/JZLongPressWeekView.swift | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/JZCalendarWeekView/JZLongPressWeekView.swift b/JZCalendarWeekView/JZLongPressWeekView.swift index e4ef910..649f5f5 100644 --- a/JZCalendarWeekView/JZLongPressWeekView.swift +++ b/JZCalendarWeekView/JZLongPressWeekView.swift @@ -350,6 +350,8 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { // Long press should not begin if no events at long press position and addNew not required if collectionView.indexPathForItem(at: pointInCollectionView) == nil && !longPressTypes.contains(LongPressType.addNew) { return false + } else if !longPressTypes.contains(LongPressType.move) { + return false } return true @@ -378,12 +380,6 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { isLongPressing = true } - // Check whether we should be doing this long press type - if !longPressTypes.contains(currentLongPressType) { - isLongPressing = false - return - } - // The startDate of the longPressView (the date of top Y in longPressView) var longPressViewStartDate: Date! From 2c3d29c1d0fe43435d510217b2ee62446edebba0 Mon Sep 17 00:00:00 2001 From: Chris Byatt Date: Tue, 16 Oct 2018 15:58:06 +0100 Subject: [PATCH 03/14] Fix long press check --- JZCalendarWeekView/JZLongPressWeekView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JZCalendarWeekView/JZLongPressWeekView.swift b/JZCalendarWeekView/JZLongPressWeekView.swift index 649f5f5..2af7ac7 100644 --- a/JZCalendarWeekView/JZLongPressWeekView.swift +++ b/JZCalendarWeekView/JZLongPressWeekView.swift @@ -350,7 +350,7 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { // Long press should not begin if no events at long press position and addNew not required if collectionView.indexPathForItem(at: pointInCollectionView) == nil && !longPressTypes.contains(LongPressType.addNew) { return false - } else if !longPressTypes.contains(LongPressType.move) { + } else if collectionView.indexPathForItem(at: pointInCollectionView) != nil && !longPressTypes.contains(LongPressType.move) { return false } From e840128818fbacbcc567554d345be5e143cf5a16 Mon Sep 17 00:00:00 2001 From: Chris Byatt Date: Tue, 16 Oct 2018 18:05:29 +0100 Subject: [PATCH 04/14] Add custom long press type --- JZCalendarWeekView/JZLongPressWeekView.swift | 50 ++++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/JZCalendarWeekView/JZLongPressWeekView.swift b/JZCalendarWeekView/JZLongPressWeekView.swift index 2af7ac7..afaadf2 100644 --- a/JZCalendarWeekView/JZLongPressWeekView.swift +++ b/JZCalendarWeekView/JZLongPressWeekView.swift @@ -24,6 +24,9 @@ public protocol JZLongPressViewDelegate: class { /// - editingEvent: the moving (existed, editing) event /// - startDate: the startDate of the event when gesture ends func weekView(_ weekView: JZLongPressWeekView, editingEvent: JZBaseEvent, didEndMoveLongPressAt startDate: Date) + + // When Custom long press gesture begins, this function will be called. + func weekView(_ weekView: JZLongPressWeekView, didBeginLongPressOn cell: JZLongPressEventCell) /// Sometimes the longPress will be cancelled because some curtain reason. /// Normally this function no need to be implemented. @@ -57,6 +60,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, didBeginLongPressOn cell: JZLongPressEventCell) {} } extension JZLongPressViewDataSource { @@ -78,6 +82,9 @@ open class JZLongPressWeekView: JZBaseWeekView { case addNew /// when long press position is on a existed event, this type will allow user to move the existed event case move + + // Custom event to implement functionality besides move when long press on an event + case custom } /// This structure is used to save editing information before reusing collectionViewCell (Type Move used only) @@ -250,7 +257,7 @@ open class JZLongPressWeekView: JZBaseWeekView { open func initLongPressView(selectedCell: UICollectionViewCell?, type: LongPressType, startDate: Date) -> UIView { let longPressView = type == .move ? longPressDataSource!.weekView(self, movingCell: selectedCell!, viewForMoveLongPressAt: startDate) : - longPressDataSource!.weekView(self, viewForAddNewLongPressAt: startDate) + longPressDataSource!.weekView(self, viewForAddNewLongPressAt: startDate) longPressView.clipsToBounds = false //timeText width will change from 00:00 - 24:00, and for each time the length will be different @@ -319,7 +326,7 @@ open class JZLongPressWeekView: JZBaseWeekView { return jzCell.event.id == currentEditingInfo.event.id } - /*** Because of reusability, we set some cell contentViews to translucent, then when those views are reused, if you don't scroll back + /*** Because of reusability, we set some cell contentViews to translucent, then when those views are reused, if you don't scroll back the willDisplayCell will not be called, then those reused contentViews will be translucent and cannot be found */ /// Get the current moving cells to change to alpha (crossing days will have more than one cells) private func getCurrentMovingCells() -> [UICollectionViewCell] { @@ -344,16 +351,18 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { if gestureRecognizer.state == .possible { // Long press on ouside margin area should not begin let isOutsideBeginArea = pointInSelfView.x < longPressLeftMarginX || pointInSelfView.x > longPressRightMarginX || - pointInSelfView.y < longPressTopMarginY || pointInSelfView.y > longPressBottomMarginY + pointInSelfView.y < longPressTopMarginY || pointInSelfView.y > longPressBottomMarginY if isOutsideBeginArea { return false } } // Long press should not begin if no events at long press position and addNew not required if collectionView.indexPathForItem(at: pointInCollectionView) == nil && !longPressTypes.contains(LongPressType.addNew) { return false - } else if collectionView.indexPathForItem(at: pointInCollectionView) != nil && !longPressTypes.contains(LongPressType.move) { + } + + if collectionView.indexPathForItem(at: pointInCollectionView) != nil && !longPressTypes.contains(LongPressType.move) && !longPressTypes.contains(LongPressType.custom) { return false } - + return true } @@ -372,13 +381,30 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { if isLongPressing == false { if let indexPath = collectionView.indexPathForItem(at: pointInCollectionView) { // Can add some conditions for allowing only few types of cells can be moved - currentLongPressType = .move - currentMovingCell = collectionView.cellForItem(at: indexPath) + if longPressTypes.contains(.move) { + currentLongPressType = .move + currentMovingCell = collectionView.cellForItem(at: indexPath) + } else { + currentLongPressType = .custom + currentMovingCell = collectionView.cellForItem(at: indexPath) + } } else { currentLongPressType = .addNew } isLongPressing = true } + + if currentLongPressType == .custom { + if state == .began { + longPressDelegate?.weekView(self, didBeginLongPressOn: currentMovingCell as! JZLongPressEventCell) + return + } else if state == .ended || state == .cancelled { + isLongPressing = false + return + } else { + return + } + } // The startDate of the longPressView (the date of top Y in longPressView) var longPressViewStartDate: Date! @@ -389,18 +415,18 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { } if state == .began { - currentEditingInfo.cellSize = currentLongPressType == .move ? currentMovingCell.frame.size : CGSize(width: flowLayout.sectionWidth, height: flowLayout.hourHeight * CGFloat(addNewDurationMins/60)) pressPosition = currentLongPressType == .move ? (pointInCollectionView.x - currentMovingCell.frame.origin.x, pointInCollectionView.y - currentMovingCell.frame.origin.y) : - (currentEditingInfo.cellSize.width/2, currentEditingInfo.cellSize.height/2) + (currentEditingInfo.cellSize.width/2, currentEditingInfo.cellSize.height/2) longPressViewStartDate = getLongPressViewStartDate(pointInCollectionView: pointInCollectionView, pointInSelfView: pointInSelfView) longPressView = initLongPressView(selectedCell: currentMovingCell, type: currentLongPressType, startDate: longPressViewStartDate) longPressView.frame.size = currentEditingInfo.cellSize longPressView.transform = CGAffineTransform(scaleX: 0.1, y: 0.1) self.addSubview(longPressView) - + longPressView.center = CGPoint(x: pointInSelfView.x - pressPosition!.xToViewLeft + currentEditingInfo.cellSize.width/2, y: pointInSelfView.y - pressPosition!.yToViewTop + currentEditingInfo.cellSize.height/2) + if currentLongPressType == .move { currentEditingInfo.event = (currentMovingCell as! JZLongPressEventCell).event getCurrentMovingCells().forEach { @@ -416,9 +442,7 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { let topYPoint = max(pointInSelfView.y - pressPosition!.yToViewTop, longPressTopMarginY) longPressView.center = CGPoint(x: pointInSelfView.x - pressPosition!.xToViewLeft + currentEditingInfo.cellSize.width/2, y: topYPoint + currentEditingInfo.cellSize.height/2) - } else if state == .cancelled { - UIView.animate(withDuration: 0.3, delay: 0.0, options: .curveEaseOut, animations: { self.longPressView.alpha = 0 }, completion: { @@ -426,9 +450,7 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { self.longPressView.removeFromSuperview() }) longPressDelegate?.weekView(self, longPressType: currentLongPressType, didCancelLongPressAt: longPressViewStartDate) - } else if state == .ended { - self.longPressView.removeFromSuperview() if currentLongPressType == .addNew { longPressDelegate?.weekView(self, didEndAddNewLongPressAt: longPressViewStartDate) From 49fe082f003ca721a75e2b6dff5ec547ac122af2 Mon Sep 17 00:00:00 2001 From: Chris Byatt Date: Wed, 17 Oct 2018 10:16:42 +0100 Subject: [PATCH 05/14] Refactor and comments --- JZCalendarWeekView/JZLongPressWeekView.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/JZCalendarWeekView/JZLongPressWeekView.swift b/JZCalendarWeekView/JZLongPressWeekView.swift index 2af7ac7..4767dcd 100644 --- a/JZCalendarWeekView/JZLongPressWeekView.swift +++ b/JZCalendarWeekView/JZLongPressWeekView.swift @@ -104,7 +104,7 @@ open class JZLongPressWeekView: JZBaseWeekView { public weak var longPressDataSource: JZLongPressViewDataSource? // You can modify these properties below - public var longPressTypes: [LongPressType]! + public var longPressTypes: [LongPressType] = [LongPressType]() /// It is used to identify the minimum time interval(Minute) when dragging the event view (minimum value is 1, maximum is 60) public var moveTimeMinInterval: Int = 15 /// For an addNew event, the event duration mins determine the add new event duration and height @@ -347,10 +347,16 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { pointInSelfView.y < longPressTopMarginY || pointInSelfView.y > longPressBottomMarginY if isOutsideBeginArea { return false } } - // Long press should not begin if no events at long press position and addNew not required - if collectionView.indexPathForItem(at: pointInCollectionView) == nil && !longPressTypes.contains(LongPressType.addNew) { + + let hasItemAtPoint = collectionView.indexPathForItem(at: pointInCollectionView) != nil + + // Long press should not begin if there are events at long press position and move not required + if hasItemAtPoint && !longPressTypes.contains(LongPressType.move) { return false - } else if collectionView.indexPathForItem(at: pointInCollectionView) != nil && !longPressTypes.contains(LongPressType.move) { + } + + // Long press should not begin if no events at long press position and addNew not required + if !hasItemAtPoint && !longPressTypes.contains(LongPressType.addNew) { return false } From 3b93d43864df672c8487b77954ad95338daaf24b Mon Sep 17 00:00:00 2001 From: Chris Byatt Date: Tue, 18 Dec 2018 15:04:41 +0000 Subject: [PATCH 06/14] Update comments --- JZCalendarWeekView/JZLongPressWeekView.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/JZCalendarWeekView/JZLongPressWeekView.swift b/JZCalendarWeekView/JZLongPressWeekView.swift index 5102522..ca8cddb 100644 --- a/JZCalendarWeekView/JZLongPressWeekView.swift +++ b/JZCalendarWeekView/JZLongPressWeekView.swift @@ -25,7 +25,11 @@ public protocol JZLongPressViewDelegate: class { /// - startDate: the startDate of the event when gesture ends func weekView(_ weekView: JZLongPressWeekView, editingEvent: JZBaseEvent, didEndMoveLongPressAt startDate: Date) - // When Custom long press gesture begins, this function will be called. + /// When Custom long press gesture begins on an , this function will be called. + /// Use this function to perform actions when a use long presses on an existing event + /// - Parameters: + /// - weekView: current long pressed JZLongPressWeekView + /// - cell: current long pressed JZLongPressEventCell func weekView(_ weekView: JZLongPressWeekView, didBeginLongPressOn cell: JZLongPressEventCell) /// Sometimes the longPress will be cancelled because some curtain reason. @@ -82,8 +86,7 @@ open class JZLongPressWeekView: JZBaseWeekView { case addNew /// when long press position is on a existed event, this type will allow user to move the existed event case move - - // Custom event to implement functionality besides move when long press on an event + // Custom event to implement functionality besides move when long press on an existing event case custom } From 0d1da75e9a852e625047e38da119aedeb7b0c643 Mon Sep 17 00:00:00 2001 From: Chris Byatt Date: Tue, 18 Dec 2018 15:09:25 +0000 Subject: [PATCH 07/14] Rename variables to make more sense --- JZCalendarWeekView/JZLongPressWeekView.swift | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/JZCalendarWeekView/JZLongPressWeekView.swift b/JZCalendarWeekView/JZLongPressWeekView.swift index ca8cddb..31badd6 100644 --- a/JZCalendarWeekView/JZLongPressWeekView.swift +++ b/JZCalendarWeekView/JZLongPressWeekView.swift @@ -392,17 +392,17 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { let pointInCollectionView = gestureRecognizer.location(in: collectionView) let state = gestureRecognizer.state - var currentMovingCell: UICollectionViewCell! + var currentLongPressCell: UICollectionViewCell! if isLongPressing == false { if let indexPath = collectionView.indexPathForItem(at: pointInCollectionView) { // Can add some conditions for allowing only few types of cells can be moved if longPressTypes.contains(.move) { currentLongPressType = .move - currentMovingCell = collectionView.cellForItem(at: indexPath) - } else { + currentLongPressCell = collectionView.cellForItem(at: indexPath) + } else if longPressTypes.contains(.custom) { currentLongPressType = .custom - currentMovingCell = collectionView.cellForItem(at: indexPath) + currentLongPressCell = collectionView.cellForItem(at: indexPath) } } else { currentLongPressType = .addNew @@ -412,7 +412,7 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { if currentLongPressType == .custom { if state == .began { - longPressDelegate?.weekView(self, didBeginLongPressOn: currentMovingCell as! JZLongPressEventCell) + longPressDelegate?.weekView(self, didBeginLongPressOn: currentLongPressCell as! JZLongPressEventCell) return } else if state == .ended || state == .cancelled { isLongPressing = false @@ -431,12 +431,11 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { } if state == .began { - - currentEditingInfo.cellSize = currentLongPressType == .move ? currentMovingCell.frame.size : CGSize(width: flowLayout.sectionWidth, height: flowLayout.hourHeight * CGFloat(addNewDurationMins)/60) - pressPosition = currentLongPressType == .move ? (pointInCollectionView.x - currentMovingCell.frame.origin.x, pointInCollectionView.y - currentMovingCell.frame.origin.y) : + currentEditingInfo.cellSize = currentLongPressType == .move ? currentLongPressCell.frame.size : CGSize(width: flowLayout.sectionWidth, height: flowLayout.hourHeight * CGFloat(addNewDurationMins)/60) + pressPosition = currentLongPressType == .move ? (pointInCollectionView.x - currentLongPressCell.frame.origin.x, pointInCollectionView.y - currentLongPressCell.frame.origin.y) : (currentEditingInfo.cellSize.width/2, currentEditingInfo.cellSize.height/2) longPressViewStartDate = getLongPressViewStartDate(pointInCollectionView: pointInCollectionView, pointInSelfView: pointInSelfView) - longPressView = initLongPressView(selectedCell: currentMovingCell, type: currentLongPressType, startDate: longPressViewStartDate) + longPressView = initLongPressView(selectedCell: currentLongPressCell, type: currentLongPressType, startDate: longPressViewStartDate) longPressView.frame.size = currentEditingInfo.cellSize longPressView.transform = CGAffineTransform(scaleX: 0.1, y: 0.1) self.addSubview(longPressView) @@ -445,7 +444,7 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { y: pointInSelfView.y - pressPosition!.yToViewTop + currentEditingInfo.cellSize.height/2) if currentLongPressType == .move { - currentEditingInfo.event = (currentMovingCell as! JZLongPressEventCell).event + currentEditingInfo.event = (currentLongPressCell as! JZLongPressEventCell).event getCurrentMovingCells().forEach { $0.contentView.layer.opacity = movingCellOpacity currentEditingInfo.allOpacityContentViews.append($0.contentView) From 8ffbee891d91c421f3ac552b457e4f2282d67b45 Mon Sep 17 00:00:00 2001 From: Chris Byatt Date: Tue, 18 Dec 2018 15:10:37 +0000 Subject: [PATCH 08/14] Make readme match --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ef4178a..968f391 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Inspired from WRCalendarView (https://github.com/wayfinders/WRCalendarView) - [x] Two Scroll types: One-Day scroll (scroll a section) or Page scroll - [x] Two Types of Long Press Gestures: Add a new event & Move an existing event - [x] Events display on calendar view (supports events with conflict time and events crossing few days) +- [x] Set horizontal scrollable range dates - [x] Support all device orientations (including iPhone X Landscape) and iPad (Slide Over and Split View) - [x] Customise your own current timeline - [x] All-Day Events @@ -108,7 +109,7 @@ public protocol JZLongPressViewDataSource: class { ``` Also, you should provide the long press types and there are some other properties you can change. -```swift +```swift calendarWeekView.longPressDelegate = self calendarWeekView.longPressDataSource = self calendarWeekView.longPressTypes = [.addNew, .move] @@ -124,7 +125,7 @@ If you want to use the `move` type long press, you have to inherit your `UIColle In JZCalendarWeekView, the data model is using `[Date: [Event]]` dictionary because for each day (a section in collectionView), there might be some events.
A static function called `getIntraEventsByDate` provided in `JZWeekViewHelper` allow you to tranform your events list into `[Date: [Event]]` dictionary. -```swift +```swift open class func getIntraEventsByDate(originalEvents: [T]) -> [Date: [T]] ``` In order to call this function, you should create a subclass of `JZBaseEvent` and also implement the `NSCopying` protocol.
@@ -141,6 +142,14 @@ In order to active all-day feature, there are only two things you need to do. 2. In your customised CalendarViewWeekView, override the `viewForSupplementaryElementOfKind` and use `updateView` in `AllDayHeader` to update your all-day view with your own views. [Example](Example/JZCalendarWeekViewExample/Source/LongPressViews/LongPressWeekView.swift) +### Horizontal Scrollable Range + +Horizontal scrollable range dates allow you to set your preferred scrollable range. CalendarWeekView can only be horizontal scrollable between `startDate`(including) and `endDate`(including). `nil` means no limit. + +1. You can set `scrollableRange` when you call `setupCalendar()` or simply change this variable. +2. If you change `scrollType` without calling `forceReload()`, you should call `setHorizontalEdgesOffsetX()` to reset the edges, because for different scroll types, the edges are different. + + For futher usage, you can also check the example project, some comments in code or just email me.
## Requirements @@ -164,8 +173,8 @@ pod 'JZCalendarWeekView', '0.5.1' ## Todo -- [ ] Limited date range: First Date and Last Date in CalendarView - [ ] DecorationView for different background views (refer to #12) +- [ ] Limited date range: start time and end Time (vertical) in CalendarView - [ ] Theme implementation - [ ] New scroll type: Infinite scroll - [ ] Support different types of event arrangment rules @@ -178,6 +187,3 @@ If you have any questions and suggestions, feel free to contact me. ## License JZCalendarWeekView is available under the MIT license. See the [LICENSE](https://github.com/zjfjack/JZCalendarWeekView/blob/master/LICENSE) for more info. - - - From 000145b00dc47d2749209a09b0dd1d35f58f2c62 Mon Sep 17 00:00:00 2001 From: Chris Byatt Date: Tue, 18 Dec 2018 15:18:06 +0000 Subject: [PATCH 09/14] Update readme to explain custom long press --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 968f391..cdc4971 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,8 @@ public protocol JZLongPressViewDelegate: class { func weekView(_ weekView: JZLongPressWeekView, didEndAddNewLongPressAt startDate: Date) /// When Move long press gesture ends, this function will be called. func weekView(_ weekView: JZLongPressWeekView, editingEvent: JZBaseEvent, didEndMoveLongPressAt startDate: Date) + /// When an event is long pressed on, this function will be called. + func weekView(_ weekView: JZLongPressWeekView, didBeginLongPressOn cell: JZLongPressEventCell) /// Sometimes the longPress will be cancelled because some curtain reason. func weekView(_ weekView: JZLongPressWeekView, longPressType: JZLongPressWeekView.LongPressType, didCancelLongPressAt startDate: Date) } @@ -112,7 +114,7 @@ Also, you should provide the long press types and there are some other propertie ```swift calendarWeekView.longPressDelegate = self calendarWeekView.longPressDataSource = self -calendarWeekView.longPressTypes = [.addNew, .move] +calendarWeekView.longPressTypes = [.addNew, .move, .custom] // Optional calendarWeekView.addNewDurationMins = 120 From cbf64a40d6a34b735855ff2f96443159a3210909 Mon Sep 17 00:00:00 2001 From: Chris Byatt Date: Tue, 18 Dec 2018 15:36:39 +0000 Subject: [PATCH 10/14] Readd missing custom gesture should begin --- JZCalendarWeekView/JZLongPressWeekView.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/JZCalendarWeekView/JZLongPressWeekView.swift b/JZCalendarWeekView/JZLongPressWeekView.swift index 31badd6..abda80d 100644 --- a/JZCalendarWeekView/JZLongPressWeekView.swift +++ b/JZCalendarWeekView/JZLongPressWeekView.swift @@ -368,6 +368,10 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { } let hasItemAtPoint = collectionView.indexPathForItem(at: pointInCollectionView) != nil + + if hasItemAtPoint && longPressTypes.contains(LongPressType.custom) { + return true + } // Long press should not begin if there are events at long press position and move not required if hasItemAtPoint && !longPressTypes.contains(LongPressType.move) { From e0f623cc1b3c779d1968b3399ddb532d6c637c58 Mon Sep 17 00:00:00 2001 From: Chris Byatt Date: Thu, 8 Aug 2019 15:16:32 +0100 Subject: [PATCH 11/14] fix long compile time error --- .../JZCalendarWeekViewExample.xcodeproj/project.pbxproj | 8 ++++---- JZCalendarWeekView/JZWeekViewFlowLayout.swift | 5 +---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Example/JZCalendarWeekViewExample.xcodeproj/project.pbxproj b/Example/JZCalendarWeekViewExample.xcodeproj/project.pbxproj index 6feb0ad..9fa19fb 100644 --- a/Example/JZCalendarWeekViewExample.xcodeproj/project.pbxproj +++ b/Example/JZCalendarWeekViewExample.xcodeproj/project.pbxproj @@ -518,11 +518,11 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = XRYH9M2JN7; + DEVELOPMENT_TEAM = L85MD8WTSB; INFOPLIST_FILE = "$(SRCROOT)/JZCalendarWeekViewExample/Supporting Files/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.zjfjack.JZCalendarWeekViewExample; + PRODUCT_BUNDLE_IDENTIFIER = com.midrive.JZCalendarWeekViewExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; @@ -535,11 +535,11 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = XRYH9M2JN7; + DEVELOPMENT_TEAM = L85MD8WTSB; INFOPLIST_FILE = "$(SRCROOT)/JZCalendarWeekViewExample/Supporting Files/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.zjfjack.JZCalendarWeekViewExample; + PRODUCT_BUNDLE_IDENTIFIER = com.midrive.JZCalendarWeekViewExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/JZCalendarWeekView/JZWeekViewFlowLayout.swift b/JZCalendarWeekView/JZWeekViewFlowLayout.swift index 6d1ef14..79c5627 100644 --- a/JZCalendarWeekView/JZWeekViewFlowLayout.swift +++ b/JZCalendarWeekView/JZWeekViewFlowLayout.swift @@ -40,10 +40,7 @@ open class JZWeekViewFlowLayout: UICollectionViewFlowLayout { open var contentsMargin: UIEdgeInsets { return UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0) } open var itemMargin: UIEdgeInsets { return UIEdgeInsets(top: 1, left: 1, bottom: 1, right: 1) } /// weekview contentSize height - open var maxSectionHeight: CGFloat { - let height = hourHeight * 24 // statement too long for Swift 5 compiler - return columnHeaderHeight + height + contentsMargin.top + contentsMargin.bottom + allDayHeaderHeight - } + open var maxSectionHeight: CGFloat { return columnHeaderHeight as CGFloat + hourHeight as CGFloat * 24 + contentsMargin.top as CGFloat + contentsMargin.bottom as CGFloat + allDayHeaderHeight as CGFloat } let minOverlayZ = 1000 // Allows for 900 items in a section without z overlap issues let minCellZ = 100 // Allows for 100 items in a section's background From 1be84c308823cfc8683fc086c818f8116b73ff12 Mon Sep 17 00:00:00 2001 From: Chris Byatt Date: Tue, 20 Aug 2019 15:08:10 +0100 Subject: [PATCH 12/14] Update version --- JZCalendarWeekView.podspec | 4 ++-- JZCalendarWeekView/JZLongPressWeekView.swift | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/JZCalendarWeekView.podspec b/JZCalendarWeekView.podspec index 3080cb1..eb744ba 100644 --- a/JZCalendarWeekView.podspec +++ b/JZCalendarWeekView.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = "JZCalendarWeekView" - s.version = "0.7.1" + s.version = "0.7.2" s.summary = "Calendar Week & Day View in iOS Swift" s.homepage = "https://github.com/zjfjack/JZCalendarWeekView" s.license = { :type => "MIT", :file => "LICENSE" } s.author = { "Jeff Zhang" => "zekejeff@gmail.com" } s.platform = :ios, "9.0" - s.source = { :git => "https://github.com/zjfjack/JZCalendarWeekView.git", :tag => s.version } + s.source = { :git => "https://github.com/fawxy/JZCalendarWeekView.git", :tag => s.version } s.source_files = "JZCalendarWeekView/**/*.swift" end diff --git a/JZCalendarWeekView/JZLongPressWeekView.swift b/JZCalendarWeekView/JZLongPressWeekView.swift index ae620ec..0170914 100644 --- a/JZCalendarWeekView/JZLongPressWeekView.swift +++ b/JZCalendarWeekView/JZLongPressWeekView.swift @@ -416,7 +416,6 @@ extension JZLongPressWeekView: UIGestureRecognizerDelegate { let state = gestureRecognizer.state var currentLongPressCell: UICollectionViewCell! - var currentMovingCell: UICollectionViewCell! if isLongPressing == false { if let indexPath = collectionView.indexPathForItem(at: pointInCollectionView) { From 32d3df22bb72eb464141f6685636e63bff4829ee Mon Sep 17 00:00:00 2001 From: Chris Byatt Date: Tue, 20 Aug 2019 17:23:13 +0100 Subject: [PATCH 13/14] Fix diary taps --- JZCalendarWeekView/JZBaseWeekView.swift | 50 ++++++++++++++----------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/JZCalendarWeekView/JZBaseWeekView.swift b/JZCalendarWeekView/JZBaseWeekView.swift index a852e8c..2edb690 100644 --- a/JZCalendarWeekView/JZBaseWeekView.swift +++ b/JZCalendarWeekView/JZBaseWeekView.swift @@ -31,7 +31,7 @@ open class JZBaseWeekView: UIView { (numOfDays) days before current page first date, which means the start of the collectionView, not the current page first date - The core structure of JZCalendarWeekView is 3 pages, previous-current-next - If you want to update this value instead of using [updateWeekView(to date: Date)](), please **make sure the date is startOfDay**. - */ + */ public var initDate: Date! { didSet { baseDelegate?.initDateDidChange(self, initDate: initDate) @@ -144,17 +144,17 @@ open class JZBaseWeekView: UIView { /** Basic Setup method for JZCalendarWeekView,it **must** be called. - + - Parameters: - - numOfDays: Number of days in a page - - setDate: The initial set date, the first date in current page except WeekView (numOfDays = 7) - - allEvents: The dictionary of all the events for present. JZWeekViewHelper.getIntraEventsByDate can help transform the data - - firstDayOfWeek: First day of a week, **only works when numOfDays is 7**. Default value is Sunday - - scrollType: The horizontal scroll type for this view. Default value is pageScroll - - currentTimelineType: The current time line type for this view. Default value is section - - visibleTime: WeekView will be scroll to this time, when it appears the **first time**. This visibleTime only determines **y** offset. Defaut value is current time. - - scrollableRange: The scrollable area for this weekView, both start and end dates are included, set nil as unlimited in one side - */ + - numOfDays: Number of days in a page + - setDate: The initial set date, the first date in current page except WeekView (numOfDays = 7) + - allEvents: The dictionary of all the events for present. JZWeekViewHelper.getIntraEventsByDate can help transform the data + - firstDayOfWeek: First day of a week, **only works when numOfDays is 7**. Default value is Sunday + - scrollType: The horizontal scroll type for this view. Default value is pageScroll + - currentTimelineType: The current time line type for this view. Default value is section + - visibleTime: WeekView will be scroll to this time, when it appears the **first time**. This visibleTime only determines **y** offset. Defaut value is current time. + - scrollableRange: The scrollable area for this weekView, both start and end dates are included, set nil as unlimited in one side + */ open func setupCalendar(numOfDays: Int, setDate: Date, allEvents: [Date: [JZBaseEvent]], @@ -330,11 +330,15 @@ open class JZBaseWeekView: UIView { return dates } + open func selectedItemAt(indexPath: IndexPath) { + + } + /** - Used to Refresh the weekView when viewWillTransition - - **Must override viewWillTransition in the ViewController and call this function** - */ + Used to Refresh the weekView when viewWillTransition + + **Must override viewWillTransition in the ViewController and call this function** + */ open func refreshWeekView() { updateWeekView(to: self.initDate.add(component: .day, value: numOfDays)) } @@ -358,7 +362,7 @@ open class JZBaseWeekView: UIView { /** Get date excluding time from **collectionView contentOffset only** rather than gesture point in collectionView - - Parameter contentOffsetX: collectionView contentOffset x + - Parameter contentOffsetX: collectionView contentOffset x */ open func getDateForContentOffsetX(_ contentOffsetX: CGFloat) -> Date { let adjustedX = contentOffsetX - flowLayout.contentsMargin.left @@ -368,7 +372,7 @@ open class JZBaseWeekView: UIView { /** Get time excluding date from **collectionView contentOffset only** rather than gesture point in collectionView - - Parameter contentOffsetY: collectionView contentOffset y + - Parameter contentOffsetY: collectionView contentOffset y */ open func getDateForContentOffsetY(_ contentOffsetY: CGFloat) -> (hour: Int, minute: Int) { var adjustedY = contentOffsetY - flowLayout.contentsMargin.top @@ -380,7 +384,7 @@ open class JZBaseWeekView: UIView { /** Get full date from **collectionView contentOffset only** rather than gesture point in collectionView - - Parameter contentOffset: collectionView contentOffset + - Parameter contentOffset: collectionView contentOffset */ open func getDateForContentOffset(_ contentOffset: CGPoint) -> Date { let yearMonthDay = getDateForContentOffsetX(contentOffset.x) @@ -390,7 +394,7 @@ open class JZBaseWeekView: UIView { /** Get date excluding time from **gesture point in collectionView only** rather than collectionView contentOffset - - Parameter xCollectionView: gesture point x in collectionView + - Parameter xCollectionView: gesture point x in collectionView */ open func getDateForPointX(_ xCollectionView: CGFloat) -> Date { // RowHeader(horizontal UICollectionReusableView) should be considered in gesture point @@ -402,7 +406,7 @@ open class JZBaseWeekView: UIView { /** Get time excluding date from **gesture point in collectionView only** rather than collectionView contentOffset - - Parameter yCollectionView: gesture point y in collectionView + - Parameter yCollectionView: gesture point y in collectionView */ open func getDateForPointY(_ yCollectionView: CGFloat) -> (hour: Int, minute: Int) { // ColumnHeader and AllDayHeader(vertical UICollectionReusableView) should be considered in gesture point @@ -418,7 +422,7 @@ open class JZBaseWeekView: UIView { /** Get full date from **gesture point in collectionView only** rather than collectionView contentOffset - - Parameter point: gesture point in collectionView + - Parameter point: gesture point in collectionView */ open func getDateForPoint(_ point: CGPoint) -> Date { let yearMonthDay = getDateForPointX(point.x) @@ -529,6 +533,10 @@ extension JZBaseWeekView: UICollectionViewDelegate, UICollectionViewDelegateFlow self.endOfScroll() } + open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + self.selectedItemAt(indexPath: indexPath) + } + /// Some actions need to be done when scroll ends private func endOfScroll() { // vertical scroll should not load page, handled in loadPage method From 3cd365bdd0ba15c9d6766437f9bafec92b27b089 Mon Sep 17 00:00:00 2001 From: Chris Byatt Date: Tue, 20 Aug 2019 17:24:30 +0100 Subject: [PATCH 14/14] Update podspec --- JZCalendarWeekView.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/JZCalendarWeekView.podspec b/JZCalendarWeekView.podspec index eb744ba..c5ec799 100644 --- a/JZCalendarWeekView.podspec +++ b/JZCalendarWeekView.podspec @@ -1,8 +1,8 @@ Pod::Spec.new do |s| s.name = "JZCalendarWeekView" - s.version = "0.7.2" + s.version = "0.7.3" s.summary = "Calendar Week & Day View in iOS Swift" - s.homepage = "https://github.com/zjfjack/JZCalendarWeekView" + s.homepage = "https://github.com/midrive/JZCalendarWeekView" s.license = { :type => "MIT", :file => "LICENSE" } s.author = { "Jeff Zhang" => "zekejeff@gmail.com" } s.platform = :ios, "9.0"