Skip to content

Commit

Permalink
Fix crash with a hidden CarouselView on iOS (#13397)
Browse files Browse the repository at this point in the history
Co-authored-by: Javier Suárez <javiersuarezruiz@hotmail.com>
  • Loading branch information
github-actions[bot] and jsuarezruiz authored Feb 16, 2023
1 parent 6ee362f commit 9c34659
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public CarouselViewLayout(ItemsLayout itemsLayout, CarouselView carouselView) :

public override void ConstrainTo(CGSize size)
{
//TODO: Should we scale the items
var width = size.Width - _carouselView.PeekAreaInsets.Left - _carouselView.PeekAreaInsets.Right;
var height = size.Height - _carouselView.PeekAreaInsets.Top - _carouselView.PeekAreaInsets.Bottom;
// TODO: Should we scale the items
var width = size.Width != 0 ? size.Width - _carouselView.PeekAreaInsets.Left - _carouselView.PeekAreaInsets.Right : 0;
var height = size.Height != 0 ? size.Height - _carouselView.PeekAreaInsets.Top - _carouselView.PeekAreaInsets.Bottom : 0;

if (ScrollDirection == UICollectionViewScrollDirection.Horizontal)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,45 @@ await CreateHandlerAndAddToWindow<LayoutHandler>(layout, async (handler) =>
Assert.NotNull(handler.PlatformView);
});
}

[Fact]
public async Task HiddenCarouselViewNoCrash()
{
SetupBuilder();

ObservableCollection<int> data = new ObservableCollection<int>()
{
1,
2,
};

var template = new DataTemplate(() =>
{
return new Grid()
{
new Label()
};
});

var carouselView = new CarouselView()
{
ItemTemplate = template,
ItemsSource = data
};

var layout = new Grid()
{
carouselView,
};

layout.IsVisible = false;

await CreateHandlerAndAddToWindow<LayoutHandler>(layout, async (handler) =>
{
await Task.Delay(100);
Assert.NotNull(handler.PlatformView);
});
}
}

internal class CustomDataTemplateSelectorSelector : DataTemplateSelector
Expand Down

0 comments on commit 9c34659

Please sign in to comment.