Skip to content

Commit

Permalink
- fix SO exception
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed Apr 27, 2021
1 parent ea862ce commit ff252dc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ internal void OnPushRequested(NavigationRequestedEventArgs e, IMauiContext mauiC

void PushPage(IPage page, bool animated, IMauiContext mauiContext, TaskCompletionSource<bool> completionSource = null)
{
var nativeView = page.ToNative(mauiContext);
var viewController = page.ToUIViewController(mauiContext);
var handler = (INativeViewHandler)page.Handler;

_trackers[page] = handler;

if (completionSource != null)
_completionTasks[handler.ViewController] = completionSource;
_completionTasks[viewController] = completionSource;

PushViewController(handler.ViewController, animated);
PushViewController(viewController, animated);
}


Expand Down
9 changes: 4 additions & 5 deletions src/Core/src/Handlers/Page/PageHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ protected override PageView CreateNativeView()

_pageViewController = new PageViewController(VirtualView, this.MauiContext);

// This triggers LoadView
if (_pageViewController.View is PageView pv1)
return pv1;
if (_pageViewController.CurrentNativeView == null)
_pageViewController.LoadNativeView();

if (_pageViewController.CurrentNativeView is PageView pv2)
return pv2;
if (_pageViewController.CurrentNativeView is PageView pv)
return pv;

throw new InvalidOperationException($"PageViewController.View must be a PageView");
}
Expand Down
16 changes: 12 additions & 4 deletions src/Core/src/Platform/iOS/ContainerViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,26 @@ void SetView(IView? view, bool forceRefresh = false)
}
currentNativeView?.RemoveFromSuperview();
currentNativeView = null;
if (IsViewLoaded && _view != null)
if (IsViewLoaded)
{
_ = Context ?? throw new ArgumentNullException(nameof(Context));
View!.AddSubview(currentNativeView = _view.ToNative(Context));
LoadNativeView();
}
}

public override void LoadView()
{
base.LoadView();
if (_view != null && Context != null)
View!.AddSubview(currentNativeView = _view.ToNative(Context));
LoadNativeView();
}

internal void LoadNativeView()
{
if (_view == null)
return;

_ = Context ?? throw new ArgumentNullException(nameof(Context));
View!.AddSubview(currentNativeView = _view.ToNative(Context));
}

public override void ViewDidLayoutSubviews()
Expand Down

0 comments on commit ff252dc

Please sign in to comment.