Skip to content

Commit

Permalink
Support Min/Max Height/Width on IView and applying MauiApp/MauiAppBui…
Browse files Browse the repository at this point in the history
…lder pattern

- Support Min/Max Height/Width on IView (dotnet#2265)
- Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
  • Loading branch information
rookiejava committed Apr 10, 2022
1 parent e8a5396 commit b0f03fe
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/Controls/samples/Controls.Sample.Tizen/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

namespace Maui.Controls.Sample.Tizen
{
class Program : MauiApplication<Startup>
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
61 changes: 22 additions & 39 deletions src/Core/src/Platform/Tizen/MauiApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,35 @@

namespace Microsoft.Maui
{

public class MauiApplication<TStartup> : MauiApplication where TStartup : IStartup, new()
public abstract class MauiApplication : CoreUIApplication
{
protected override void OnPreCreate()
internal WeakReference<IWindow>? _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<TizenLifecycle.OnPreCreate>(del => del(this));
Services = mauiApp.Services;

Current.Services?.InvokeLifecycleEvents<TizenLifecycle.OnPreCreate>(del => del(this));
}

protected override void OnCreate()
Expand Down Expand Up @@ -121,31 +129,6 @@ protected override void OnTerminate()
Current.Services?.InvokeLifecycleEvents<TizenLifecycle.OnTerminate>(del => del(this));
}


// Configure native services like HandlersContext, ImageSourceHandlers etc..
void ConfigureNativeServices(HostBuilderContext ctx, IServiceCollection services)
{
}
}

public abstract class MauiApplication : CoreUIApplication
{
internal WeakReference<IWindow>? _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!;
Expand Down
37 changes: 26 additions & 11 deletions src/Core/src/Platform/Tizen/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ElmSharp.Accessible;
using Microsoft.Maui.Graphics;
using Tizen.UIExtensions.ElmSharp;
using static Microsoft.Maui.Primitives.Dimension;

namespace Microsoft.Maui
{
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit b0f03fe

Please sign in to comment.