Create a specific XAML page for the ShellPageWrapper used for Shell Navigation (#11766)

* Convert Shell Page to Xaml page

* - Add Shell store tests

* - disable appx for pages and copy from correct ui test folder

* - fix yaml checks

* - force UseDotNetNativeToolchain false

fixes #11736
This commit is contained in:
Shane Neuville 2020-08-24 15:05:44 -06:00 коммит произвёл GitHub
Родитель 22f5bf8f5d
Коммит f32b5ea85c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
11 изменённых файлов: 165 добавлений и 54 удалений

Просмотреть файл

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Linq;
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
using System.Threading;
using System.ComponentModel;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.Shell)]
#endif
public class ShellStoreTests
{
#if UITEST
IApp RunningApp;
[SetUp]
public void ShellStoreSetup()
{
RunningApp = AppSetup.Setup();
if (RunningApp.Query("SwapRoot - Store Shell").Length > 0)
RunningApp.Tap("SwapRoot - Store Shell");
else
RunningApp.NavigateTo("SwapRoot - Store Shell");
RunningApp.WaitForElement("Welcome to the HomePage");
}
[Test]
public void LoadsWithoutCrashing()
{
RunningApp.WaitForElement("Welcome to the HomePage");
}
#endif
}
}

Просмотреть файл

@ -824,6 +824,7 @@
<DependentUpon>Issue6698View2.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)ShellStoreTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8145.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue10222.cs" />

Просмотреть файл

