Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert to using Navigation Page Shims #1495

Merged
merged 8 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Compatibility/ControlGallery/src/WinUI/App.xaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<Application
<local1:MiddleApp
xmlns:local1="using:Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI"
x:Class="Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WinUI3Desktop">

<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Microsoft.Maui.Controls.Compatibility/WinUI/Resources.xbf" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<!-- Other merged dictionaries here -->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

</Application>
</local1:MiddleApp>
16 changes: 11 additions & 5 deletions src/Compatibility/ControlGallery/src/WinUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@

namespace Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI
{
public class MiddleApp : MauiWinUIApplication<Startup>
{
}

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Microsoft.UI.Xaml.Application
sealed partial class App : MiddleApp
{
private UI.Xaml.Window m_window;
public static bool RunningAsUITests { get; private set; }
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
Expand All @@ -38,22 +41,25 @@ public App()
//Suspending += OnSuspending;
}

public override MauiWinUIWindow CreateWindow()
{
return new MainPage();
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs e)
{
base.OnLaunched(e);
if (!String.IsNullOrWhiteSpace(e.Arguments) &&
e.Arguments.Contains("RunningAsUITests"))
{
RunningAsUITests = true;
ControlGallery.App.PreloadTestCasesIssuesList = false;
}

m_window = new MainPage();
Maui.Controls.Compatibility.Forms.Init(m_window as MainPage);
}

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions src/Compatibility/ControlGallery/src/WinUI/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<forms:WindowsPage
<local1:MauiWinUIWindow
xmlns:local1="using:Microsoft.Maui"
x:Class="Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand All @@ -7,4 +8,4 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:forms="using:Microsoft.Maui.Controls.Compatibility.Platform.UWP"
mc:Ignorable="d">
</forms:WindowsPage>
</local1:MauiWinUIWindow>
24 changes: 9 additions & 15 deletions src/Compatibility/ControlGallery/src/WinUI/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ namespace Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage
public sealed partial class MainPage : MauiWinUIWindow
{
ControlGallery.App _app;

public MainPage()
{
InitializeComponent();
Expand All @@ -47,19 +45,12 @@ public MainPage()
// When the native binding gallery loads up, it'll let us know so we can set up the native bindings
MessagingCenter.Subscribe<NativeBindingGalleryPage>(this, NativeBindingGalleryPage.ReadyForNativeBindingsMessage, AddNativeBindings);

this.Activated += MainPage_Activated;
}

public override Application CreateApplication()
{
_app = new ControlGallery.App();
return _app;
}

public override void LoadApplication(Application application)
private void MainPage_Activated(object sender, UI.Xaml.WindowActivatedEventArgs args)
{
base.LoadApplication(application);

_app.PropertyChanged += _app_PropertyChanged;
Application.Current.PropertyChanged += _app_PropertyChanged;
WireUpKeyDown();
}

Expand Down Expand Up @@ -92,12 +83,15 @@ void OnKeyDown(object sender, KeyRoutedEventArgs args)
{
if (args.Key == VirtualKey.Escape)
{
_app.Reset();
(Application.Current as ControlGallery.App)
.Reset();

args.Handled = true;
}
else if (args.Key == VirtualKey.F1)
{
_app.PlatformTest();
(Application.Current as ControlGallery.App)
.PlatformTest();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ void OnCreate(
Profile.FramePartition("SetSupportActionBar");
AToolbar bar = null;

if (ToolbarResource == 0)
if (_toolbarResource == 0)
{
ToolbarResource = Resource.Layout.toolbar;
}

if (TabLayoutResource == 0)
if (_tabLayoutResource == 0)
{
TabLayoutResource = Resource.Layout.tabbar;
_tabLayoutResource = Resource.Layout.tabbar;
}

if (ToolbarResource != 0)
Expand Down Expand Up @@ -504,9 +504,31 @@ internal class DefaultApplication : Application

public static event BackButtonPressedEventHandler BackPressed;

public static int TabLayoutResource { get; set; }
static int _tabLayoutResource;
public static int TabLayoutResource
{
get
{
if (_tabLayoutResource == 0)
return Resource.Layout.tabbar;

return _tabLayoutResource;
}
set => _tabLayoutResource = value;
}

public static int ToolbarResource { get; set; }
static int _toolbarResource;
public static int ToolbarResource
{
get
{
if (_toolbarResource == 0)
return Resource.Layout.toolbar;

return _toolbarResource;
}
set => _toolbarResource = value;
}

#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,7 @@ void UpdateToolbar()
toggle.SyncState();
}

var activity = (AppCompatActivity)context.GetActivity();
var icon = new DrawerArrowDrawable(activity.SupportActionBar.ThemedContext);
var icon = new DrawerArrowDrawable(context.GetThemedContext());
icon.Progress = 1;
bar.NavigationIcon = icon;

Expand Down
2 changes: 1 addition & 1 deletion src/Compatibility/Core/src/WinUI/Resources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<Setter Property="FontWeight" Value="Bold" />
</Style>

<Style x:Key="MauiRootContainerStyle" TargetType="Panel">
<Style x:Key="RootContainerStyle" TargetType="Panel">
<Setter Property="Background" Value="{ThemeResource ApplicationPageBackgroundThemeBrush}" />
</Style>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1472,10 +1472,10 @@ public override async void DidMoveToParentViewController(UIViewController parent

public override UIViewController ChildViewControllerForStatusBarHidden()
{
return (UIViewController)Platform.GetRenderer(Current);
return Platform.GetRenderer(Current).ViewController;
}

public override UIViewController ChildViewControllerForHomeIndicatorAutoHidden => (UIViewController)Platform.GetRenderer(Current);
public override UIViewController ChildViewControllerForHomeIndicatorAutoHidden => Platform.GetRenderer(Current).ViewController;

void IEffectControlProvider.RegisterEffect(Effect effect)
{
Expand Down
1 change: 0 additions & 1 deletion src/Controls/src/Core/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public static class AppHostBuilderExtensions
{
static readonly Dictionary<Type, Type> DefaultMauiControlHandlers = new Dictionary<Type, Type>
{
{ typeof(NavigationPage), typeof(NavigationPageHandler) },
#if WINDOWS
{ typeof(Shell), typeof(ShellHandler) },
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/Core/src/Platform/Windows/MauiWinUIApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ namespace Microsoft.Maui
public class MauiWinUIApplication<TStartup> : MauiWinUIApplication
where TStartup : IStartup, new()
{
public virtual UI.Xaml.Window CreateWindow() =>
new MauiWinUIWindow();

protected override void OnLaunched(UI.Xaml.LaunchActivatedEventArgs args)
{
LaunchActivatedEventArgs = args;
Expand Down
4 changes: 4 additions & 0 deletions src/Core/src/Platform/Windows/Styles/Resources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
<x:Boolean x:Key="MicrosoftMauiCoreIncluded">true</x:Boolean>

<uwp:ColorConverter x:Key="ColorConverter" />

<Style x:Key="MauiRootContainerStyle" TargetType="Panel">
<Setter Property="Background" Value="{ThemeResource ApplicationPageBackgroundThemeBrush}" />
</Style>

</ResourceDictionary>