Skip to content

Commit b0f03fe

Browse files
committed
Support Min/Max Height/Width on IView and applying MauiApp/MauiAppBuilder 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)
1 parent e8a5396 commit b0f03fe

File tree

5 files changed

+54
-55
lines changed

5 files changed

+54
-55
lines changed

src/Compatibility/Core/src/AppHostBuilderExtensions.Tizen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.Maui.Controls.Hosting
88
{
99
public static partial class AppHostBuilderExtensions
1010
{
11-
internal static IAppHostBuilder ConfigureCompatibilityLifecycleEvents(this IAppHostBuilder builder) =>
11+
internal static MauiAppBuilder ConfigureCompatibilityLifecycleEvents(this MauiAppBuilder builder) =>
1212
builder.ConfigureLifecycleEvents(events => events.AddTizen(OnConfigureLifeCycle));
1313

1414
static void OnConfigureLifeCycle(ITizenLifecycleBuilder tizen)

src/Controls/samples/Controls.Sample.Tizen/Main.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
namespace Maui.Controls.Sample.Tizen
66
{
7-
class Program : MauiApplication<Startup>
7+
class Program : MauiApplication
88
{
9+
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
10+
911
protected override void OnCreate()
1012
{
1113
base.OnCreate();
12-
//Microsoft.Maui.Controls.Essentials.Platform.Init(this);
1314
}
1415

1516
static void Main(string[] args)

src/Core/src/Hosting/LifecycleEvents/AppHostBuilderExtensions.Tizen.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
using System;
12
using Microsoft.Maui.Hosting;
23
using Microsoft.Maui.LifecycleEvents;
3-
using System;
44

55
namespace Microsoft.Maui.LifecycleEvents
66
{
77
public static partial class AppHostBuilderExtensions
88
{
9-
internal static IAppHostBuilder ConfigureCrossPlatformLifecycleEvents(this IAppHostBuilder builder) =>
9+
internal static MauiAppBuilder ConfigureCrossPlatformLifecycleEvents(this MauiAppBuilder builder) =>
1010
builder.ConfigureLifecycleEvents(events => events.AddTizen(OnConfigureLifeCycle));
1111

1212
static void OnConfigureLifeCycle(ITizenLifecycleBuilder tizen)

src/Core/src/Platform/Tizen/MauiApplication.cs

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,35 @@
88

99
namespace Microsoft.Maui
1010
{
11-
12-
public class MauiApplication<TStartup> : MauiApplication where TStartup : IStartup, new()
11+
public abstract class MauiApplication : CoreUIApplication
1312
{
14-
protected override void OnPreCreate()
13+
internal WeakReference<IWindow>? _virtualWindow;
14+
internal IWindow? VirtualWindow
1515
{
16-
base.OnPreCreate();
16+
get
17+
{
18+
IWindow? window = null;
19+
_virtualWindow?.TryGetTarget(out window);
20+
return window;
21+
}
22+
}
1723

18-
var startup = new TStartup();
24+
protected MauiApplication()
25+
{
26+
Current = this;
27+
}
1928

20-
var host = startup
21-
.CreateAppHostBuilder()
22-
.ConfigureServices(ConfigureNativeServices)
23-
.ConfigureUsing(startup)
24-
.Build();
29+
protected abstract MauiApp CreateMauiApp();
2530

26-
Services = host.Services;
31+
protected override void OnPreCreate()
32+
{
33+
base.OnPreCreate();
2734

28-
if (Services == null)
29-
throw new InvalidOperationException($"The {nameof(IServiceProvider)} instance was not found.");
35+
var mauiApp = CreateMauiApp();
3036

31-
Current.Services.InvokeLifecycleEvents<TizenLifecycle.OnPreCreate>(del => del(this));
37+
Services = mauiApp.Services;
38+
39+
Current.Services?.InvokeLifecycleEvents<TizenLifecycle.OnPreCreate>(del => del(this));
3240
}
3341

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

124-
125-
// Configure native services like HandlersContext, ImageSourceHandlers etc..
126-
void ConfigureNativeServices(HostBuilderContext ctx, IServiceCollection services)
127-
{
128-
}
129-
}
130-
131-
public abstract class MauiApplication : CoreUIApplication
132-
{
133-
internal WeakReference<IWindow>? _virtualWindow;
134-
internal IWindow? VirtualWindow
135-
{
136-
get
137-
{
138-
IWindow? window = null;
139-
_virtualWindow?.TryGetTarget(out window);
140-
return window;
141-
}
142-
}
143-
144-
protected MauiApplication()
145-
{
146-
Current = this;
147-
}
148-
149132
public static new MauiApplication Current { get; private set; } = null!;
150133

151134
public Window MainWindow { get; protected set; } = null!;

src/Core/src/Platform/Tizen/ViewExtensions.cs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using ElmSharp.Accessible;
33
using Microsoft.Maui.Graphics;
44
using Tizen.UIExtensions.ElmSharp;
5+
using static Microsoft.Maui.Primitives.Dimension;
56

67
namespace Microsoft.Maui
78
{
@@ -93,28 +94,42 @@ public static void InvalidateMeasure(this EvasObject nativeView, IView view)
9394

9495
public static void UpdateWidth(this EvasObject nativeView, IView view)
9596
{
96-
if (view.Width == -1)
97-
{
98-
// Ignore the initial set of the height; the initial layout will take care of it
99-
return;
100-
}
101-
10297
UpdateSize(nativeView, view);
10398
}
10499

105100
public static void UpdateHeight(this EvasObject nativeView, IView view)
106101
{
107-
if (view.Height == -1)
108-
{
109-
// Ignore the initial set of the height; the initial layout will take care of it
110-
return;
111-
}
102+
UpdateSize(nativeView, view);
103+
}
104+
105+
public static void UpdateMinimumWidth(this EvasObject nativeView, IView view)
106+
{
107+
UpdateSize(nativeView, view);
108+
}
112109

110+
public static void UpdateMinimumHeight(this EvasObject nativeView, IView view)
111+
{
112+
UpdateSize(nativeView, view);
113+
}
114+
115+
public static void UpdateMaximumWidth(this EvasObject nativeView, IView view)
116+
{
117+
UpdateSize(nativeView, view);
118+
}
119+
120+
public static void UpdateMaximumHeight(this EvasObject nativeView, IView view)
121+
{
113122
UpdateSize(nativeView, view);
114123
}
115124

116125
public static void UpdateSize(EvasObject nativeView, IView view)
117126
{
127+
if (!IsExplicitSet(view.Width) || !IsExplicitSet(view.Height))
128+
{
129+
// Ignore the initial setting of the value; the initial layout will take care of it
130+
return;
131+
}
132+
118133
// Updating the frame (assuming it's an actual change) will kick off a layout update
119134
// Handling of the default (-1) width/height will be taken care of by GetDesiredSize
120135
nativeView.Resize(view.Width.ToScaledPixel(), view.Height.ToScaledPixel());

0 commit comments

Comments
 (0)