@@ -50,10 +50,10 @@ extension ASCollectionView where SectionID == Int
5050 /**
5151 Initializes a collection view with a single section of static content
5252 */
53- init ( @ViewArrayBuilder content : ( ) -> [ AnyView ] )
53+ init ( @ViewArrayBuilder staticContent : ( ( ) -> [ AnyView ] ) ) //Clashing with above functions in Swift 5.1, therefore internal for time being
5454 {
5555 sections = [
56- ASCollectionViewSection ( id: 0 , content: content )
56+ ASCollectionViewSection ( id: 0 , content: staticContent )
5757 ]
5858 }
5959}
@@ -212,8 +212,14 @@ public struct ASCollectionView<SectionID: Hashable>: UIViewControllerRepresentab
212212 cell. invalidateLayout = {
213213 collectionView. collectionViewLayout. invalidateLayout ( )
214214 }
215- cell. selfSizeHorizontal = self . delegate? . collectionView ( cellShouldSelfSizeHorizontallyForItemAt: indexPath) ?? true
216- cell. selfSizeVertical = self . delegate? . collectionView ( cellShouldSelfSizeVerticallyForItemAt: indexPath) ?? true
215+ cell. selfSizeHorizontal =
216+ self . delegate? . collectionView ( cellShouldSelfSizeHorizontallyForItemAt: indexPath)
217+ ?? ( collectionView. collectionViewLayout as? ASCollectionViewLayoutProtocol ) ? . selfSizeHorizontally
218+ ?? true
219+ cell. selfSizeVertical =
220+ self . delegate? . collectionView ( cellShouldSelfSizeVerticallyForItemAt: indexPath)
221+ ?? ( collectionView. collectionViewLayout as? ASCollectionViewLayoutProtocol ) ? . selfSizeVertically
222+ ?? true
217223 cell. setupFor (
218224 id: itemID,
219225 hostingController: hostController)
@@ -411,6 +417,7 @@ extension ASCollectionView.Coordinator
411417{
412418 func setupPrefetching( )
413419 {
420+ let numberToPreload = 10
414421 prefetchSubscription = queuePrefetch
415422 . collect ( . byTime( DispatchQueue . main, 0.1 ) ) // Wanted to use .throttle(for: 0.1, scheduler: DispatchQueue(label: "ASCollectionView PREFETCH"), latest: true) -> THIS CRASHES?? BUG??
416423 . compactMap
@@ -430,33 +437,33 @@ extension ASCollectionView.Coordinator
430437 let sectionIndexPaths = self . parent. sections [ item. section] . dataSource. getIndexPaths ( withSectionIndex: item. section)
431438 let nextItemsInSection : ArraySlice < IndexPath > = {
432439 guard ( item. last + 1 ) < sectionIndexPaths. endIndex else { return [ ] }
433- return sectionIndexPaths [ ( item. last + 1 ) ..< min ( item. last + 6 , sectionIndexPaths. endIndex) ]
440+ return sectionIndexPaths [ ( item. last + 1 ) ..< min ( item. last + numberToPreload + 1 , sectionIndexPaths. endIndex) ]
434441 } ( )
435442 let previousItemsInSection : ArraySlice < IndexPath > = {
436443 guard ( item. first - 1 ) >= sectionIndexPaths. startIndex else { return [ ] }
437- return sectionIndexPaths [ max ( sectionIndexPaths. startIndex, item. first - 5 ) ..< item. first]
444+ return sectionIndexPaths [ max ( sectionIndexPaths. startIndex, item. first - numberToPreload ) ..< item. first]
438445 } ( )
439446 return Array ( nextItemsInSection) + Array( previousItemsInSection)
440447 }
441448 // CHECK IF THERES AN EARLIER SECTION TO PRELOAD
442449 if
443450 let firstSection = toPrefetch. keys. min ( ) , // FIND THE EARLIEST VISIBLE SECTION
444451 ( firstSection - 1 ) >= self . parent. sections. startIndex, // CHECK THERE IS A SECTION BEFORE THIS
445- let firstIndex = visibleIndexPathsBySection [ firstSection] ? . first, firstIndex < 5 // CHECK HOW CLOSE TO THIS SECTION WE ARE
452+ let firstIndex = visibleIndexPathsBySection [ firstSection] ? . first, firstIndex < numberToPreload // CHECK HOW CLOSE TO THIS SECTION WE ARE
446453 {
447454 let precedingSection = firstSection - 1
448- toPrefetch [ precedingSection] = self . parent. sections [ precedingSection] . dataSource. getIndexPaths ( withSectionIndex: precedingSection) . suffix ( 5 )
455+ toPrefetch [ precedingSection] = self . parent. sections [ precedingSection] . dataSource. getIndexPaths ( withSectionIndex: precedingSection) . suffix ( numberToPreload )
449456 }
450457 // CHECK IF THERES A LATER SECTION TO PRELOAD
451458 if
452459 let lastSection = toPrefetch. keys. max ( ) , // FIND THE LAST VISIBLE SECTION
453460 ( lastSection + 1 ) < self . parent. sections. endIndex, // CHECK THERE IS A SECTION AFTER THIS
454461 let lastIndex = visibleIndexPathsBySection [ lastSection] ? . last,
455462 let lastSectionEndIndex = self . parent. sections [ lastSection] . dataSource. getIndexPaths ( withSectionIndex: lastSection) . last? . item,
456- ( lastSectionEndIndex - lastIndex) < 5 // CHECK HOW CLOSE TO THIS SECTION WE ARE
463+ ( lastSectionEndIndex - lastIndex) < numberToPreload // CHECK HOW CLOSE TO THIS SECTION WE ARE
457464 {
458465 let nextSection = lastSection + 1
459- toPrefetch [ nextSection] = Array ( self . parent. sections [ nextSection] . dataSource. getIndexPaths ( withSectionIndex: nextSection) . prefix ( 5 ) )
466+ toPrefetch [ nextSection] = Array ( self . parent. sections [ nextSection] . dataSource. getIndexPaths ( withSectionIndex: nextSection) . prefix ( numberToPreload ) )
460467 }
461468 return toPrefetch
462469 }
0 commit comments