ソースを参照

singleview lifetime for android.

Dan Walmsley 3 年 前
コミット
d48b61b5d0

+ 0 - 7
samples/ControlCatalog.Android/MainActivity.cs

@@ -1,5 +1,4 @@
 using Android.App;
-using Android.OS;
 using Android.Content.PM;
 using Avalonia.Android;
 
@@ -8,11 +7,5 @@ namespace ControlCatalog.Android
     [Activity(Label = "ControlCatalog.Android", Theme = "@style/MyTheme.NoActionBar", Icon = "@drawable/icon", LaunchMode = LaunchMode.SingleInstance, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
     public class MainActivity : AvaloniaActivity
     {
-        protected override void OnCreate(Bundle? savedInstanceState)
-        {
-            base.OnCreate(savedInstanceState);
-
-            Content = new MainView();
-        }
     }
 }

+ 1 - 2
samples/ControlCatalog.Android/SplashActivity.cs

@@ -22,8 +22,7 @@ namespace ControlCatalog.Android
             if (Avalonia.Application.Current == null)
             {
                 AppBuilder.Configure<App>()
-                    .UseAndroid()
-                    .SetupWithoutStarting();
+                    .UseAndroid();
             }
 
             StartActivity(new Intent(Application.Context, typeof(MainActivity)));

+ 14 - 1
src/Android/Avalonia.Android/AndroidPlatform.cs

@@ -4,6 +4,7 @@ using Avalonia.Android;
 using Avalonia.Android.Platform;
 using Avalonia.Android.Platform.Input;
 using Avalonia.Controls;
+using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Controls.Platform;
 using Avalonia.Input;
 using Avalonia.Input.Platform;
@@ -14,6 +15,17 @@ using Avalonia.Skia;
 
 namespace Avalonia
 {
+    public class SingleViewLifetime : ISingleViewApplicationLifetime
+    {
+        public AvaloniaView View;
+
+        public Control MainView
+        {
+            get => (Control)View.Content;
+            set => View.Content = value;
+        }
+    }
+
     public static class AndroidApplicationExtensions
     {
         public static T UseAndroid<T>(this T builder) where T : AppBuilderBase<T>, new()
@@ -21,7 +33,8 @@ namespace Avalonia
             var options = AvaloniaLocator.Current.GetService<AndroidPlatformOptions>() ?? new AndroidPlatformOptions();
             return builder
                 .UseWindowingSubsystem(() => AndroidPlatform.Initialize(options), "Android")
-                .UseSkia();
+                .UseSkia()
+                .SetupWithLifetime(new SingleViewLifetime());
         }
     }
 }

+ 3 - 13
src/iOS/Avalonia.iOS/AvaloniaAppDelegate.cs

@@ -1,5 +1,3 @@
-using Avalonia.Controls;
-using Avalonia.Controls.ApplicationLifetimes;
 using Foundation;
 using UIKit;
 
@@ -18,7 +16,9 @@ namespace Avalonia.iOS
         {
             var builder = AppBuilder.Configure<TApp>();
             CustomizeAppBuilder(builder);
-            var lifetime = new Lifetime();
+
+            var lifetime = new SingleViewLifetime();
+
             builder.AfterSetup(_ =>
             {
                 Window = new UIWindow();
@@ -35,15 +35,5 @@ namespace Avalonia.iOS
             Window.Hidden = false;
             return true;
         }
-
-        class Lifetime : ISingleViewApplicationLifetime
-        {
-            public AvaloniaView View;
-            public Control MainView
-            {
-                get => View.Content;
-                set => View.Content = value;
-            }
-        }
     }
 }

+ 2 - 0
src/iOS/Avalonia.iOS/Platform.cs

@@ -45,6 +45,7 @@ namespace Avalonia.iOS
             Timer ??= new DisplayLinkTimer();
             var keyboard = new KeyboardDevice();
             var softKeyboard = new SoftKeyboardHelper();
+            
             AvaloniaLocator.CurrentMutable
                 .Bind<IPlatformOpenGlInterface>().ToConstant(GlFeature)
                 .Bind<ICursorFactory>().ToConstant(new CursorFactoryStub())
@@ -57,6 +58,7 @@ namespace Avalonia.iOS
                 .Bind<IRenderTimer>().ToConstant(Timer)
                 .Bind<IPlatformThreadingInterface>().ToConstant(new PlatformThreadingInterface())
                 .Bind<IKeyboardDevice>().ToConstant(keyboard);
+
             keyboard.PropertyChanged += (_, changed) =>
             {
                 if (changed.PropertyName == nameof(KeyboardDevice.FocusedElement))

+ 12 - 3
src/iOS/Avalonia.iOS/SingleViewLifetime.cs

@@ -1,7 +1,16 @@
+using Avalonia.Controls;
+using Avalonia.Controls.ApplicationLifetimes;
+
 namespace Avalonia.iOS
 {
-    public class SingleViewLifetime
+    public class SingleViewLifetime : ISingleViewApplicationLifetime
     {
-        
+        public AvaloniaView View;
+
+        public Control MainView
+        {
+            get => View.Content;
+            set => View.Content = value;
+        }
     }
-}
+}