Skip to content

Commit

Permalink
Fix SwipeItemView size issues on Android (#10522) Fixes #10065 Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezruiz authored Dec 12, 2022
1 parent a63b120 commit 509d91e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@
Mode="Reveal">
<SwipeItemView
Command="{Binding Source={x:Reference CustomSwipeItemCollectionView}, Path=BindingContext.FavouriteCommand}">
<Grid
WidthRequest="100">
<BoxView
BackgroundColor="{StaticResource SwipeItemBackgroundColor}"
CornerRadius="0, 6, 0, 6" />
<Label
Text="Favourite"
Style="{StaticResource SwipeItemTextStyle}"/>
</Grid>
<Border
WidthRequest="100"
BackgroundColor="{StaticResource SwipeItemBackgroundColor}">
<Border.StrokeShape>
<RoundRectangle CornerRadius="0, 6, 0, 6" />
</Border.StrokeShape>
<Label
Text="Favourite"
Style="{StaticResource SwipeItemTextStyle}"/>
</Border>
</SwipeItemView>
</SwipeItems>
</SwipeView.RightItems>
Expand Down
28 changes: 17 additions & 11 deletions src/Core/src/Platform/Android/MauiSwipeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,12 @@ List<AView> GetNativeSwipeItems()

void UpdateSwipeItemViewLayout(ISwipeItemView swipeItemView)
{
if (swipeItemView?.Handler is not IPlatformViewHandler handler)
return;

var swipeItemSize = GetSwipeItemSize(swipeItemView);
handler.LayoutVirtualView(0, 0, (int)swipeItemSize.Width, (int)swipeItemSize.Height);

swipeItemView?.Handler?.ToPlatform().InvalidateMeasure(swipeItemView);
}

Expand Down Expand Up @@ -1157,11 +1163,6 @@ Size GetSwipeItemSize(ISwipeItem swipeItem)

if (isHorizontal)
{
if (swipeItem is ISwipeItem)
{
return new Size(items.Mode == SwipeMode.Execute ? (threshold > 0 ? threshold : contentWidth) / items.Count : (threshold < SwipeViewExtensions.SwipeItemWidth ? SwipeViewExtensions.SwipeItemWidth : threshold), contentHeight);
}

if (swipeItem is ISwipeItemView horizontalSwipeItemView)
{
var swipeItemViewSizeRequest = horizontalSwipeItemView.Measure(double.PositiveInfinity, double.PositiveInfinity);
Expand All @@ -1175,15 +1176,14 @@ Size GetSwipeItemSize(ISwipeItem swipeItem)

return new Size(swipeItemWidth, contentHeight);
}
}
else
{

if (swipeItem is ISwipeItem)
{
var swipeItemHeight = GetSwipeItemHeight();
return new Size(contentWidth / items.Count, (threshold > 0 && threshold < swipeItemHeight) ? threshold : swipeItemHeight);
return new Size(items.Mode == SwipeMode.Execute ? (threshold > 0 ? threshold : contentWidth) / items.Count : (threshold < SwipeViewExtensions.SwipeItemWidth ? SwipeViewExtensions.SwipeItemWidth : threshold), contentHeight);
}

}
else
{
if (swipeItem is ISwipeItemView verticalSwipeItemView)
{
var swipeItemViewSizeRequest = verticalSwipeItemView.Measure(double.PositiveInfinity, double.PositiveInfinity);
Expand All @@ -1197,6 +1197,12 @@ Size GetSwipeItemSize(ISwipeItem swipeItem)

return new Size(contentWidth / items.Count, swipeItemHeight);
}

if (swipeItem is ISwipeItem)
{
var swipeItemHeight = GetSwipeItemHeight();
return new Size(contentWidth / items.Count, (threshold > 0 && threshold < swipeItemHeight) ? threshold : swipeItemHeight);
}
}

return Size.Zero;
Expand Down

0 comments on commit 509d91e

Please sign in to comment.