Skip to content

Commit

Permalink
fix: ios navbar lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
rajamatt committed Feb 4, 2025
1 parent 06822e9 commit 54bd5be
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@
xmlns:utu="using:Uno.Toolkit.UI"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d ios">
<Page.Resources>
<Style x:Key="SmallFlyoutPresenterStyle"
TargetType="FlyoutPresenter">
<Setter Property="MinHeight" Value="300" />
<Setter Property="MinWidth" Value="300" />
</Style>
</Page.Resources>

<Grid>

<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<utu:NavigationBar Content="First Page"
MainCommandMode="Action"
Expand All @@ -22,6 +30,7 @@
<utu:NavigationBar.MainCommand>
<AppBarButton Click="NavigateBack"
Label="Close"
AutomationProperties.AutomationId="FluentPage1NavBarMainCommand"
Style="{StaticResource DefaultAppBarButtonStyle}">
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/CloseIcon.png" />
Expand Down Expand Up @@ -72,5 +81,34 @@
<Button Click="NavigateToNextPage"
Content="Navigate To Second Page" />
</StackPanel>

<StackPanel Grid.Row="2"
VerticalAlignment="Stretch">
<Button AutomationProperties.AutomationId="OpenPage2FlyoutButton"
Content="Open Page2 in flyout"
Click="OpenPage2Flyout"
Grid.Row="2">
<Button.Flyout>
<Flyout FlyoutPresenterStyle="{StaticResource SmallFlyoutPresenterStyle}">
<Grid>
<Frame x:Name="Page2FlyoutFrame" />
</Grid>
</Flyout>
</Button.Flyout>
</Button>

<Button AutomationProperties.AutomationId="OpenPage3FlyoutButton"
Content="Open Page3 in flyout"
Click="OpenPage3Flyout"
Grid.Row="2">
<Button.Flyout>
<Flyout FlyoutPresenterStyle="{StaticResource SmallFlyoutPresenterStyle}">
<Grid>
<Frame x:Name="Page3FlyoutFrame" />
</Grid>
</Flyout>
</Button.Flyout>
</Button>
</StackPanel>
</Grid>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ public FluentNavigationBarSampleNestedPage()
private void NavigateToNextPage(object sender, RoutedEventArgs e) => Frame.Navigate(typeof(FluentNavigationBarSampleNestedPage2));

private void NavigateBack(object sender, RoutedEventArgs e) => Shell.GetForCurrentView().BackNavigateFromNestedSample();

private void OpenPage2Flyout(object sender, RoutedEventArgs e) => Page2FlyoutFrame.Navigate(typeof(FluentNavigationBarSampleNestedPage2));

private void OpenPage3Flyout(object sender, RoutedEventArgs e) => Page3FlyoutFrame.Navigate(typeof(FluentNavigationBarSampleNestedPage3));
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
<utu:NavigationBar Content="Second Page"
AutomationProperties.AutomationId="FluentPage2NavBar"
Style="{StaticResource DefaultNavigationBar}">
<utu:NavigationBar.MainCommand>
<AppBarButton Click="NavigateBack"
Label="Close"
AutomationProperties.AutomationId="FluentPage2NavBarMainCommand"
Style="{StaticResource DefaultAppBarButtonStyle}">
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/CloseIcon.png" />
</AppBarButton.Icon>
</AppBarButton>
</utu:NavigationBar.MainCommand>
<utu:NavigationBar.PrimaryCommands>
<AppBarButton Label="More"
Style="{StaticResource DefaultAppBarButtonStyle}" />
Expand All @@ -40,6 +50,10 @@
to navigate back.
</TextBlock>

<Button AutomationProperties.AutomationId="NavigateToThirdButton"
Click="NavigateToThird"
Content="Navigate to Third" />

<Button Click="NavigateBack"
Content="Navigate Back" />
</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public FluentNavigationBarSampleNestedPage2()
}

private void NavigateBack(object sender, RoutedEventArgs e) => Frame.GoBack();

