Skip to content

Commit

Permalink
Merge pull request #2945 from unoplatform/mergify/bp/release/beta/2.1…
Browse files Browse the repository at this point in the history
…/pr-2933

[iOS] Fix text in CommandBar title not appearing after navigation (bp #2933)
  • Loading branch information
jeromelaban authored Apr 6, 2020
2 parents 22343e8 + 396aaa0 commit 2f98f00
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 4 deletions.
1 change: 1 addition & 0 deletions build/ios-uitest-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ else
namespace = 'SamplesApp.UITests.Microsoft_UI_Xaml_Controls.NumberBoxTests' or \
namespace = 'SamplesApp.UITests.Windows_UI_Xaml_Controls.TextBoxTests' or \
namespace = 'SamplesApp.UITests.Windows_UI_Xaml_Controls.PivotTests' or \
namespace = 'SamplesApp.UITests.Windows_UI_Xaml_Controls.CommandBarTests' or \
namespace = 'SamplesApp.UITests.Windows_UI_Xaml_Controls.ComboBoxTests' or \
namespace = 'SamplesApp.UITests.Windows_UI_Xaml_Media_Animation.DoubleAnimation_Tests' or \
namespace = 'SamplesApp.UITests.Windows_UI_Xaml_Controls.BorderTests'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Uno.UITest.Helpers;
using Uno.UITest.Helpers.Queries;

namespace SamplesApp.UITests.Windows_UI_Xaml_Controls.ComboBoxTests
namespace SamplesApp.UITests.Windows_UI_Xaml_Controls.CommandBarTests
{
[TestFixture]
public partial class NativeCommandBar_Tests : SampleControlUITestBase
Expand Down Expand Up @@ -62,5 +62,27 @@ public void NativeCommandBar_Content_Alignment_Automated()

TakeScreenshot("Left");
}

[Test]
[AutoRetry]
public void When_TextBlock_Centred_Native_Frame()
{
Run("UITests.Windows_UI_Xaml_Controls.CommandBar.CommandBar_Native_Frame");

_app.WaitForElement("NavigateInitialButton");
_app.FastTap("NavigateInitialButton");

_app.WaitForElement("NavigateDetailButton");
_app.FastTap("NavigateDetailButton");

_app.WaitForElement("NavigateBackButton");
_app.FastTap("NavigateBackButton");

_app.WaitForElement("CommandBarTitleText");
var rect = _app.GetRect("CommandBarTitleText");

Assert.Greater(rect.Height, 1);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Uno.UITest.Helpers;
using Uno.UITest.Helpers.Queries;

namespace SamplesApp.UITests.Windows_UI_Xaml_Controls.ComboBoxTests
namespace SamplesApp.UITests.Windows_UI_Xaml_Controls.CommandBarTests
{
[TestFixture]
public partial class XamlCommandBar_Tests : SampleControlUITestBase
Expand Down
21 changes: 21 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CommandBar\CommandBar_Native_Frame.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CommandBar\CommandBar_Native_With_Content.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand All @@ -557,6 +561,14 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CommandBar\Native_Frame\Page_Detail.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CommandBar\Native_Frame\Page_With_CommandBar_TextBlock.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ContentControlTestsControl\ContentControlNoTemplateNoContent.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -3398,6 +3410,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ComboBox\ComboBox_VisibleBounds.xaml.cs">
<DependentUpon>ComboBox_VisibleBounds.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CommandBar\CommandBar_Native_Frame.xaml.cs">
<DependentUpon>CommandBar_Native_Frame.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CommandBar\CommandBar_Native_With_Content.xaml.cs">
<DependentUpon>CommandBar_Native_With_Content.xaml</DependentUpon>
</Compile>
Expand All @@ -3410,6 +3425,12 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\BitmapIconTests\BitmapIcon_Generic.xaml.cs">
<DependentUpon>BitmapIcon_Generic.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CommandBar\Native_Frame\Page_Detail.xaml.cs">
<DependentUpon>Page_Detail.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CommandBar\Native_Frame\Page_With_CommandBar_TextBlock.xaml.cs">
<DependentUpon>Page_With_CommandBar_TextBlock.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ContentControlTestsControl\ContentControlNoTemplateNoContent.xaml.cs">
<DependentUpon>ContentControlNoTemplateNoContent.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<UserControl x:Class="UITests.Windows_UI_Xaml_Controls.CommandBar.CommandBar_Native_Frame"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml_Controls.CommandBar"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:xamarin="http://uno.ui/xamarin"
mc:Ignorable="d xamarin"
d:DesignHeight="300"
d:DesignWidth="400">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Frame x:Name="hostFrame"
xamarin:Style="{StaticResource NativeDefaultFrame}" />
<Button x:Name="NavigateInitialButton"
Grid.Row="1"
Content="Navigate to first page"
Click="Navigate_Initial" />
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using UITests.Windows_UI_Xaml_Controls.CommandBar.Native_Frame;
using Uno.UI.Samples.Controls;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace UITests.Windows_UI_Xaml_Controls.CommandBar
{
[Sample]
public sealed partial class CommandBar_Native_Frame : UserControl
{
public CommandBar_Native_Frame()
{
this.InitializeComponent();
}

private void Navigate_Initial(object sender, RoutedEventArgs args)
{
hostFrame.Navigate(typeof(Page_With_CommandBar_TextBlock));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Page x:Class="UITests.Windows_UI_Xaml_Controls.CommandBar.Native_Frame.Page_Detail"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml_Controls.CommandBar.Native_Frame"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<StackPanel>
<CommandBar Content="Details" />
<TextBlock Text="A page providing more detail" />
<Button x:Name="NavigateBackButton"
Content="Navigate back"
Click="Navigate_Back" />
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace UITests.Windows_UI_Xaml_Controls.CommandBar.Native_Frame
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Page_Detail : Page
{
public Page_Detail()
{
this.InitializeComponent();
}

private void Navigate_Back(object sender, RoutedEventArgs args) => Frame.GoBack();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Page x:Class="UITests.Windows_UI_Xaml_Controls.CommandBar.Native_Frame.Page_With_CommandBar_TextBlock"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml_Controls.CommandBar.Native_Frame"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:xamarin="http://uno.ui/xamarin"
mc:Ignorable="d xamarin"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<!--<RowDefinition Height="Auto" />-->
</Grid.RowDefinitions>
<CommandBar xamarin:Style="{StaticResource NativeDefaultCommandBar}">
<CommandBar.Content>
<TextBlock x:Name="CommandBarTitleText"
Text="Page title"
VerticalAlignment="Center" />
</CommandBar.Content>
</CommandBar>
<Border Grid.Row="1"
Margin="40"
BorderBrush="Blue"
BorderThickness="2"
CornerRadius="5">
<StackPanel>
<TextBlock Text="This is the content of the page" />
<Button x:Name="NavigateDetailButton"
Content="Navigate to details"
Click="Navigate_Onward" />
</StackPanel>
</Border>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace UITests.Windows_UI_Xaml_Controls.CommandBar.Native_Frame
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Page_With_CommandBar_TextBlock : Page
{
public Page_With_CommandBar_TextBlock()
{
this.InitializeComponent();
}

private void Navigate_Onward(object sender, RoutedEventArgs args)
{
Frame.Navigate(typeof(Page_Detail));
}

}
}
11 changes: 9 additions & 2 deletions src/Uno.UI/Controls/CommandBarNavigationItemRenderer.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ internal partial class TitleView : Border
{
private bool _blockReentrantMeasure;
private Size _childSize;
private Size? _lastAvailableSize;

public TitleView()
{
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
Expand Down Expand Up @@ -167,6 +169,8 @@ protected override Size MeasureOverride(Size availableSize)
{
_blockReentrantMeasure = true;

_lastAvailableSize = availableSize;

// By default, iOS will horizontally center the TitleView inside the UINavigationBar,
// ignoring the size of the left and right buttons.

Expand Down Expand Up @@ -207,7 +211,10 @@ public override CGRect Frame
get { return base.Frame; }
set
{
if (!UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
if (!UIDevice.CurrentDevice.CheckSystemVersion(11, 0)
// iOS likes to mix things up by calling SizeThatFits with zero Height for no apparent reason (eg when navigating back to a page). When
// this happens, we need to remeasure with the correct size to ensure children are laid out correctly.
|| (_lastAvailableSize?.Height == 0 && value.Height != 0))
{
// This allows text trimming when there are more AppBarButtons
var availableSize = value.Size;
Expand All @@ -218,4 +225,4 @@ public override CGRect Frame
}
}
}
}
}
2 changes: 2 additions & 0 deletions src/Uno.UI/Extensions/UIViewExtensions.iOSmacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Uno.Logging;
using Windows.UI.Core;
using Uno.UI.Controls;
using Windows.UI.Xaml.Controls;

#if XAMARIN_IOS_UNIFIED
using Foundation;
Expand Down Expand Up @@ -594,6 +595,7 @@ StringBuilder AppendView(_View innerView)
.Append($" {(innerView.Hidden ? "Hidden" : "Visible")}")
#endif
.Append(uiElement?.NeedsClipToSlot ?? false ? " CLIPPED_TO_SLOT" : "")
.Append(innerView is TextBlock textBlock ? $" Text=\"{textBlock.Text}\"" : "")
.AppendLine();
}
}
Expand Down

0 comments on commit 2f98f00

Please sign in to comment.