Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ApplicationHandler #2653

Merged
merged 42 commits into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions src/Compatibility/Core/src/Android/AppCompat/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Android.OS;
using Android.Views;
using Android.Views.Animations;
using Microsoft.Maui.Controls.Compatibility.Platform.Android.AppCompat;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Graphics;
Expand Down Expand Up @@ -329,7 +328,7 @@ public static void ClearRenderer(AView renderedView)
var mauiContext = Forms.MauiContext;

if (fragmentManager != null || layoutInflater != null)
mauiContext = new ScopedMauiContext(mauiContext, null, null, layoutInflater, fragmentManager);
mauiContext = mauiContext.MakeScoped(layoutInflater, fragmentManager);

handler = mauiContext.Handlers.GetHandler(element.GetType()) as IViewHandler;
handler.SetMauiContext(mauiContext);
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.GetOptionalNativeWindow(), 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 @@ public class CoreViewModel : BaseGalleryViewModel
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
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
@@ -1,4 +1,4 @@
#nullable disable
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -15,21 +15,17 @@ internal partial class AlertManager

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

if (Subscriptions.Any(s => s.Window == nativeWindow))
{
return;
}

Subscriptions.Add(new AlertRequestHelper(nativeWindow, mauiContext));
Subscriptions.Add(new AlertRequestHelper(nativeWindow, window.MauiContext));
}

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

var toRemove = Subscriptions.Where(s => s.Window == nativeWindow).ToList();

Expand All @@ -42,8 +38,8 @@ internal void Unsubscribe(Window window)

internal sealed class AlertRequestHelper : IDisposable
{
static Task<bool> CurrentAlert;
static Task<string> CurrentPrompt;
static Task<bool>? CurrentAlert;
static Task<string?>? CurrentPrompt;

internal AlertRequestHelper(UI.Xaml.Window window, IMauiContext mauiContext)
{
Expand Down Expand Up @@ -201,7 +197,7 @@ static async Task<bool> ShowAlert(ContentDialog alert)
return result == ContentDialogResult.Primary;
}

static async Task<string> ShowPrompt(PromptDialog prompt)
static async Task<string?> ShowPrompt(PromptDialog prompt)
{
ContentDialogResult result = await prompt.ShowAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Threading.Tasks;
using Foundation;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Graphics;
using UIKit;
Expand All @@ -16,21 +17,17 @@ internal partial class AlertManager

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

if (Subscriptions.Any(s => s.Window == nativeWindow))
{
return;
}

Subscriptions.Add(new AlertRequestHelper(nativeWindow));
}

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

var toRemove = Subscriptions.Where(s => s.Window == nativeWindow).ToList();

Expand Down
9 changes: 2 additions & 7 deletions src/Controls/src/Core/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,10 @@ public static Task<bool> TranslateTo(this VisualElement view, double x, double y
return tcs.Task;
}

internal static IAnimationManager? GetAnimationManager(this IAnimatable animatable)
internal static IAnimationManager GetAnimationManager(this IAnimatable animatable)
{
if (animatable is Element e && e.FindMauiContext() is IMauiContext mauiContext)
{
if (mauiContext is IScopedMauiContext scoped)
return scoped.AnimationManager;
else
return mauiContext.Services.GetService<IAnimationManager>();
}
return mauiContext.GetAnimationManager();

throw new ArgumentException($"Unable to find {nameof(IAnimationManager)} for '{animatable.GetType().FullName}'.", nameof(animatable));
}
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
4 changes: 2 additions & 2 deletions src/Controls/tests/Core.UnitTests/SwipeViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void TestBottomItems()
}

[Test]
public void TestProgramaticallyOpen()
public void TestProgrammaticallyOpen()
{
bool isOpen = false;

Expand Down Expand Up @@ -188,7 +188,7 @@ public void TestProgramaticallyOpen()
}

[Test]
public void TestProgramaticallyClose()
public void TestProgrammaticallyClose()
{
bool isOpen = false;

Expand Down
Loading