@@ -117,6 +117,9 @@ protected override string DetermineCellReuseId(NSIndexPath indexPath)
117
117
return base . DetermineCellReuseId ( itemIndex ) ;
118
118
}
119
119
120
+ private protected override ( Type CellType , string CellTypeReuseId ) DetermineTemplatedCellType ( )
121
+ => ( typeof ( CarouselTemplatedCell2 ) , CarouselTemplatedCell2 . ReuseId ) ;
122
+
120
123
protected override Items . IItemsViewSource CreateItemsViewSource ( )
121
124
{
122
125
var itemsSource = ItemsSourceFactory2 . CreateForCarouselView ( ItemsView . ItemsSource , this , ItemsView . Loop ) ;
@@ -506,54 +509,49 @@ async Task UpdateInitialPosition()
506
509
return ;
507
510
}
508
511
509
- int position = carousel . Position ;
510
- var currentItem = carousel . CurrentItem ;
511
-
512
- if ( currentItem != null )
513
- {
514
- // Sometimes the item could be just being removed while we navigate back to the CarouselView
515
- var positionCurrentItem = ItemsSource . GetIndexForItem ( currentItem ) . Row ;
516
- if ( positionCurrentItem != - 1 )
517
- {
518
- position = positionCurrentItem ;
519
- }
520
- }
521
-
522
- var projectedPosition = NSIndexPath . FromItemSection ( position , _section ) ;
523
-
524
- if ( LoopItemsSource . Loop )
525
- {
526
- //We need to set the position to the correct position since we added 1 item at the beginning
527
- projectedPosition = GetScrollToIndexPath ( position ) ;
528
- }
529
-
530
- var uICollectionViewScrollPosition = IsHorizontal ? UICollectionViewScrollPosition . CenteredHorizontally : UICollectionViewScrollPosition . CenteredVertically ;
531
-
532
- await Task . Delay ( 100 ) . ContinueWith ( ( t ) =>
512
+ await Task . Delay ( 100 ) . ContinueWith ( _ =>
533
513
{
534
514
MainThread . BeginInvokeOnMainThread ( ( ) =>
535
515
{
536
516
if ( ! IsViewLoaded )
537
517
{
538
518
return ;
539
519
}
520
+
540
521
InitialPositionSet = true ;
541
522
542
523
if ( ItemsSource is null || ItemsSource . ItemCount == 0 )
543
524
{
544
525
return ;
545
526
}
546
527
528
+ int position = carousel . Position ;
529
+ var currentItem = carousel . CurrentItem ;
530
+
531
+ if ( currentItem != null )
532
+ {
533
+ // Sometimes the item could be just being removed while we navigate back to the CarouselView
534
+ var positionCurrentItem = ItemsSource . GetIndexForItem ( currentItem ) . Row ;
535
+ if ( positionCurrentItem != - 1 )
536
+ {
537
+ position = positionCurrentItem ;
538
+ }
539
+ }
540
+
541
+ var projectedPosition = LoopItemsSource . Loop
542
+ ? GetScrollToIndexPath ( position ) // We need to set the position to the correct position since we added 1 item at the beginning
543
+ : NSIndexPath . FromItemSection ( position , _section ) ;
544
+
545
+ var uICollectionViewScrollPosition = IsHorizontal ? UICollectionViewScrollPosition . CenteredHorizontally : UICollectionViewScrollPosition . CenteredVertically ;
546
+
547
547
CollectionView . ScrollToItem ( projectedPosition , uICollectionViewScrollPosition , false ) ;
548
548
549
549
//Set the position on VirtualView to update the CurrentItem also
550
550
SetPosition ( position ) ;
551
551
552
552
UpdateVisualStates ( ) ;
553
553
} ) ;
554
-
555
554
} ) ;
556
-
557
555
}
558
556
559
557
void UpdateVisualStates ( )
0 commit comments