Skip to content

Commit

Permalink
fixed ios wrong remeasurings on screen rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Dobrynin committed Sep 1, 2024
1 parent 2ed8e74 commit b9e97d2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
13 changes: 5 additions & 8 deletions MPowerKit.VirtualizeListView/FixedRefreshView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ public class FixedRefreshView : RefreshView
protected bool PrevEnabled { get; set; }
protected bool PrevPullRefreshEnabled { get; set; }

public FixedRefreshView()
protected override void OnSizeAllocated(double width, double height)
{
#if ANDROID
this.SizeChanged += FixedRefreshView_SizeChanged;
#endif
}
base.OnSizeAllocated(width, height);

private void FixedRefreshView_SizeChanged(object? sender, EventArgs e)
{
Content?.Layout(new Rect(0, 0, Width - Padding.HorizontalThickness, Height - Padding.VerticalThickness));
#if ANDROID || IOS
Content?.Layout(new Rect(0, 0, width - Padding.HorizontalThickness, height - Padding.VerticalThickness));
#endif
}

protected virtual void Refresh()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,17 @@ protected virtual Size GetDesiredLayoutSize(double widthConstraint, double heigh
{
if (IsOrientation(ScrollOrientation.Both) || LaidOutItems.Count == 0) return new();

#if IOS
if (IsOrientation(ScrollOrientation.Vertical))
{
widthConstraint = Math.Min(widthConstraint, AvailableSpace.Width - ListView.Padding.HorizontalThickness);
}
else
{
heightConstraint = Math.Min(heightConstraint, AvailableSpace.Height - ListView.Padding.VerticalThickness);
}
#endif

return IsOrientation(ScrollOrientation.Vertical)
? new(widthConstraint, LaidOutItems[^1].RightBottomWithMargin.Y)
: new(LaidOutItems[^1].RightBottomWithMargin.X, heightConstraint);
Expand Down
8 changes: 4 additions & 4 deletions Sample/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
Text="Move" />
</Grid>

<!--<mpowerkit:FixedRefreshView Grid.Row="1"
Refreshing="FixedRefreshView_Refreshing">-->
<mpowerkit:FixedRefreshView Grid.Row="2"
Refreshing="FixedRefreshView_Refreshing">
<mpowerkit:VirtualizeListView x:Name="listView"
Grid.Row="2"
Padding="15"
Grid.Row="2"
BackgroundColor="Aqua"
IsGrouped="False">
<mpowerkit:VirtualizeListView.Resources>
Expand Down Expand Up @@ -164,7 +164,7 @@
</mpowerkit:VirtualizeListView.ItemTemplate>-->
</mpowerkit:VirtualizeListView>

<!--</mpowerkit:FixedRefreshView>-->
</mpowerkit:FixedRefreshView>

</Grid>
</ContentPage>
3 changes: 1 addition & 2 deletions Sample/Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<!--<MauiVersion>8.0.90-ci.*</MauiVersion>-->

<!-- Display name -->
<ApplicationTitle>Sample</ApplicationTitle>
Expand All @@ -35,7 +36,6 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -58,7 +58,6 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit b9e97d2

Please sign in to comment.