Posts

Post not yet marked as solved
0 Replies
517 Views
Hi guys, I am trying to implement multiple cell types in one section with Compoisitonal Layout.I am trying to use custom group for section elements but with custom group implementation orthogonalScrollingBehavior does not work.     private func makeRestaurantCarouselLayout(sectionIndex: Int) -> NSCollectionLayoutSection? {         guard let delegate else { return nil } /// element will be showed in section         let items = delegate.getSectionItems(with: sectionIndex)         let customGroup = NSCollectionLayoutGroup.custom(layoutSize:                 .init(widthDimension: .fractionalWidth(1.0),                       heightDimension: .fractionalWidth(0.6)) ) { env in             var customItems = [NSCollectionLayoutGroupCustomItem]()             let restaurantCarouselWidth = env.container.contentSize.width * 85 / 100             let height = env.container.contentSize.height             let seeAllWidth = env.container.contentSize.width * 20 / 100             var lastXPosition: CGFloat = 8             let spaceBetweenItem: CGFloat = 8             for item in items {                 switch item {                 case .restaurantSliding:                     let frame = CGRect(                         x: lastXPosition,                         y: .zero,                         width: restaurantCarouselWidth,                         height: height                     )                     customItems.append(NSCollectionLayoutGroupCustomItem(frame: frame))                     lastXPosition += restaurantCarouselWidth + spaceBetweenItem                 case .seeAll:                     let frame = CGRect(                         x: lastXPosition,                         y: .zero,                         width: seeAllWidth,                         height: height                     )                     customItems.append(NSCollectionLayoutGroupCustomItem(frame: frame))                     lastXPosition += seeAllWidth + spaceBetweenItem                 default:                     continue                 }             }             return customItems         }         let section = NSCollectionLayoutSection(group: customGroup) /// not working         section.orthogonalScrollingBehavior = .continuous         section.contentInsets = .init(             top: 12,             leading: 0,             bottom: 8,             trailing: 0         )         return section     } So I am asking that how can I handle multiple cell type in one section ? If your answer is custom group how can I use orthogonalScrollingBehavior with custom group ? The other question to Apple there isn't any information or documentation about NSCollectionLayoutGroup.custom. Do you have plan to add documentation ? Documentation Link: https://developer.apple.com/documentation/uikit/nscollectionlayoutgroup/3213853-custom
Posted Last updated
.