Skip to content
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7f41710
Remove Device.OpenUri
mattleibow Sep 22, 2021
1c5cb5a
Don't use flags for this
mattleibow Sep 23, 2021
a82ccd9
Remove Flags and SetFlags
mattleibow Sep 23, 2021
3cd14af
remove more
mattleibow Sep 23, 2021
2b10661
move to the correct folder
mattleibow Sep 23, 2021
6c0157a
oops
mattleibow Sep 23, 2021
5ea88ed
more oops
mattleibow Sep 23, 2021
bf3144e
oops
mattleibow Sep 23, 2021
fb5d222
ns
mattleibow Sep 23, 2021
7fe0ad0
Add ApplicationHandler
mattleibow Sep 23, 2021
6c6f8e0
Pass it all along
mattleibow Sep 23, 2021
dbf04d5
comment
mattleibow Sep 23, 2021
0128287
fix the test
mattleibow Sep 23, 2021
e21ef19
Merge remote-tracking branch 'origin/main' into dev/openuriaction
mattleibow Sep 23, 2021
7a129a1
Merge branch 'dev/openuriaction' into dev/apphandler
mattleibow Sep 23, 2021
6abf1aa
- fix shadowing
PureWeen Sep 23, 2021
894a3c8
Merge remote-tracking branch 'origin/main' into dev/apphandler
mattleibow Sep 24, 2021
742e1ff
Merge remote-tracking branch 'origin/main' into dev/apphandler
mattleibow Sep 24, 2021
dd76b6d
Clean up a few things
mattleibow Sep 24, 2021
22da1ef
oops
mattleibow Sep 24, 2021
ed5d8eb
BetterName
mattleibow Sep 24, 2021
3e1221e
Overloads not supported anymore
mattleibow Sep 24, 2021
2ad5aaf
this
mattleibow Sep 24, 2021
94c506e
oops
mattleibow Sep 24, 2021
fa3c3fb
MacCat can terminate
mattleibow Sep 25, 2021
0e8f3d6
Merge remote-tracking branch 'origin/main' into dev/apphandler
mattleibow Sep 25, 2021
2aaa7a4
Fix the device tests
mattleibow Sep 25, 2021
34d072f
Merge branch 'main' into dev/apphandler
mattleibow Sep 25, 2021
e5402cc
that
mattleibow Sep 25, 2021
54f9663
This is not a useful property
mattleibow Sep 25, 2021
b9ce663
same names
mattleibow Sep 25, 2021
5a0db8a
Merge remote-tracking branch 'origin/main' into dev/apphandler
mattleibow Sep 29, 2021
7c2fba7
Push what I have
mattleibow Sep 30, 2021
941c27a
Programmatically
mattleibow Sep 30, 2021
b783e7e
Merge remote-tracking branch 'origin/main' into dev/apphandler
mattleibow Sep 30, 2021
e2c53c4
Merge remote-tracking branch 'origin/main' into dev/apphandler
mattleibow Sep 30, 2021
7d2f2d5
More changes
mattleibow Oct 1, 2021
14a0582
oops
mattleibow Oct 1, 2021
ae39dec
Merge remote-tracking branch 'origin/main' into dev/apphandler
mattleibow Oct 1, 2021
08c6b8f
Fix the stack overflow
mattleibow Oct 1, 2021
fa8ad64
The tests start too fast!
mattleibow Oct 2, 2021
f865f16
Use a testing context
mattleibow Oct 2, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected override void OnCreate(Bundle bundle)
// reflection will stop working
ResourceManager.Init(null);

Microsoft.Maui.Controls.Compatibility.Forms.Init(this, bundle);
Forms.Init(new MauiContext(MauiApplication.Current.Services, this), bundle);
FormsMaps.Init(this, bundle);

ViewHandler.ViewMapper
Expand All @@ -65,7 +65,7 @@ protected override void OnCreate(Bundle bundle)

