Browse Source
* Implement IOptionalFeatureProvider on Application class * Use IActivatableLifetime from the TryGetFeature instead of a lifetime * Reimplement macOS IActivatableLifetime * Reimplement iOS IActivatableLifetime * Reimplement Browser IActivatableLifetime * Reimplement Android IActivatableLifetime * Make AndroidActivatableLifetime aware of activity re-creation * Don't crash control catalog dialogs page * Browser TryEnterBackground shouldn't return truepull/14826/head
committed by
GitHub
23 changed files with 212 additions and 94 deletions
@ -0,0 +1,47 @@ |
|||
using System; |
|||
using Android.App; |
|||
using Avalonia.Controls.ApplicationLifetimes; |
|||
|
|||
namespace Avalonia.Android.Platform; |
|||
|
|||
internal class AndroidActivatableLifetime : IActivatableLifetime |
|||
{ |
|||
private IAvaloniaActivity _activity; |
|||
|
|||
public IAvaloniaActivity Activity |
|||
{ |
|||
get => _activity; |
|||
set |
|||
{ |
|||
if (_activity is not null) |
|||
{ |
|||
_activity.Activated -= ActivityOnActivated; |
|||
_activity.Deactivated -= ActivityOnDeactivated; |
|||
} |
|||
|
|||
_activity = value; |
|||
|
|||
if (_activity is not null) |
|||
{ |
|||
_activity.Activated += ActivityOnActivated; |
|||
_activity.Deactivated += ActivityOnDeactivated; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public event EventHandler<ActivatedEventArgs> Activated; |
|||
public event EventHandler<ActivatedEventArgs> Deactivated; |
|||
|
|||
public bool TryLeaveBackground() => (_activity as Activity)?.MoveTaskToBack(true) == true; |
|||
public bool TryEnterBackground() => false; |
|||
|
|||
private void ActivityOnDeactivated(object sender, ActivatedEventArgs e) |
|||
{ |
|||
Deactivated?.Invoke(this, e); |
|||
} |
|||
|
|||
private void ActivityOnActivated(object sender, ActivatedEventArgs e) |
|||
{ |
|||
Activated?.Invoke(this, e); |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using Avalonia.Browser.Interop; |
|||
using Avalonia.Controls.ApplicationLifetimes; |
|||
using Avalonia.Threading; |
|||
|
|||
namespace Avalonia.Browser; |
|||
|
|||
internal class BrowserActivatableLifetime : IActivatableLifetime |
|||
{ |
|||
public BrowserActivatableLifetime() |
|||
{ |
|||
bool? initiallyVisible = InputHelper.SubscribeVisibilityChange(visible => |
|||
{ |
|||
initiallyVisible = null; |
|||
(visible ? Activated : Deactivated)?.Invoke(this, new ActivatedEventArgs(ActivationKind.Background)); |
|||
}); |
|||
|
|||
// Trigger Activated as an initial state, if web page is visible, and wasn't hidden during initialization.
|
|||
if (initiallyVisible == true) |
|||
{ |
|||
_ = Dispatcher.UIThread.InvokeAsync(() => |
|||
{ |
|||
if (initiallyVisible == true) |
|||
{ |
|||
Activated?.Invoke(this, new ActivatedEventArgs(ActivationKind.Background)); |
|||
} |
|||
}, DispatcherPriority.Background); |
|||
} |
|||
} |
|||
|
|||
public event EventHandler<ActivatedEventArgs>? Activated; |
|||
public event EventHandler<ActivatedEventArgs>? Deactivated; |
|||
|
|||
public bool TryLeaveBackground() => false; |
|||
public bool TryEnterBackground() => false; |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System; |
|||
using Avalonia.Controls.ApplicationLifetimes; |
|||
|
|||
namespace Avalonia.iOS; |
|||
|
|||
internal class ActivatableLifetime : IActivatableLifetime |
|||
{ |
|||
public ActivatableLifetime(IAvaloniaAppDelegate avaloniaAppDelegate) |
|||
{ |
|||
avaloniaAppDelegate.Activated += (_, args) => Activated?.Invoke(this, args); |
|||
avaloniaAppDelegate.Deactivated += (_, args) => Deactivated?.Invoke(this, args); |
|||
} |
|||
|
|||
public event EventHandler<ActivatedEventArgs>? Activated; |
|||
public event EventHandler<ActivatedEventArgs>? Deactivated; |
|||
public bool TryLeaveBackground() => false; |
|||
public bool TryEnterBackground() => false; |
|||
} |
|||
Loading…
Reference in new issue