|
|
|
@ -17,21 +17,18 @@ namespace Avalonia.Android |
|
|
|
{ |
|
|
|
public class AvaloniaView : FrameLayout |
|
|
|
{ |
|
|
|
private EmbeddableControlRoot _root; |
|
|
|
private EmbeddableControlRoot? _root; |
|
|
|
private readonly ViewImpl _view; |
|
|
|
|
|
|
|
private IDisposable? _timerSubscription; |
|
|
|
private object? _content; |
|
|
|
|
|
|
|
public AvaloniaView(Context context) : base(context) |
|
|
|
{ |
|
|
|
_view = new ViewImpl(this); |
|
|
|
AddView(_view.View); |
|
|
|
|
|
|
|
_root = new EmbeddableControlRoot(_view); |
|
|
|
_root.Prepare(); |
|
|
|
|
|
|
|
this.SetBackgroundColor(global::Android.Graphics.Color.Transparent); |
|
|
|
OnConfigurationChanged(); |
|
|
|
} |
|
|
|
|
|
|
|
internal TopLevelImpl TopLevelImpl => _view; |
|
|
|
@ -39,15 +36,42 @@ namespace Avalonia.Android |
|
|
|
|
|
|
|
public object? Content |
|
|
|
{ |
|
|
|
get { return _root.Content; } |
|
|
|
set { _root.Content = value; } |
|
|
|
get { return _root?.Content; } |
|
|
|
set |
|
|
|
{ |
|
|
|
_content = null; |
|
|
|
if (_root != null) |
|
|
|
_root.Content = value; |
|
|
|
else |
|
|
|
{ |
|
|
|
_content = value; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected override void Dispose(bool disposing) |
|
|
|
{ |
|
|
|
base.Dispose(disposing); |
|
|
|
} |
|
|
|
|
|
|
|
protected override void OnDetachedFromWindow() |
|
|
|
{ |
|
|
|
base.OnDetachedFromWindow(); |
|
|
|
_root?.Dispose(); |
|
|
|
_root = null!; |
|
|
|
_root = null; |
|
|
|
} |
|
|
|
|
|
|
|
protected override void OnAttachedToWindow() |
|
|
|
{ |
|
|
|
_root = new EmbeddableControlRoot(_view); |
|
|
|
_root.Prepare(); |
|
|
|
if(_content != null) |
|
|
|
{ |
|
|
|
_root.Content = _content; |
|
|
|
} |
|
|
|
SendConfigurationChanged(Context?.Resources?.Configuration); |
|
|
|
|
|
|
|
base.OnAttachedToWindow(); |
|
|
|
} |
|
|
|
|
|
|
|
public override bool DispatchKeyEvent(KeyEvent? e) |
|
|
|
@ -70,6 +94,8 @@ namespace Avalonia.Android |
|
|
|
|
|
|
|
internal void OnVisibilityChanged(bool isVisible) |
|
|
|
{ |
|
|
|
if (_root == null) |
|
|
|
return; |
|
|
|
if (isVisible && _timerSubscription == null) |
|
|
|
{ |
|
|
|
if (AvaloniaLocator.Current.GetService<IRenderTimer>() is ChoreographerTimer timer) |
|
|
|
@ -95,16 +121,17 @@ namespace Avalonia.Android |
|
|
|
protected override void OnConfigurationChanged(Configuration? newConfig) |
|
|
|
{ |
|
|
|
base.OnConfigurationChanged(newConfig); |
|
|
|
OnConfigurationChanged(); |
|
|
|
SendConfigurationChanged(newConfig ?? Context?.Resources?.Configuration); |
|
|
|
} |
|
|
|
|
|
|
|
private void OnConfigurationChanged() |
|
|
|
private void SendConfigurationChanged(Configuration? newConfig) |
|
|
|
{ |
|
|
|
if (Context is { } context) |
|
|
|
_view?.InsetsManager?.SetDefaultSystemLightMode(!(newConfig?.UiMode.HasFlag(UiMode.NightYes) ?? false)); |
|
|
|
if (Context is { } context && newConfig is { } config) |
|
|
|
{ |
|
|
|
var settings = |
|
|
|
AvaloniaLocator.Current.GetRequiredService<IPlatformSettings>() as AndroidPlatformSettings; |
|
|
|
settings?.OnViewConfigurationChanged(context); |
|
|
|
settings?.OnViewConfigurationChanged(context, config); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|