Open tarunbhutani opened 5 years ago
@tarunbhutani any chance you can create a sample project that demonstrates this issue and post a link here so I can take a look?
For what it's worth I'm running into this issue too. My scenario is a bit different though.
A: Portrait collection view/IGListKit B: Landscape collection view/IGListKit
When A does a UIWindow transition -> B B updates the orientation lock and auto rotate spins the view into landscape.
When B dismisses/tells the coordinator to return to A the collection view within A will sometimes throw this error
*** Assertion failure in -[IGListCollectionViewLayout _calculateLayoutIfNeeded](), /Pods/IGListKit/Source/IGListCollectionViewLayout.mm:527
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Width of item 0 in section 0 (414 pt) must be less than or equal to container (392 pt) accounting for section insets {0, 0, 0, 0}'
Whats weird is it only happens ~5-10% of the time, and it's definitely happening while the auto rotate is being executed by the system and viewDidLoad is called inside controller A.
B is setup like this:
override public var shouldAutorotate: Bool {
switch UIDevice.current.orientation() {
case .landscapeRight: return false
default: return true
}
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeRight
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .landscapeRight
}
And A has the same but portrait.
I have the same problem with that assertion our project was written by another programmer so I unlock library and comment this assertion in IGListCollectionViewLayout.mm lines 519-527
I couldn't find which Controller has that problem :|
I'm seeing the same issue on the latest release and also building from master
directly.
@tarunbhutani / @HamidZandi I don't suppose you were able to get to the bottom of this at all please?
I'm building against iOS 12 through to the latest beta. I can try and find some time to put together an app that replicates this over the next few days.
Did anyone found solution for this particular issue?
I have the same problem after updated from iOS 13 to 14.
To anyone that is facing this issue: Please check your sections' func sizeForItem(at index: Int) -> CGSize
to see if you are using collectionContext.containerSize.width
or something similar. Because containerSize
does not take insets into account and will request a size from collection view which will not be available to it (hence, the assertion)!
You can do something like this (in your section):
var cellWidth: CGFloat {
collectionContext.containerSize.width - (self.inset.left + self.inset.right)
}
var cellHeight: CGFloat {
// calculate your height
}
override func sizeForItem(at index: Int) -> CGSize {
CGSize(width: cellWidth, height: cellHeight)
}
p.s.: for some reasons unknown to me, collectionContext.insetContainerSize
does not work properly or, I'm not using it right.
App is crashing whenever giving left and right contentInset to UICollectionView.
Error:
Scenario: I've to display two sections in each row where as my collection view leading and trailing is bind to super view. While presenting, the list should have leading and tailing margin.
Question: What is the best way to adding left and right content insets to collection view?
Current working solution:
Not sure, Whether this is the correct solution or hack.