Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Android CarouselViewRenderer should call base UpdateItemsSource and U…
Browse files Browse the repository at this point in the history
…pdateAdapter to reset scroll listener and observers
  • Loading branch information
danielcaceresm committed Mar 11, 2022
1 parent 12708e1 commit 6956fb2
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,37 +119,37 @@ protected override void TearDownOldElement(ItemsView oldElement)

protected override void UpdateAdapter()
{
// By default the CollectionViewAdapter creates the items at whatever size the template calls for
// But for the Carousel, we want it to create the items to fit the width/height of the viewport
// So we give it an alternate delegate for creating the views

var oldItemViewAdapter = ItemsViewAdapter;

UnsubscribeCollectionItemsSourceChanged(oldItemViewAdapter);
if (oldItemViewAdapter != null)
{
Carousel.SetValueFromRenderer(FormsCarouselView.PositionProperty, 0);
Carousel.SetValueFromRenderer(FormsCarouselView.CurrentItemProperty, null);
}

ItemsViewAdapter = new CarouselViewAdapter<ItemsView, IItemsViewSource>(Carousel,
(view, context) => new SizedItemContentView(Context, GetItemWidth, GetItemHeight));

_gotoPosition = -1;

SwapAdapter(ItemsViewAdapter, false);
base.UpdateAdapter();

UpdateInitialPosition();

if (ItemsViewAdapter?.ItemsSource is ObservableItemsSource observableItemsSource)
observableItemsSource.CollectionItemsSourceChanged += CollectionItemsSourceChanged;
}

oldItemViewAdapter?.Dispose();
protected override ItemsViewAdapter<ItemsView, IItemsViewSource> CreateAdapter()
{
// By default the CollectionViewAdapter creates the items at whatever size the template calls for
// But for the Carousel, we want it to create the items to fit the width/height of the viewport
// So we give it an alternate delegate for creating the views
return new CarouselViewAdapter<ItemsView, IItemsViewSource>(Carousel,
(view, context) => new SizedItemContentView(Context, GetItemWidth, GetItemHeight));
}

protected override void UpdateItemsSource()
protected override void UpdateItemsSource()
{
UpdateAdapter();
UpdateEmptyView();
base.UpdateItemsSource();
_carouselViewLoopManager.SetItemsSource(ItemsViewAdapter.ItemsSource);
}

Expand Down

0 comments on commit 6956fb2

Please sign in to comment.