Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
[GH-12429] Fixed extra height on Shell Flyout and fix issues with fly…
Browse files Browse the repository at this point in the history
…out items not updating layout (#12967) fixes #12429 fixes #12785

* Fixed extra height and added sample page

* - fix some dynamic layouts

* - fix android to resize

* - get rid of cell reuse, allow buttons inside template, let cells resize dynamically

* - Add UITests
- Fix Android Measuring

* - remove comments

* - fix UWP Measuring

* - Fix Automation Id to use Bindings on uwp

* - fix language and iOS test

* - cleanup

* - fix iOS margin issue

* - fix iOS type

Co-authored-by: shane <shneuvil@microsoft.com>
Co-authored-by: Javier Suárez <javiersuarezruiz@hotmail.com>
  • Loading branch information
3 people committed Dec 18, 2020
1 parent 4d4679a commit acb4af5
Show file tree
Hide file tree
Showing 14 changed files with 414 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<ProjectExtensions>
<VisualStudio>
<UserProperties TriggeredFromHotReload="False" XamarinHotReloadUnhandledDeviceExceptionXamarinFormsControlGalleryAndroidHideInfoBar="True" />
<UserProperties XamarinHotReloadUnhandledDeviceExceptionXamarinFormsControlGalleryAndroidHideInfoBar="True" TriggeredFromHotReload="False" />
</VisualStudio>
</ProjectExtensions>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,47 @@ protected override void Init()
}),
AutomationId = "ResizeHeaderFooter"
});

if (Device.RuntimePlatform == Device.iOS)
{
Items.Add(new MenuItem()
{
Text = "Zero Margin Header Test",
Command = new Command(() =>
{
FlyoutHeader =
new StackLayout()
{
AutomationId = "ZeroMarginLayout",
Margin = 0,
Children =
{
new Label() { Text = "Header View" }
}
};
FlyoutHeaderTemplate = null;
FlyoutBehavior = FlyoutBehavior.Locked;
}),
AutomationId = "ZeroMarginHeader"
});
}
}


#if UITEST

#if __IOS__
[Test]
public void FlyoutHeaderWithZeroMarginShouldHaveNoY()
{
RunningApp.WaitForElement("PageLoaded");
this.TapInFlyout("ZeroMarginHeader", makeSureFlyoutStaysOpen: true);
var layout = RunningApp.WaitForElement("ZeroMarginLayout")[0].Rect.Y;
Assert.AreEqual(0, layout);
}
#endif

[Test]
public void FlyoutTests()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8" ?>
<controls:TestShell
x:Class="Xamarin.Forms.Controls.Issues.Issue12429"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
xmlns:local="clr-namespace:Xamarin.Forms.Controls.Issues">
<FlyoutItem>
<Shell.ItemTemplate>
<DataTemplate>
<StackLayout Orientation="Horizontal" AutomationId="SmallFlyoutItem" Spacing="0" HeightRequest="{Binding BindingContext.SmallFlyoutItem}" BackgroundColor="LightBlue" >
<Label Text="I'm set to specific height: " TextColor="White" />
<Label Text="{Binding BindingContext.SmallFlyoutItem}" TextColor="White" />
</StackLayout>
</DataTemplate>
</Shell.ItemTemplate>
<ShellContent>
<local:Issue12429Page />
</ShellContent>
</FlyoutItem>
<FlyoutItem>
<Shell.ItemTemplate>
<DataTemplate>
<StackLayout IsVisible="False" BackgroundColor="Black" >
<Label Text="Not Visible" />
</StackLayout>
</DataTemplate>
</Shell.ItemTemplate>
<ShellContent>
<local:Issue12429Page />
</ShellContent>
</FlyoutItem>
<FlyoutItem>
<Shell.ItemTemplate>
<DataTemplate>
<StackLayout BackgroundColor="Purple">
<Label Text="I'm sized to my layout" />
</StackLayout>
</DataTemplate>
</Shell.ItemTemplate>
<ShellContent>
<local:Issue12429Page />
</ShellContent>
</FlyoutItem>
<FlyoutItem>
<Shell.ItemTemplate>
<DataTemplate>
<StackLayout AutomationId="ResizeMe" BackgroundColor="LightGray" HeightRequest="120">
<Button AutomationId="ResizeFlyoutItem" Text="Grow Me" Clicked="ResizeFlyoutItem" />
<Button AutomationId="ResizeFlyoutItemDown" Text="Shrink Me" Clicked="ResizeFlyoutItemDown" />
</StackLayout>
</DataTemplate>
</Shell.ItemTemplate>
<ShellContent>
<local:Issue12429Page />
</ShellContent>
</FlyoutItem>
<FlyoutItem Title="Default Flyout Item. Height is 44 on iOS and UWP. Height is 50 on Android)">
<ShellContent>
<local:Issue12429Page />
</ShellContent>
</FlyoutItem>
</controls:TestShell>
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif


namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 12429, "[Bug] Shell flyout items have a minimum height", PlatformAffected.iOS)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.Shell)]
#endif
public partial class Issue12429 : TestShell
{
public double SmallFlyoutItem { get; }
public double SizeToModifyBy { get; }

public Issue12429()
{
SmallFlyoutItem = 35d;
SizeToModifyBy = 20d;

#if APP
InitializeComponent();


if (Device.RuntimePlatform == Device.Android)
SmallFlyoutItem = SmallFlyoutItem / Device.info.ScalingFactor;

if (Device.RuntimePlatform == Device.Android)
SizeToModifyBy = SizeToModifyBy / Device.info.ScalingFactor;
#endif


this.BindingContext = this;
}

protected override void Init()
{
}

void ResizeFlyoutItem(System.Object sender, System.EventArgs e)
{
((sender as Element).Parent as VisualElement).HeightRequest += SizeToModifyBy;
}

void ResizeFlyoutItemDown(System.Object sender, System.EventArgs e)
{
((sender as Element).Parent as VisualElement).HeightRequest -= SizeToModifyBy;
}

#if UITEST
[Test]
public void FlyoutItemSizesToExplicitHeight()
{
RunningApp.WaitForElement("PageLoaded");
this.ShowFlyout();
var height = RunningApp.WaitForElement("SmallFlyoutItem")[0].Rect.Height;
Assert.That(height, Is.EqualTo(SmallFlyoutItem).Within(1));
}


[Test]
public void FlyoutItemHeightAndWidthIncreaseAndDecreaseCorrectly()
{
RunningApp.WaitForElement("PageLoaded");
this.ShowFlyout();
var initialHeight = RunningApp.WaitForElement("ResizeMe")[0].Rect.Height;

TapInFlyout("ResizeFlyoutItem", makeSureFlyoutStaysOpen: true);
var newHeight = RunningApp.WaitForElement("ResizeMe")[0].Rect.Height;
Assert.That(newHeight - initialHeight, Is.EqualTo(SizeToModifyBy).Within(1));

TapInFlyout("ResizeFlyoutItemDown", makeSureFlyoutStaysOpen: true);
newHeight = RunningApp.WaitForElement("ResizeMe")[0].Rect.Height;
Assert.That(initialHeight, Is.EqualTo(newHeight).Within(1));

TapInFlyout("ResizeFlyoutItemDown", makeSureFlyoutStaysOpen: true);
newHeight = RunningApp.WaitForElement("ResizeMe")[0].Rect.Height;
Assert.That(initialHeight - newHeight, Is.EqualTo(SizeToModifyBy).Within(1));

}
#endif

}


[Preserve(AllMembers = true)]
public class Issue12429Page : ContentPage
{
public Issue12429Page()
{
Background = SolidColorBrush.White;
var label = new Label
{
Text = "Flyout Item 1: Explicit Height of 35, Flyout Item 2: will grow and shrink when you click the buttons, Flyout Item 3: doesn't exist, and Flyout Item 4: uses the default platform sizes.",
VerticalTextAlignment = TextAlignment.Center,
TextColor = Color.Black,
AutomationId = "PageLoaded"
};

Content = new StackLayout()
{
Children =
{
new Label
{
Text = "Flyout Item 1: Explicit Height of 35.",
VerticalTextAlignment = TextAlignment.Center,
TextColor = Color.Black,
AutomationId = "PageLoaded"
},
new Label
{
Text = "Flyout Item 2: Height sizes to the content.",
VerticalTextAlignment = TextAlignment.Center,
TextColor = Color.Black
},
new Label
{
Text = "Flyout Item 3: will grow and shrink when you click the buttons.",
VerticalTextAlignment = TextAlignment.Center,
TextColor = Color.Black
},
new Label
{
Text = "Flyout Item 4: doesn't exist. You should only see 4 Flyout Items",
VerticalTextAlignment = TextAlignment.Center,
TextColor = Color.Black
},
new Label
{
Text = "Flyout Item 5: uses the default height if no templates are used.",
VerticalTextAlignment = TextAlignment.Center,
TextColor = Color.Black
}
}
};
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<DependentUpon>Issue12344.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue12246.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12429.xaml.cs">
<DependentUpon>Issue12429.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue12652.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12714.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue2447.xaml.cs">
Expand Down Expand Up @@ -2566,9 +2570,13 @@
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue12429.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11853.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
</Project>
3 changes: 3 additions & 0 deletions Xamarin.Forms.Core/Shell/BaseShellItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str
if (Device.RuntimePlatform == Device.Android)
defaultGridClass.Setters.Add(new Setter { Property = Grid.HeightRequestProperty, Value = 50 });
else
defaultGridClass.Setters.Add(new Setter { Property = Grid.HeightRequestProperty, Value = 44 });
ColumnDefinitionCollection columnDefinitions = new ColumnDefinitionCollection();
Expand Down
Loading

0 comments on commit acb4af5

Please sign in to comment.