@ -29,6 +29,7 @@ namespace Xamarin.Forms.Controls
{
public const string ChangeRoot = "com.xamarin.ChangeRoot";
}
[Preserve(AllMembers = true)]
internal class CoreCarouselPage : CarouselPage
{
@ -39,16 +40,20 @@ namespace Xamarin.Forms.Controls
Children.Add(new CoreRootPage(this, NavigationBehavior.PushModalAsync) { Title = "Page 2" });
}
}
[Preserve(AllMembers = true)]
internal class CoreContentPage : ContentPage
{
public CoreRootView CoreRootView { get; }
public CoreContentPage()
{
On<iOS>().SetUseSafeArea(true);
AutomationId = "ContentPageRoot";
Content = new StackLayout { Children = { new CoreRootView(), new CorePageView(this, NavigationBehavior.PushModalAsync) } };
CoreRootView = new CoreRootView();
Content = new StackLayout { Children = { CoreRootView, new CorePageView(this, NavigationBehavior.PushModalAsync) } };
}
}
[Preserve(AllMembers = true)]
internal class CoreMasterDetailPage : MasterDetailPage
{
@ -522,16 +527,17 @@ namespace Xamarin.Forms.Controls
}
readonly Dictionary<string, GalleryPageFactory> _titleToPage;
public async Task PushPage(string pageTitle)
public async Task<bool> PushPage(string pageTitle)
{
GalleryPageFactory pageFactory = null;
if (!_titleToPage.TryGetValue(pageTitle, out pageFactory))
return;
return false;
var page = pageFactory.Realize();
await PushPage(page);
return true;
}
public void FilterPages(string filter)
@ -545,6 +551,8 @@ namespace Xamarin.Forms.Controls
[Preserve(AllMembers = true)]
internal class CoreRootPage : ContentPage
{
CoreRootView CoreRootView { get; }
public CoreRootPage(Page rootPage, NavigationBehavior navigationBehavior = NavigationBehavior.PushAsync)
{
ValidateRegistrar();
@ -573,7 +581,19 @@ namespace Xamarin.Forms.Controls
Command = new Command(async () =>
{
if (!string.IsNullOrEmpty(searchBar.Text))
await corePageView.PushPage(searchBar.Text);
{
if(!(await corePageView.PushPage(searchBar.Text)))
{
foreach(CoreViewContainer item in CoreRootView.ItemsSource)
{
if(item.Name == searchBar.Text)
{
CoreRootView.SelectedItem = item;
break;
}
}
}
}
else
await Navigation.PushModalAsync(TestCases.GetTestCases());
})
@ -607,10 +627,11 @@ namespace Xamarin.Forms.Controls
this.SetAutomationPropertiesName("Gallery");
this.SetAutomationPropertiesHelpText("Lists all gallery pages");
CoreRootView = new CoreRootView();
Content = new AbsoluteLayout
{
Children = {
{ new CoreRootView (), new Rectangle(0, 0.0, 1, 0.35), AbsoluteLayoutFlags.All },
{ CoreRootView, new Rectangle(0, 0.0, 1, 0.35), AbsoluteLayoutFlags.All },
{ stackLayout, new Rectangle(0, 0.5, 1, 0.30), AbsoluteLayoutFlags.All },
{ corePageView, new Rectangle(0, 1.0, 1.0, 0.35), AbsoluteLayoutFlags.All },
}

Просмотреть файл

@ -148,6 +148,8 @@ namespace Xamarin.Forms.Core.UITests
{
internal static class AppExtensions
{
const string goToTestButtonQuery = "* marked:'GoToTestButton'";
public static AppRect ScreenBounds(this IApp app)
{
return app.Query(Queries.Root()).First().Rect;
@ -163,14 +165,13 @@ namespace Xamarin.Forms.Core.UITests
NavigateToGallery(app, page, null);
}
public static void NavigateToGallery(this IApp app, string page, string visual)
public static void NavigateTo(this IApp app, string text)
{
const string goToTestButtonQuery = "* marked:'GoToTestButton'";
app.WaitForElement(q => q.Raw(goToTestButtonQuery), "Timed out waiting for Go To Test button to appear", TimeSpan.FromMinutes(2));
var text = Regex.Match(page, "'(?<text>[^']*)'").Groups["text"].Value;
NavigateTo(app, text, null);
}
public static void NavigateTo(this IApp app, string text, string visual)
{
app.WaitForElement("SearchBar");
app.ClearText(q => q.Raw("* marked:'SearchBar'"));
app.EnterText(q => q.Raw("* marked:'SearchBar'"), text);
@ -187,7 +188,14 @@ namespace Xamarin.Forms.Core.UITests
app.Tap(q => q.Raw(goToTestButtonQuery));
}
app.WaitForNoElement(o => o.Raw(goToTestButtonQuery), "Timed out waiting for Go To Test button to disappear", TimeSpan.FromMinutes(2));
app.WaitForNoElement(o => o.Raw(goToTestButtonQuery), "Timed out waiting for Go To Test button to disappear", TimeSpan.FromMinutes(1));
}
public static void NavigateToGallery(this IApp app, string page, string visual)
{
app.WaitForElement(q => q.Raw(goToTestButtonQuery), "Timed out waiting for Go To Test button to appear", TimeSpan.FromMinutes(2));
var text = Regex.Match(page, "'(?<text>[^']*)'").Groups["text"].Value;
NavigateTo(app, text, visual);
}

Просмотреть файл

@ -19,6 +19,8 @@ namespace Xamarin.Forms.Core.UITests
{
if (Session == null)
Session = CreateWindowsDriver();
else
Reset();
return new WinDriverApp(Session);
}

Просмотреть файл

@ -0,0 +1,13 @@
<Page
x:Class="Xamarin.Forms.Platform.UWP.ShellPageWrapper"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Xamarin.Forms.Platform.UAP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<ContentPresenter Name="Root" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
</ContentPresenter>
</Page>

Просмотреть файл

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
namespace Xamarin.Forms.Platform.UWP
{
partial class ShellPageWrapper
{
public ShellPageWrapper()
{
InitializeComponent();
}
public Page Page { get; set; }
protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
LoadPage();
}
protected override void OnNavigatedFrom(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
Root.Content = null;
}
public void LoadPage()
{
if (Page != null)
{
var container = Page.GetOrCreateRenderer().ContainerElement;
Root.Content = container;
container.Loaded -= OnPageLoaded;
container.Loaded += OnPageLoaded;
}
}
private void OnPageLoaded(object sender, RoutedEventArgs e)
{
var frameworkElement = sender as FrameworkElement;
Page.Layout(new Rectangle(0, 0, frameworkElement.ActualWidth, frameworkElement.ActualHeight));
}
}
}

Просмотреть файл

@ -162,43 +162,6 @@ namespace Xamarin.Forms.Platform.UWP
}
}
internal class ShellPageWrapper : Windows.UI.Xaml.Controls.Page
{
public ShellPageWrapper()
{
}
public Page Page { get; set; }
protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
LoadPage();
}
protected override void OnNavigatedFrom(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
Content = null;
}
public void LoadPage()
{
if (Page != null)
{
var container = Page.GetOrCreateRenderer().ContainerElement;
Content = container;
container.Loaded -= OnPageLoaded;
container.Loaded += OnPageLoaded;
}
}
private void OnPageLoaded(object sender, RoutedEventArgs e)
{
var frameworkElement = sender as FrameworkElement;
Page.Layout(new Rectangle(0, 0, frameworkElement.ActualWidth, frameworkElement.ActualHeight));
}
}
NavigationTransitionInfo GetTransitionInfo(ShellNavigationSource navSource)
{
switch (navSource)

Просмотреть файл

@ -31,6 +31,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Shell\ShellPageWrapper.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="CollectionView\ItemsViewStyles.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

Просмотреть файл

@ -470,11 +470,13 @@ Task ("cg-uwp-build-tests")
.WithProperty("PackageCertificateThumbprint", "a59087cc92a9a8117ffdb5255eaa155748f9f852")
.WithProperty("PackageCertificateKeyFile", "Xamarin.Forms.ControlGallery.WindowsUniversal_TemporaryKey.pfx")
.WithProperty("PackageCertificatePassword", "")
// The platform unit tests can't run when UseDotNetNativeToolchain is set to true so we force it off here
.WithProperty("UseDotNetNativeToolchain", "false")
.WithRestore()
);
MSBuild("Xamarin.Forms.Core.Windows.UITests\\Xamarin.Forms.Core.Windows.UITests.csproj",
GetMSBuildSettings().WithRestore());
GetMSBuildSettings(buildConfiguration:"Debug").WithRestore());
});
Task ("cg-uwp-deploy")

