From fe0f3186dfe4e904817ecb3d2f399c8749443e1b Mon Sep 17 00:00:00 2001 From: Kangho Hur Date: Tue, 31 Aug 2021 10:54:28 +0900 Subject: [PATCH] Support Min/Max Height/Width on IView and applying MauiApp/MauiAppBuilder pattern - Support Min/Max Height/Width on IView (#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (#2137) --- .../src/AppHostBuilderExtensions.Tizen.cs | 2 +- .../samples/Controls.Sample.Tizen/Main.cs | 5 +- .../AppHostBuilderExtensions.Tizen.cs | 4 +- .../src/Platform/Tizen/MauiApplication.cs | 61 +++++++------------ src/Core/src/Platform/Tizen/ViewExtensions.cs | 37 +++++++---- 5 files changed, 54 insertions(+), 55 deletions(-) diff --git a/src/Compatibility/Core/src/AppHostBuilderExtensions.Tizen.cs b/src/Compatibility/Core/src/AppHostBuilderExtensions.Tizen.cs index 33de52bf7023..65d29b93b097 100644 --- a/src/Compatibility/Core/src/AppHostBuilderExtensions.Tizen.cs +++ b/src/Compatibility/Core/src/AppHostBuilderExtensions.Tizen.cs @@ -8,7 +8,7 @@ namespace Microsoft.Maui.Controls.Hosting { public static partial class AppHostBuilderExtensions { - internal static IAppHostBuilder ConfigureCompatibilityLifecycleEvents(this IAppHostBuilder builder) => + internal static MauiAppBuilder ConfigureCompatibilityLifecycleEvents(this MauiAppBuilder builder) => builder.ConfigureLifecycleEvents(events => events.AddTizen(OnConfigureLifeCycle)); static void OnConfigureLifeCycle(ITizenLifecycleBuilder tizen) diff --git a/src/Controls/samples/Controls.Sample.Tizen/Main.cs b/src/Controls/samples/Controls.Sample.Tizen/Main.cs index 5d114a8f6451..caba8616d508 100644 --- a/src/Controls/samples/Controls.Sample.Tizen/Main.cs +++ b/src/Controls/samples/Controls.Sample.Tizen/Main.cs @@ -4,12 +4,13 @@ namespace Maui.Controls.Sample.Tizen { - class Program : MauiApplication + class Program : MauiApplication { + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + protected override void OnCreate() { base.OnCreate(); - //Microsoft.Maui.Controls.Essentials.Platform.Init(this); } static void Main(string[] args) diff --git a/src/Core/src/Hosting/LifecycleEvents/AppHostBuilderExtensions.Tizen.cs b/src/Core/src/Hosting/LifecycleEvents/AppHostBuilderExtensions.Tizen.cs index 91563d84046f..42c2ba653d59 100644 --- a/src/Core/src/Hosting/LifecycleEvents/AppHostBuilderExtensions.Tizen.cs +++ b/src/Core/src/Hosting/LifecycleEvents/AppHostBuilderExtensions.Tizen.cs @@ -1,12 +1,12 @@ +using System; using Microsoft.Maui.Hosting; using Microsoft.Maui.LifecycleEvents; -using System; namespace Microsoft.Maui.LifecycleEvents { public static partial class AppHostBuilderExtensions { - internal static IAppHostBuilder ConfigureCrossPlatformLifecycleEvents(this IAppHostBuilder builder) => + internal static MauiAppBuilder ConfigureCrossPlatformLifecycleEvents(this MauiAppBuilder builder) => builder.ConfigureLifecycleEvents(events => events.AddTizen(OnConfigureLifeCycle)); static void OnConfigureLifeCycle(ITizenLifecycleBuilder tizen) diff --git a/src/Core/src/Platform/Tizen/MauiApplication.cs b/src/Core/src/Platform/Tizen/MauiApplication.cs index cfc9c7b8f654..c602250506aa 100644 --- a/src/Core/src/Platform/Tizen/MauiApplication.cs +++ b/src/Core/src/Platform/Tizen/MauiApplication.cs @@ -8,27 +8,35 @@ namespace Microsoft.Maui { - - public class MauiApplication : MauiApplication where TStartup : IStartup, new() + public abstract class MauiApplication : CoreUIApplication { - protected override void OnPreCreate() + internal WeakReference? _virtualWindow; + internal IWindow? VirtualWindow { - base.OnPreCreate(); + get + { + IWindow? window = null; + _virtualWindow?.TryGetTarget(out window); + return window; + } + } - var startup = new TStartup(); + protected MauiApplication() + { + Current = this; + } - var host = startup - .CreateAppHostBuilder() - .ConfigureServices(ConfigureNativeServices) - .ConfigureUsing(startup) - .Build(); + protected abstract MauiApp CreateMauiApp(); - Services = host.Services; + protected override void OnPreCreate() + { + base.OnPreCreate(); - if (Services == null) - throw new InvalidOperationException($"The {nameof(IServiceProvider)} instance was not found."); + var mauiApp = CreateMauiApp(); - Current.Services.InvokeLifecycleEvents(del => del(this)); + Services = mauiApp.Services; + + Current.Services?.InvokeLifecycleEvents(del => del(this)); } protected override void OnCreate() @@ -121,31 +129,6 @@ protected override void OnTerminate() Current.Services?.InvokeLifecycleEvents(del => del(this)); } - - // Configure native services like HandlersContext, ImageSourceHandlers etc.. - void ConfigureNativeServices(HostBuilderContext ctx, IServiceCollection services) - { - } - } - - public abstract class MauiApplication : CoreUIApplication - { - internal WeakReference? _virtualWindow; - internal IWindow? VirtualWindow - { - get - { - IWindow? window = null; - _virtualWindow?.TryGetTarget(out window); - return window; - } - } - - protected MauiApplication() - { - Current = this; - } - public static new MauiApplication Current { get; private set; } = null!; public Window MainWindow { get; protected set; } = null!; diff --git a/src/Core/src/Platform/Tizen/ViewExtensions.cs b/src/Core/src/Platform/Tizen/ViewExtensions.cs index 8e991e7d0e91..cc399ed7294d 100644 --- a/src/Core/src/Platform/Tizen/ViewExtensions.cs +++ b/src/Core/src/Platform/Tizen/ViewExtensions.cs @@ -2,6 +2,7 @@ using ElmSharp.Accessible; using Microsoft.Maui.Graphics; using Tizen.UIExtensions.ElmSharp; +using static Microsoft.Maui.Primitives.Dimension; namespace Microsoft.Maui { @@ -93,28 +94,42 @@ public static void InvalidateMeasure(this EvasObject nativeView, IView view) public static void UpdateWidth(this EvasObject nativeView, IView view) { - if (view.Width == -1) - { - // Ignore the initial set of the height; the initial layout will take care of it - return; - } - UpdateSize(nativeView, view); } public static void UpdateHeight(this EvasObject nativeView, IView view) { - if (view.Height == -1) - { - // Ignore the initial set of the height; the initial layout will take care of it - return; - } + UpdateSize(nativeView, view); + } + + public static void UpdateMinimumWidth(this EvasObject nativeView, IView view) + { + UpdateSize(nativeView, view); + } + public static void UpdateMinimumHeight(this EvasObject nativeView, IView view) + { + UpdateSize(nativeView, view); + } + + public static void UpdateMaximumWidth(this EvasObject nativeView, IView view) + { + UpdateSize(nativeView, view); + } + + public static void UpdateMaximumHeight(this EvasObject nativeView, IView view) + { UpdateSize(nativeView, view); } public static void UpdateSize(EvasObject nativeView, IView view) { + if (!IsExplicitSet(view.Width) || !IsExplicitSet(view.Height)) + { + // Ignore the initial setting of the value; the initial layout will take care of it + return; + } + // Updating the frame (assuming it's an actual change) will kick off a layout update // Handling of the default (-1) width/height will be taken care of by GetDesiredSize nativeView.Resize(view.Width.ToScaledPixel(), view.Height.ToScaledPixel());