From f9deaa5bf42c4fd9adb0d8c5b2c46a764ec7d4af Mon Sep 17 00:00:00 2001 From: Kangho Hur Date: Tue, 6 Jul 2021 17:57:42 +0900 Subject: [PATCH] Bump to latest - Modal Navigation Manager (#1563) - Implement the basic WindowHandler (#1468) - Don't extract native defaults, meaning users can no longer reset a color back to a platform theme (#1485) - Implement Alerts (Alert, Prompt and ActionSheet) (#1328) - And so on. --- .../src/Core/HandlerImpl/Window.Tizen.cs | 12 +++++++ .../ModalNavigationService.Tizen.cs | 22 ------------- src/Core/src/IMauiContext.cs | 1 + src/Core/src/Platform/MauiContext.Tizen.cs | 2 ++ .../src/Platform/Tizen/HandlerExtensions.cs | 32 ++++++++++++++++--- .../src/Platform/Tizen/MauiApplication.cs | 2 ++ 6 files changed, 44 insertions(+), 27 deletions(-) create mode 100644 src/Controls/src/Core/HandlerImpl/Window.Tizen.cs delete mode 100644 src/Controls/src/Core/Platform/ModalNavigationService/ModalNavigationService.Tizen.cs diff --git a/src/Controls/src/Core/HandlerImpl/Window.Tizen.cs b/src/Controls/src/Core/HandlerImpl/Window.Tizen.cs new file mode 100644 index 000000000000..12dcf19a25ea --- /dev/null +++ b/src/Controls/src/Core/HandlerImpl/Window.Tizen.cs @@ -0,0 +1,12 @@ +#nullable enable +using System; +using EWindow = ElmSharp.Window; + +namespace Microsoft.Maui.Controls +{ + public partial class Window + { + internal EWindow NativeWindow => + (Handler?.NativeView as EWindow) ?? throw new InvalidOperationException("Window should have a ElmSharp.Window set."); + } +} \ No newline at end of file diff --git a/src/Controls/src/Core/Platform/ModalNavigationService/ModalNavigationService.Tizen.cs b/src/Controls/src/Core/Platform/ModalNavigationService/ModalNavigationService.Tizen.cs deleted file mode 100644 index f9800c51b6d9..000000000000 --- a/src/Controls/src/Core/Platform/ModalNavigationService/ModalNavigationService.Tizen.cs +++ /dev/null @@ -1,22 +0,0 @@ -#nullable enable - -using System; -using System.Threading.Tasks; - -namespace Microsoft.Maui.Controls.Platform -{ - internal partial class ModalNavigationService - { - public Task PopModalAsync(bool animated) - { - // TODO: Need to implementation - throw new NotImplementedException(); - } - - public Task PushModalAsync(Page modal, bool animated) - { - // TODO: Need to implementation - throw new NotImplementedException(); - } - } -} diff --git a/src/Core/src/IMauiContext.cs b/src/Core/src/IMauiContext.cs index 11b1593bb241..e1648772dffa 100644 --- a/src/Core/src/IMauiContext.cs +++ b/src/Core/src/IMauiContext.cs @@ -12,6 +12,7 @@ public interface IMauiContext Android.Content.Context? Context { get; } #elif TIZEN CoreUIAppContext? Context { get; } + ElmSharp.Window? Window { get; } #endif } } \ No newline at end of file diff --git a/src/Core/src/Platform/MauiContext.Tizen.cs b/src/Core/src/Platform/MauiContext.Tizen.cs index 3a0b26c4b7cc..231f6a27583f 100644 --- a/src/Core/src/Platform/MauiContext.Tizen.cs +++ b/src/Core/src/Platform/MauiContext.Tizen.cs @@ -1,4 +1,5 @@ using System; +using ElmSharp; namespace Microsoft.Maui { @@ -33,5 +34,6 @@ public CoreUIAppContext? Context } } + public Window? Window => Context?.MainWindow; } } \ No newline at end of file diff --git a/src/Core/src/Platform/Tizen/HandlerExtensions.cs b/src/Core/src/Platform/Tizen/HandlerExtensions.cs index 878728238bba..580ce27a0cbe 100644 --- a/src/Core/src/Platform/Tizen/HandlerExtensions.cs +++ b/src/Core/src/Platform/Tizen/HandlerExtensions.cs @@ -1,4 +1,5 @@ using System; +using Tizen.Applications; using ElmSharp; using Microsoft.Maui.Handlers; @@ -18,11 +19,12 @@ public static EvasObject ToNative(this IView view, IMauiContext context, bool is var handler = view.Handler; if (handler == null) - { - handler = context.Handlers.GetHandler(view.GetType()); + handler = context.Handlers.GetHandler(view.GetType()) as IViewHandler; + + if (handler == null) + throw new Exception($"Handler not found for view {view} or was not {nameof(IViewHandler)}."); - if (handler == null) - throw new Exception($"Handler not found for view {view}"); + handler.SetMauiContext(context); handler.SetMauiContext(context); @@ -34,7 +36,6 @@ public static EvasObject ToNative(this IView view, IMauiContext context, bool is if (!(handler.NativeView is EvasObject result)) { throw new InvalidOperationException($"Unable to convert {view} to {typeof(EvasObject)}"); - } // Root content view should register to LayoutUpdated() callback. if (isRoot && handler is LayoutHandler layoutHandler) @@ -44,5 +45,26 @@ public static EvasObject ToNative(this IView view, IMauiContext context, bool is return result; } + + public static void SetWindow(this Window nativeWindow, IWindow window, IMauiContext mauiContext) + { + _ = nativeWindow ?? throw new ArgumentNullException(nameof(nativeWindow)); + _ = window ?? throw new ArgumentNullException(nameof(window)); + _ = mauiContext ?? throw new ArgumentNullException(nameof(mauiContext)); + + var handler = window.Handler as IWindowHandler; + if (handler == null) + handler = mauiContext.Handlers.GetHandler(window.GetType()) as IWindowHandler; + + if (handler == null) + throw new Exception($"Handler not found for view {window} or was not {nameof(IWindowHandler)}'"); + + handler.SetMauiContext(mauiContext); + + window.Handler = handler; + + if (handler.VirtualView != window) + handler.SetVirtualView(window); + } } } \ No newline at end of file diff --git a/src/Core/src/Platform/Tizen/MauiApplication.cs b/src/Core/src/Platform/Tizen/MauiApplication.cs index 67425e4dc8dc..d82bf5708984 100644 --- a/src/Core/src/Platform/Tizen/MauiApplication.cs +++ b/src/Core/src/Platform/Tizen/MauiApplication.cs @@ -145,6 +145,8 @@ protected override void OnTerminate() public static new MauiApplication Current { get; private set; } = null!; + public Window MainWindow { get; protected set; } = null!; + public IServiceProvider Services { get; protected set; } = null!; public IApplication Application { get; protected set; } = null!;