//FormsMaterial.Init(this, bundle);
AndroidAppLinks.Init(this);
Microsoft.Maui.Controls.Compatibility.Forms.ViewInitialized += (sender, e) =>
Forms.ViewInitialized += (sender, e) =>
{
// if (!string.IsNullOrWhiteSpace(e.View.StyleId)) {
// e.NativeView.ContentDescription = e.View.StyleId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override void OnCreate(Bundle savedInstanceState)

base.OnCreate(savedInstanceState);

Microsoft.Maui.Controls.Compatibility.Forms.Init(this, savedInstanceState);
Forms.Init(new MauiContext(MauiApplication.Current.Services, this), savedInstanceState);
LoadApplication(new Issue10182Application());

_activity1 = (Activity1)DependencyService.Resolve<Context>();
Expand Down
24 changes: 0 additions & 24 deletions src/Compatibility/Core/src/Android/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ public static Color GetColorButtonNormal(Context context)
public static void Init(IActivationState activationState, InitializationOptions? options = null) =>
Init(activationState.Context, activationState.SavedInstance, options);

// Provide backwards compat for Forms.Init and AndroidActivity
// Why is bundle a param if never used?
public static void Init(Context activity, Bundle bundle) =>
Init(new MauiContext(activity), bundle);

public static void Init(IMauiContext context, Bundle bundle, InitializationOptions? options = null)
{
Assembly resourceAssembly;
Expand All @@ -204,27 +199,13 @@ public static void Init(IMauiContext context, Bundle bundle, InitializationOptio
Profile.FrameEnd();
}

public static void Init(Context activity, Bundle bundle, Assembly resourceAssembly) =>
Init(new MauiContext(activity), bundle, resourceAssembly);

public static void Init(IMauiContext context, Bundle bundle, Assembly resourceAssembly)
{
Profile.FrameBegin();
SetupInit(context, resourceAssembly, null);
Profile.FrameEnd();
}

public static void Init(InitializationOptions options)
{
Profile.FrameBegin();
SetupInit(
new MauiContext(options.Activity),
options.ResourceAssembly,
options
);
Profile.FrameEnd();
}

public static void SetTitleBarVisibility(Activity activity, AndroidTitleBarVisibility visibility)
{
if (visibility == AndroidTitleBarVisibility.Never)
Expand Down Expand Up @@ -880,11 +861,6 @@ bool TryGetTextAppearance(int appearance, out double val)
return false;
}

public void QuitApplication()
{
Internals.Log.Warning(nameof(AndroidPlatformServices), "Platform doesn't implement QuitApp");
}

public SizeRequest GetNativeSize(VisualElement view, double widthConstraint, double heightConstraint)
{
return Platform.Android.Platform.GetNativeSize(view, widthConstraint, heightConstraint);
Expand Down
12 changes: 1 addition & 11 deletions src/Compatibility/Core/src/Windows/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,9 @@ public static partial class Forms

public static void Init(IActivationState state, InitializationOptions? options = null)
{
SetupInit(state.Context, state.Context.Window, maybeOptions: options);
SetupInit(state.Context, (state.Context as IMauiWindowContext)?.Window, maybeOptions: options);
}

public static void Init(
UI.Xaml.Window mainWindow,
IEnumerable<Assembly> rendererAssemblies = null)
{
SetupInit(new MauiContext(), mainWindow, rendererAssemblies);
}

public static void Init(InitializationOptions options) =>
SetupInit(new MauiContext(), null, null, options);

static void SetupInit(
IMauiContext mauiContext,
UI.Xaml.Window mainWindow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,6 @@ void renderingFrameEventHandler(object sender, object args)
CompositionTarget.Rendering += renderingFrameEventHandler;
}

public void QuitApplication()
{
Log.Warning(nameof(WindowsBasePlatformServices), "Platform doesn't implement QuitApp");
}

public SizeRequest GetNativeSize(VisualElement view, double widthConstraint, double heightConstraint)
{
return Platform.GetNativeSize(view, widthConstraint, heightConstraint);
Expand Down
12 changes: 2 additions & 10 deletions src/Compatibility/Core/src/iOS/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,6 @@ internal static bool IsMojaveOrNewer

public static bool IsInitializedRenderers { get; private set; }

public static void Init() =>
SetupInit(new MauiContext());

public static void Init(InitializationOptions options) =>
SetupInit(new MauiContext(), options);

public static void Init(IActivationState activationState, InitializationOptions? options = null) =>
SetupInit(activationState.Context, options);

Expand Down Expand Up @@ -739,14 +733,12 @@ public Task<Stream> OpenFileAsync(string path, FileMode mode, FileAccess access,
}
}

#if !__MOBILE__
public void QuitApplication()
{
#if __MOBILE__
Log.Warning(nameof(IOSPlatformServices), "Platform doesn't implement QuitApp");
#else
NSApplication.SharedApplication.Terminate(new NSObject());
#endif
}
#endif

public SizeRequest GetNativeSize(VisualElement view, double widthConstraint, double heightConstraint)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<views:BasePage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Pages.ApplicationControlPage"
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base"
Title="App Control">

<VerticalStackLayout Padding="12" Spacing="6">

<Button Text="Terminate Application"
Clicked="OnTerminateClicked"
HorizontalOptions="Start"
Padding="20,10" />

</VerticalStackLayout>

</views:BasePage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample.Pages
{
public partial class ApplicationControlPage
{
public ApplicationControlPage()
{
InitializeComponent();
}

void OnTerminateClicked(object sender, EventArgs e)
{
Application.Current.Quit();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]
new SectionModel(typeof(AlertsPage), "Alerts",
"Displaying an alert, asking a user to make a choice, or displaying a prompt."),

new SectionModel(typeof(ApplicationControlPage), "App Control",
"Demonstrates the app control features."),

new SectionModel(typeof(AppThemeBindingPage), "AppThemeBindings",
"Devices typically include light and dark themes, which each refer to a broad set of appearance preferences that can be set at the operating system level. Applications should respect these system themes, and respond immediately when the system theme changes."),

Expand Down
3 changes: 2 additions & 1 deletion src/Controls/src/Core/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;

namespace Microsoft.Maui.Controls
{
Expand Down Expand Up @@ -44,7 +45,7 @@ internal void PlatformServicesSet()

public void Quit()
{
Device.PlatformServices?.QuitApplication();
Handler?.Invoke(ApplicationHandler.TerminateCommandKey);
}

public IAppLinks AppLinks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ public Shadow Shadow
set { SetValue(ShadowProperty, value); }
}

IView IView.Parent => Parent as IView;

public Size DesiredSize { get; protected set; }

public void Arrange(Rectangle bounds)
Expand Down
1 change: 1 addition & 0 deletions src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static partial class AppHostBuilderExtensions
#if WINDOWS || __ANDROID__
{ typeof(Shell), typeof(ShellHandler) },
#endif
{ typeof(Application), typeof(ApplicationHandler) },
{ typeof(ActivityIndicator), typeof(ActivityIndicatorHandler) },
{ typeof(BoxView), typeof(ShapeViewHandler) },
{ typeof(Button), typeof(ButtonHandler) },
Expand Down
2 changes: 0 additions & 2 deletions src/Controls/src/Core/IPlatformServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public interface IPlatformServices

string RuntimePlatform { get; }

void QuitApplication();

SizeRequest GetNativeSize(VisualElement view, double widthConstraint, double heightConstraint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal partial class AlertManager

internal void Subscribe(Window window)
{
IMauiContext mauiContext = window?.MauiContext;
var mauiContext = window?.MauiContext as IMauiWindowContext;
UI.Xaml.Window nativeWindow = mauiContext?.Window;

if (Subscriptions.Any(s => s.Window == nativeWindow))
Expand All @@ -28,7 +28,7 @@ internal void Subscribe(Window window)

internal void Unsubscribe(Window window)
{
IMauiContext mauiContext = window?.MauiContext;
var mauiContext = window?.MauiContext as IMauiWindowContext;
UI.Xaml.Window nativeWindow = mauiContext?.Window;

var toRemove = Subscriptions.Where(s => s.Window == nativeWindow).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal partial class AlertManager

internal void Subscribe(Window window)
{
IMauiContext mauiContext = window?.MauiContext;
var mauiContext = window?.MauiContext as IMauiWindowContext;
UIWindow nativeWindow = mauiContext?.Window;

if (Subscriptions.Any(s => s.Window == nativeWindow))
Expand All @@ -29,7 +29,7 @@ internal void Subscribe(Window window)

internal void Unsubscribe(Window window)
{
IMauiContext mauiContext = window?.MauiContext;
var mauiContext = window?.MauiContext as IMauiWindowContext;
UIWindow nativeWindow = mauiContext?.Window;

var toRemove = Subscriptions.Where(s => s.Window == nativeWindow).ToList();
Expand Down
5 changes: 0 additions & 5 deletions src/Controls/tests/Core.UnitTests/MockPlatformServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ public Task<DateTimeOffset> GetLastWriteTimeAsync(string path)
}
}

public void QuitApplication()
{

}

public SizeRequest GetNativeSize(VisualElement view, double widthConstraint, double heightConstraint)
{
if (getNativeSizeFunc != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class ApplicationStub : IApplication
{
readonly List<IWindow> _windows = new List<IWindow>();

public IElementHandler Handler { get; set; }

public Maui.IElement Parent { get; set; }

public IReadOnlyList<IWindow> Windows => _windows.AsReadOnly();

public string Property { get; set; } = "Default";
Expand Down
5 changes: 0 additions & 5 deletions src/Core/src/Core/IView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ public interface IView : IElement, ITransform
/// </summary>
new IViewHandler? Handler { get; set; }

/// <summary>
/// Gets the Parent of the Element.
/// </summary>
new IView? Parent { get; }

Comment thread
mattleibow marked this conversation as resolved.
/// <summary>
/// Positions child elements and determines a size for an Element.
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions src/Core/src/Handlers/Application/ApplicationHandler.Android.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Android.App;
using Microsoft.Extensions.Logging;

namespace Microsoft.Maui.Handlers
{
public partial class ApplicationHandler : ElementHandler<IApplication, Application>
{
public static void MapTerminate(ApplicationHandler handler, IApplication application, object? args)
{
handler.Logger?.LogWarning("Android does not support programatically terminating the app.");
Comment thread
mattleibow marked this conversation as resolved.
Outdated
}
}
}
11 changes: 11 additions & 0 deletions src/Core/src/Handlers/Application/ApplicationHandler.Standard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Microsoft.Maui.Handlers
{
public partial class ApplicationHandler : ElementHandler<IApplication, object>
{
protected override object CreateNativeElement() => throw new NotImplementedException();

public static void MapTerminate(ApplicationHandler handler, IApplication application, object? args) { }
}
}
10 changes: 10 additions & 0 deletions src/Core/src/Handlers/Application/ApplicationHandler.Windows.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Microsoft.Maui.Handlers
{
public partial class ApplicationHandler : ElementHandler<IApplication, UI.Xaml.Application>
{
public static void MapTerminate(ApplicationHandler handler, IApplication application, object? args)
{
handler.NativeView.Exit();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
}
Loading