Просмотреть файл

@ -193,12 +193,12 @@ steps:
TargetFolder: ${{ parameters.artifactsTargetFolder }}
- script: build.cmd -Target cg-uwp-build-tests -ScriptArgs '-BUILD_CONFIGURATION="$(BuildConfiguration)"'
condition: eq(variables['BuildConfiguration'], 'Debug')
condition: and(eq(variables['BuildConfiguration'], 'Release'), ne('${{ parameters.includePages }}', true))
displayName: 'Build Tests and APPX'
- task: CopyFiles@2
displayName: 'Copy Appx Packages'
condition: eq(variables['BuildConfiguration'], 'Debug')
condition: and(eq(variables['BuildConfiguration'], 'Release'), ne('${{ parameters.includePages }}', true))
inputs:
Contents: |
Xamarin.Forms.ControlGallery.WindowsUniversal/AppPackages/*/*
@ -220,9 +220,9 @@ steps:
- task: CopyFiles@2
displayName: 'Copy UITest Files'
condition: eq(variables['BuildConfiguration'], 'Debug')
condition: and(eq(variables['BuildConfiguration'], 'Release'), ne('${{ parameters.includePages }}', true))
inputs:
SourceFolder: Xamarin.Forms.Core.Windows.UITests/bin/$(BuildConfiguration)/
SourceFolder: Xamarin.Forms.Core.Windows.UITests/bin/Debug/
TargetFolder: '$(build.artifactstagingdirectory)/UITests'
- task: CopyFiles@2