diff --git a/src/Controls/src/Core/Handlers/Items/Android/MauiCarouselRecyclerView.cs b/src/Controls/src/Core/Handlers/Items/Android/MauiCarouselRecyclerView.cs index 102806094e8d..4770f7c98ee0 100644 --- a/src/Controls/src/Core/Handlers/Items/Android/MauiCarouselRecyclerView.cs +++ b/src/Controls/src/Core/Handlers/Items/Android/MauiCarouselRecyclerView.cs @@ -108,6 +108,18 @@ public override void TearDownOldElement(CarouselView oldElement) base.TearDownOldElement(oldElement); } + protected override void OnAttachedToWindow() + { + AddLayoutListener(); + base.OnAttachedToWindow(); + } + + protected override void OnDetachedFromWindow() + { + ClearLayoutListener(); + base.OnDetachedFromWindow(); + } + public override void UpdateAdapter() { // By default the CollectionViewAdapter creates the items at whatever size the template calls for @@ -513,7 +525,7 @@ void IMauiCarouselRecyclerView.UpdateFromPosition() void AddLayoutListener() { - if (_carouselViewLayoutListener != null) + if (_carouselViewLayoutListener is not null) return; _carouselViewLayoutListener = new CarouselViewOnGlobalLayoutListener(this); @@ -522,6 +534,9 @@ void AddLayoutListener() void LayoutReady() { + if (ItemsView is null) + return; + if (!_initialized) { ItemsView.Scrolled += CarouselViewScrolled; @@ -603,7 +618,8 @@ public CarouselViewOnGlobalLayoutListener(MauiCarouselRecyclerView recyclerView) public void OnGlobalLayout() { - if (_recyclerView.TryGetTarget(out var recyclerView)) + if (_recyclerView.TryGetTarget(out var recyclerView) && + recyclerView.IsAlive()) { recyclerView.LayoutReady(); } diff --git a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt index 0e8eac294145..88701a3df8f3 100644 --- a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt @@ -63,6 +63,8 @@ Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommand.get -> S Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommand.set -> void Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameter.get -> object! Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameter.set -> void +override Microsoft.Maui.Controls.Handlers.Items.MauiCarouselRecyclerView.OnAttachedToWindow() -> void +override Microsoft.Maui.Controls.Handlers.Items.MauiCarouselRecyclerView.OnDetachedFromWindow() -> void static readonly Microsoft.Maui.Controls.KeyboardAccelerator.KeyProperty -> Microsoft.Maui.Controls.BindableProperty! static readonly Microsoft.Maui.Controls.KeyboardAccelerator.ModifiersProperty -> Microsoft.Maui.Controls.BindableProperty! static readonly Microsoft.Maui.Controls.DragGestureRecognizer.CanDragProperty -> Microsoft.Maui.Controls.BindableProperty! @@ -197,7 +199,6 @@ Microsoft.Maui.Controls.PlatformPointerEventArgs.Sender.get -> Android.Views.Vie ~static readonly Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTappedProperty -> Microsoft.Maui.Controls.BindableProperty Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTapped.get -> bool Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTapped.set -> void - *REMOVED*~Microsoft.Maui.Controls.Editor.FontFamily.get -> string *REMOVED*~Microsoft.Maui.Controls.Editor.FontFamily.set -> void *REMOVED*Microsoft.Maui.Controls.Editor.CursorPosition.get -> int @@ -210,7 +211,6 @@ Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTapped.set -> void *REMOVED*Microsoft.Maui.Controls.Editor.FontSize.set -> void *REMOVED*Microsoft.Maui.Controls.Editor.SelectionLength.get -> int *REMOVED*Microsoft.Maui.Controls.Editor.SelectionLength.set -> void - *REMOVED*~Microsoft.Maui.Controls.SearchBar.FontFamily.get -> string *REMOVED*~Microsoft.Maui.Controls.SearchBar.FontFamily.set -> void *REMOVED*Microsoft.Maui.Controls.SearchBar.CursorPosition.get -> int @@ -223,7 +223,6 @@ Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTapped.set -> void *REMOVED*Microsoft.Maui.Controls.SearchBar.FontSize.set -> void *REMOVED*Microsoft.Maui.Controls.SearchBar.SelectionLength.get -> int *REMOVED*Microsoft.Maui.Controls.SearchBar.SelectionLength.set -> void - *REMOVED*~Microsoft.Maui.Controls.Entry.FontFamily.get -> string *REMOVED*~Microsoft.Maui.Controls.Entry.FontFamily.set -> void *REMOVED*Microsoft.Maui.Controls.Entry.CursorPosition.get -> int