Skip to content

Commit

Permalink
- maybe?
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed Apr 27, 2021
1 parent ff252dc commit 811ab36
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
3 changes: 0 additions & 3 deletions src/Core/src/Handlers/Page/PageHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ protected override PageView CreateNativeView()

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

if (_pageViewController.CurrentNativeView == null)
_pageViewController.LoadNativeView();

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

Expand Down
39 changes: 29 additions & 10 deletions src/Core/src/Platform/iOS/ContainerViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ public IView? CurrentView
get => _view;
set => SetView(value);
}

public UIView? CurrentNativeView
=> _pendingLoadedView ?? currentNativeView;

public IMauiContext? Context { get; set; }
internal UIView? CurrentNativeView => currentNativeView;

UIView? currentNativeView;

// The handler needs this view before LoadView is called on the controller
// So this is used to create the first view that the handler will use
// without forcing the VC to call LoadView
UIView? _pendingLoadedView;

void SetView(IView? view, bool forceRefresh = false)
{
if (view == _view && !forceRefresh)
Expand All @@ -28,26 +37,36 @@ void SetView(IView? view, bool forceRefresh = false)
}
currentNativeView?.RemoveFromSuperview();
currentNativeView = null;
if (IsViewLoaded)
{
LoadNativeView();
}
if (IsViewLoaded && _view != null)
LoadNativeView(_view);
}

internal UIView LoadFirstView(IView view)
{
_pendingLoadedView = CreateNativeView(view);
return _pendingLoadedView;
}

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

internal void LoadNativeView()
void LoadNativeView(IView view)
{
if (_view == null)
return;
currentNativeView = _pendingLoadedView ?? CreateNativeView(view);
_pendingLoadedView = null;
View!.AddSubview(currentNativeView);
}

protected virtual UIView CreateNativeView(IView view)
{
_ = Context ?? throw new ArgumentNullException(nameof(Context));
View!.AddSubview(currentNativeView = _view.ToNative(Context));
_ = _view ?? throw new ArgumentNullException(nameof(view));

return _view.ToNative(Context);
}

public override void ViewDidLayoutSubviews()
Expand Down
12 changes: 9 additions & 3 deletions src/Core/src/Platform/iOS/LayoutView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,19 @@ public override void LayoutSubviews()

public class PageViewController : ContainerViewController
{
readonly IPage _page;

public PageViewController(IPage page,IMauiContext mauiContext)
{
_page = page;
CurrentView = page;
Context = mauiContext;
LoadFirstView(page);
}

protected override UIView CreateNativeView(IView view)
{
return new PageView
{
CrossPlatformArrange = view.Arrange,
};
}
}

Expand Down

0 comments on commit 811ab36

Please sign in to comment.