Skip to content

Commit

Permalink
Made final changes to resize crash.
Browse files Browse the repository at this point in the history
  • Loading branch information
patchthecode committed Jul 20, 2017
1 parent 71d4850 commit 765d919
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions Sources/JTAppleCalendarLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,14 @@ 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
var sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
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
Expand Down Expand Up @@ -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]? {
Expand Down
12 changes: 6 additions & 6 deletions Sources/JTAppleCalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 765d919

Please sign in to comment.