@ -19,11 +19,13 @@ namespace Avalonia.Android
{
public partial class AvaloniaView : FrameLayout
{
private EmbeddableControlRoot _ root ;
private EmbeddableControlRoot ? _ root ;
private ExploreByTouchHelper ? _ accessHelper ;
private readonly ViewImpl _ view ;
private readonly ExploreByTouchHelper _ accessHelper ;
private IDisposable ? _ timerSubscription ;
private object? _ content ;
private bool _ surfaceCreated ;
public AvaloniaView ( Context context ) : base ( context )
@ -32,11 +34,13 @@ namespace Avalonia.Android
AddView ( _ view . View ) ;
this . SetBackgroundColor ( global :: Android . Graphics . Color . Transparent ) ;
_ root = new EmbeddableControlRoot ( _ view ) ;
_ root . Prepare ( ) ;
SetBackgroundColor ( global :: Android . Graphics . Color . Transparent ) ;
OnConfigurationChanged ( ) ;
OnConfigurationChanged ( null ) ;
_ view . InternalView ! . SurfaceWindowCreated + = InternalView_SurfaceWindowCreated ;
_ view . InternalView . SurfaceWindowDestroyed + = InternalView_SurfaceWindowDestroyed ;
@ -69,16 +73,50 @@ namespace Avalonia.Android
public object? Content
{
get { return _ root . Content ; }
set { _ root . Content = value ; }
get { return _ root ? . Content ; }
set
{
_ content = value ;
if ( _ root ! = null )
_ root . Content = value ;
}
}
internal new void Dispose ( )
{
_ root ? . Dispose ( ) ;
_ root = null ;
_ content = null ;
}
protected override void OnDetachedFromWindow ( )
{
base . OnDetachedFromWindow ( ) ;
OnVisibilityChanged ( false ) ;
_ surfaceCreated = false ;
_ root ? . Dispose ( ) ;
_ root = null ! ;
if ( _ accessHelper is { } accessHelper )
{
ViewCompat . SetAccessibilityDelegate ( this , null ) ;
_ accessHelper = null ;
}
}
protected override void OnAttachedToWindow ( )
{
_ root ? . Content = null ;
_ root = new EmbeddableControlRoot ( _ view ) ;
_ root . Prepare ( ) ;
if ( _ content ! = null )
{
_ root . Content = _ content ;
}
_ accessHelper = new AvaloniaAccessHelper ( this ) ;
ViewCompat . SetAccessibilityDelegate ( this , _ accessHelper ) ;
SendConfigurationChanged ( Context ? . Resources ? . Configuration ) ;
base . OnAttachedToWindow ( ) ;
}
[SupportedOSPlatform("android24.0")]
@ -98,6 +136,7 @@ namespace Avalonia.Android
{
if ( _ root = = null | | ! _ surfaceCreated )
return ;
if ( isVisible & & _ timerSubscription = = null )
{
if ( AndroidPlatform . Timer is { } timer )
@ -119,20 +158,21 @@ namespace Avalonia.Android
_ timerSubscription = null ;
}
}
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 ) ;
( ( AndroidScreens ) _ view . TryGetFeature < IScreenImpl > ( ) ! ) . OnChanged ( ) ;
}
}
@ -146,7 +186,7 @@ namespace Avalonia.Android
private void ViewImpl_FocusChange ( object? sender , FocusChangeEventArgs e )
{
if ( ! e . HasFocus )
if ( ! e . HasFocus )
LostFocus ? . Invoke ( ) ;
}
}