Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[net7.0] [iOS] Fix crash with a hidden CarouselView #13397

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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