yacir/CollectionViewSlantedLayout

Support for RxDataSources

danielhogl opened this issue · 1 comments

Hi,

I just tried out this layout in my project, which is using RxSwift and RxDataSource for collection views. I realised that the application crashes on binding the sections. This is how I initialise datasource and bind it to the collection view items:

let animationConfiguration = AnimationConfiguration(insertAnimation: .bottom, reloadAnimation: .bottom, deleteAnimation: .bottom)

let dataSource = RxCollectionViewSectionedAnimatedDataSource<TopListSectionModel>(animationConfiguration: animationConfiguration, configureCell: { _, collectionView, indexPath, item  in
            
            let cell: TopListCell = collectionView.dequeueReusableCell(forIndexPath: indexPath)
            cell.configure(with: item)
            
            if let layout = collectionView.collectionViewLayout as? CollectionViewSlantedLayout {
                cell.contentView.transform = CGAffineTransform(rotationAngle: layout.slantingAngle)
            }
            
            return cell
        })
          
sections
      .bind(to: collectionView.rx.items(dataSource: dataSource))
      .disposed(by: disposeBag)

Crash on binding:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for number of items in section 0 when there are only 0 sections in the collection view'

It seems like the number of sections is not set when the prepare() function in CollectionViewSlantedLayout is called. I managed to fix this by checking the number of sections in the helper numberOfItems:

var numberOfItems: Int {
    guard let collectionView = collectionView, collectionView.numberOfSections > 0 else { return 0 }
    return collectionView.numberOfItems(inSection: 0)
}

This fixes the crash, however it lead to another crash:

Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [0 0; nan nan]. Layer: <CALayer:0x600000e47f60; position = CGPoint (187.5 40); bounds = CGRect (0 0; 375 80); delegate = <UIView: 0x7fa76ed7e830; frame = (-8.98847e+307 -8.98847e+307; 1.79769e+308 1.79769e+308); transform = [nan, nan, nan, nan, 0, 0]; gestureRecognizers = <NSArray: 0x6000002f3030>; layer = <CALayer: 0x600000e47f60>>; sublayers = (<CALayer: 0x600000f41de0>, <CATransformLayer: 0x600000e41bc0>); opaque = YES; allowsGroupOpacity = YES; transform = CATransform3D (nan nan 0 0; nan nan 0 0; 0 0 1 0; 0 0 0 1)>'

I tried to debug the issue, but I haven't gotten to a conclusion yet. Could you think of a reason for this crash? Thanks for your help

stale commented

Thanks for your contribution!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version
  2. Comment that the issue is still reproducible and include:
    • What version of CollectionViewSlantedLayout you reproduced the issue on
    • What steps you followed to reproduce the issue

Issues that are labeled as crash will not be automatically marked as stale.