private void NavigateToThird(object sender, RoutedEventArgs e) => Frame.Navigate(typeof(FluentNavigationBarSampleNestedPage3));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Page x:Class="Uno.Toolkit.Samples.Content.NestedSamples.FluentNavigationBarSampleNestedPage3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Uno.Toolkit.Samples.Content.NestedSamples"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:utu="using:Uno.Toolkit.UI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<utu:NavigationBar Content="Third Page"
AutomationProperties.AutomationId="FluentPage3NavBar"
Style="{StaticResource DefaultNavigationBar}">
<utu:NavigationBar.MainCommand>
<AppBarButton Click="NavigateBack"
Label="Back"
AutomationProperties.AutomationId="FluentPage3NavBarMainCommand"
Style="{StaticResource DefaultAppBarButtonStyle}">
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/CloseIcon.png" />
</AppBarButton.Icon>
</AppBarButton>
</utu:NavigationBar.MainCommand>
</utu:NavigationBar>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.Toolkit.UI;
using Windows.Foundation;
using Windows.Foundation.Collections;
#if IS_WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
#else
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
#endif

namespace Uno.Toolkit.Samples.Content.NestedSamples;

public sealed partial class FluentNavigationBarSampleNestedPage3 : Page
{
public FluentNavigationBarSampleNestedPage3()
{
this.InitializeComponent();
}

private void NavigateBack(object sender, RoutedEventArgs e) => Frame.GoBack();
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Content\NestedSamples\FluentNavigationBarSampleNestedPage1.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Content\NestedSamples\FluentNavigationBarSampleNestedPage2.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Content\NestedSamples\FluentNavigationBarSampleNestedPage3.xaml.cs">
<DependentUpon>FluentNavigationBarSampleNestedPage3.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Content\NestedSamples\M3MaterialBottomBarSampleNestedPage.xaml.cs">
<DependentUpon>M3MaterialBottomBarSampleNestedPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -344,6 +347,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Content\NestedSamples\FluentNavigationBarSampleNestedPage3.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Content\NestedSamples\M3MaterialBottomBarSampleNestedPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ public partial class NativeNavigationBarPresenter

public NativeNavigationBarPresenter()
{
Loaded += OnLoaded;
Unloaded += OnUnloaded;
}

private void OnLoaded(object sender, RoutedEventArgs e)
{
OnOwnerChanged();
}

private void OnUnloaded(object sender, RoutedEventArgs e)
{
_mainCommandClickHandler.Disposable = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ public partial class NativeNavigationBarPresenter

public NativeNavigationBarPresenter()
{
Loaded += OnLoaded;
Unloaded += OnUnloaded;
}

private void OnLoaded(object sender, RoutedEventArgs e)
{
OnOwnerChanged();
}

private void OnUnloaded(object sender, RoutedEventArgs e)
{
_statusBarSubscription.Disposable = null;
Expand Down Expand Up @@ -141,8 +147,6 @@ protected override Size MeasureOverride(Size size)

return measuredSize;
}


}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,30 @@ public void NavBar_AppBarButton_With_Icon_Click()

App.WaitForElement("FluentPage2NavBar", "Timed out waiting for Page 2 Nav Bar");
}

[Test]
[AutoRetry]
public void NavBar_Can_Close_Flyout_With_MainCommand()
{
NavigateToNestedSample("FluentNavigationBarSampleNestedPage");
App.Tap("OpenPage2FlyoutButton");
App.WaitForElement("FluentPage2NavBar", "Timed out waiting for Page 2 Nav Bar");
App.Tap("NavigateToThirdButton");
App.WaitForElement("FluentPage3NavBar", "Timed out waiting for Page 3 Nav Bar");

PlatformHelpers.On(
iOS: () => App.Tap("FluentPage3NavBarMainCommand"),
Android: () => App.Tap(q => q.Marked("FluentPage3NavBar").Descendant("AppCompatImageButton"))
);

App.WaitForElement("FluentPage2NavBar", "Timed out waiting for Page 2 Nav Bar");

PlatformHelpers.On(
iOS: () => App.Tap("FluentPage2NavBarMainCommand"),
Android: () => App.Tap(q => q.Marked("FluentPage2NavBar").Descendant("AppCompatImageButton"))
);

App.WaitForElement("FluentPage1NavBar", "Timed out waiting for Page 1 Nav Bar");
}
}
}

0 comments on commit 54bd5be

Please sign in to comment.