Skip to content

Commit

Permalink
Fix firing modal from appearing ios14 (#14240)
Browse files Browse the repository at this point in the history
* Call Complete Pending Navigation

* - add additional check so we don't call complete too many times
  • Loading branch information
PureWeen committed Mar 28, 2023
1 parent 7316373 commit 60c2b91
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class NavigationRenderer : UINavigationController, IPlatformViewHandler
bool _navigating = false;
VisualElement _element;
bool _uiRequestedPop; // User tapped the back button or swiped to navigate back
MauiNavigationDelegate NavigationDelegate => Delegate as MauiNavigationDelegate;

[Internals.Preserve(Conditional = true)]
public NavigationRenderer() : base(typeof(MauiControlsNavigationBar), null)
Expand Down Expand Up @@ -425,10 +426,19 @@ Task<bool> GetAppearedOrDisappearedTask(Page page)
CompletePendingNavigation(false);
};

if (NavigationDelegate is not null)
NavigationDelegate.WaitingForNavigationToFinish = true;

_removeLifecycleEvents = new ActionDisposable(() =>
{
// This ensures that we don't cause multiple calls to CompletePendingNavigation.
// Depending on circumstances (covered by modal page) CompletePendingNavigation
// might get called from the Delegate vs the DidAppear/DidDisappear methods
// on the ParentingViewController.
parentViewController.Appearing -= appearing;
parentViewController.Disappearing -= disappearing;
if (NavigationDelegate is not null)
NavigationDelegate.WaitingForNavigationToFinish = false;
});

parentViewController.Appearing += appearing;
Expand Down Expand Up @@ -1008,6 +1018,8 @@ class MauiNavigationDelegate : UINavigationControllerDelegate
bool _finishedWithInitialNavigation;
readonly WeakReference<NavigationRenderer> _navigation;

public bool WaitingForNavigationToFinish { get; internal set; }

public MauiNavigationDelegate(NavigationRenderer navigationRenderer)
{
_navigation = new WeakReference<NavigationRenderer>(navigationRenderer);
Expand All @@ -1028,6 +1040,9 @@ public override void DidShowViewController(UINavigationController navigationCont
_finishedWithInitialNavigation = true;
np.SendNavigatedFromHandler(null);
}

if (WaitingForNavigationToFinish)
r.CompletePendingNavigation(true);
}
}

Expand Down
15 changes: 11 additions & 4 deletions src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ protected Task<TValue> GetValueAsync<TValue>(IElement view, Func<IPlatformViewHa
}

static SemaphoreSlim _takeOverMainContentSempahore = new SemaphoreSlim(1);
protected Task CreateHandlerAndAddToWindow<THandler>(IElement view, Func<THandler, Task> action, IMauiContext mauiContext = null)
protected Task CreateHandlerAndAddToWindow<THandler>(IElement view, Func<THandler, Task> action, IMauiContext mauiContext = null, TimeSpan? timeOut = null)
where THandler : class, IElementHandler
{
mauiContext ??= MauiContext;

timeOut ??= TimeSpan.FromSeconds(15);

return InvokeOnMainThreadAsync(async () =>
{
IWindow window = null;
Expand Down Expand Up @@ -180,15 +182,20 @@ await SetupWindowForTests<THandler>(window, async () =>
#if WINDOWS
await Task.Delay(10);
#endif
THandler handler;
if (typeof(THandler).IsAssignableFrom(window.Handler.GetType()))
await action((THandler)window.Handler);
handler = (THandler)window.Handler;
else if (typeof(THandler).IsAssignableFrom(window.Content.Handler.GetType()))
await action((THandler)window.Content.Handler);
handler = (THandler)window.Content.Handler;
else if (window.Content is ContentPage cp && typeof(THandler).IsAssignableFrom(cp.Content.Handler.GetType()))
await action((THandler)cp.Content.Handler);
handler = (THandler)cp.Content.Handler;
else
throw new Exception($"I can't work with {typeof(THandler)}");
await action(handler).WaitAsync(timeOut.Value);
#if !WINDOWS
bool isActivated = controlsWindow?.IsActivated ?? false;
Expand Down

0 comments on commit 60c2b91

Please sign in to comment.