From 765d919bb91fa3817d79d78f735bee0b720f3ba3 Mon Sep 17 00:00:00 2001 From: JayT Date: Thu, 20 Jul 2017 11:34:18 -0700 Subject: [PATCH] Made final changes to resize crash. --- Sources/JTAppleCalendarLayout.swift | 14 +++++++------- Sources/JTAppleCalendarView.swift | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Sources/JTAppleCalendarLayout.swift b/Sources/JTAppleCalendarLayout.swift index 77c43677..d0984030 100644 --- a/Sources/JTAppleCalendarLayout.swift +++ b/Sources/JTAppleCalendarLayout.swift @@ -41,7 +41,6 @@ class JTAppleCalendarLayout: UICollectionViewLayout, JTAppleCalendarLayoutProtoc var decorationCache: [IndexPath:UICollectionViewLayoutAttributes] = [:] var sectionSize: [CGFloat] = [] var lastWrittenCellAttribute: (Int, Int, CGFloat, CGFloat, CGFloat, CGFloat)! - var isPreparing = true var stride: CGFloat = 0 var minimumInteritemSpacing: CGFloat = 0 var minimumLineSpacing: CGFloat = 0 @@ -49,12 +48,7 @@ class JTAppleCalendarLayout: UICollectionViewLayout, JTAppleCalendarLayoutProtoc var headerSizes: [AnyHashable:CGFloat] = [:] var focusIndexPath: IndexPath? var isCalendarLayoutLoaded: Bool { return !cellCache.isEmpty } - var layoutIsReadyToBePrepared: Bool { - return !(!cellCache.isEmpty || - collectionView!.frame.width == 0 || - collectionView!.frame.height == 0 || - delegate.calendarDataSource == nil) - } + var layoutIsReadyToBePrepared: Bool { return !(!cellCache.isEmpty || delegate.calendarDataSource == nil) } var monthMap: [Int: Int] = [:] var numberOfRows: Int = 0 @@ -319,6 +313,12 @@ class JTAppleCalendarLayout: UICollectionViewLayout, JTAppleCalendarLayoutProtoc return CGSize(width: contentWidth, height: contentHeight) } + override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { + return + lastSetCollectionViewSize.height != newBounds.height || + lastSetCollectionViewSize.width != newBounds.width + } + /// Returns the layout attributes for all of the cells /// and views in the specified rectangle. override open func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { diff --git a/Sources/JTAppleCalendarView.swift b/Sources/JTAppleCalendarView.swift index b10e1def..1df61db7 100644 --- a/Sources/JTAppleCalendarView.swift +++ b/Sources/JTAppleCalendarView.swift @@ -113,12 +113,12 @@ open class JTAppleCalendarView: UICollectionView { override open func layoutSubviews() { super.layoutSubviews() - if (collectionViewLayout as! JTAppleCalendarLayout).lastSetCollectionViewSize != frame { - // ive seen that layout subview gets called. Calendar is setup, and then it gets called again - // At this point, it already has generaed cells which needs to be invalidated. - calendarViewLayout.invalidateLayout() - layoutIfNeeded() - } +// if (collectionViewLayout as! JTAppleCalendarLayout).lastSetCollectionViewSize != frame { +// // ive seen that layout subview gets called. Calendar is setup, and then it gets called again +// // At this point, it already has generaed cells which needs to be invalidated. +// calendarViewLayout.invalidateLayout() +// layoutIfNeeded() +// } if !delayedExecutionClosure.isEmpty, isCalendarLayoutLoaded { executeDelayedTasks()