From 5ecf1fae83a80aa3abfd654b60a4a1c68a7a70fd Mon Sep 17 00:00:00 2001 From: Russell Peake Date: Thu, 3 Nov 2016 15:50:10 +1030 Subject: [PATCH] Allow android/iOS forms UrhoSurface to be hidden and shown. --- Bindings/Forms/AndroidSurfaceRenderer.cs | 9 ++++++++- Bindings/Forms/IosSurfaceRenderer.cs | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Bindings/Forms/AndroidSurfaceRenderer.cs b/Bindings/Forms/AndroidSurfaceRenderer.cs index fa0384450..7f3d3a597 100644 --- a/Bindings/Forms/AndroidSurfaceRenderer.cs +++ b/Bindings/Forms/AndroidSurfaceRenderer.cs @@ -29,10 +29,15 @@ public class AndroidUrhoSurface : FrameLayout static TaskCompletionSource applicationTaskSource; static readonly SemaphoreSlim launcherSemaphore = new SemaphoreSlim(1); readonly FrameLayout surfaceViewPlaceholder; + static SDLSurface surfaceView; public AndroidUrhoSurface(Android.Content.Context context) : base(context) { AddView(surfaceViewPlaceholder = new FrameLayout(Context)); + if (surfaceView != null) { + surfaceView.RemoveFromParent (); + surfaceViewPlaceholder.AddView (surfaceView); + } } protected override void OnLayout(bool changed, int l, int t, int r, int b) @@ -48,9 +53,11 @@ protected override void OnLayout(bool changed, int l, int t, int r, int b) await launcherSemaphore.WaitAsync(); await Urho.Application.StopCurrent(); surfaceViewPlaceholder.RemoveAllViews(); + surfaceView?.Dispose (); + surfaceView = null; applicationTaskSource = new TaskCompletionSource(); Urho.Application.Started += UrhoApplicationStarted; - var surfaceView = Urho.Droid.UrhoSurface.CreateSurface((Activity)Context, type, options); + surfaceView = Urho.Droid.UrhoSurface.CreateSurface((Activity)Context, type, options); surfaceViewPlaceholder.AddView(surfaceView); return await applicationTaskSource.Task; } diff --git a/Bindings/Forms/IosSurfaceRenderer.cs b/Bindings/Forms/IosSurfaceRenderer.cs index a8bbe3f0b..af61844a1 100644 --- a/Bindings/Forms/IosSurfaceRenderer.cs +++ b/Bindings/Forms/IosSurfaceRenderer.cs @@ -31,6 +31,12 @@ public class IosUrhoSurface : UIView static Urho.iOS.UrhoSurface surface; static Urho.Application app; + public IosSurfaceRenderer() { + if (surface != null) { + this.Add(surface); + } + } + internal async Task Launcher(Type type, ApplicationOptions options) { await launcherSemaphore.WaitAsync();