Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Allow android/iOS forms UrhoSurface to be hidden and shown. #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Bindings/Forms/AndroidSurfaceRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ public class AndroidUrhoSurface : FrameLayout
static TaskCompletionSource<Application> 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)
Expand All @@ -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<Application>();
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;
}
Expand Down
6 changes: 6 additions & 0 deletions Bindings/Forms/IosSurfaceRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Urho.Application> Launcher(Type type, ApplicationOptions options)
{
await launcherSemaphore.WaitAsync();
Expand Down