Skip to content

Commit

Permalink
Added guard for SystemNavigationManager. Fixes #4357
Browse files Browse the repository at this point in the history
  • Loading branch information
azchohfi committed Nov 9, 2021
1 parent edb9b1b commit 6df772b
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ private void SetBackButtonVisibility(ListDetailsViewState? previousState = null)
return;
}

SystemNavigationManager navigationManager = Window.Current == null ? null : SystemNavigationManager.GetForCurrentView();

if (ViewState == ListDetailsViewState.Details)
{
if (BackButtonBehavior == BackButtonBehavior.Inline && _inlineBackButton != null)
Expand All @@ -47,8 +49,7 @@ private void SetBackButtonVisibility(ListDetailsViewState? previousState = null)
else if (BackButtonBehavior == BackButtonBehavior.Automatic)
{
// Continue to support the system back button if it is being used
SystemNavigationManager navigationManager = SystemNavigationManager.GetForCurrentView();
if (navigationManager.AppViewBackButtonVisibility == AppViewBackButtonVisibility.Visible)
if (navigationManager?.AppViewBackButtonVisibility == AppViewBackButtonVisibility.Visible)
{
// Setting this indicates that the system back button is being used
_previousSystemBackButtonVisibility = navigationManager.AppViewBackButtonVisibility;
Expand All @@ -66,10 +67,12 @@ private void SetBackButtonVisibility(ListDetailsViewState? previousState = null)
}
else if (BackButtonBehavior != BackButtonBehavior.Manual)
{
SystemNavigationManager navigationManager = SystemNavigationManager.GetForCurrentView();
_previousSystemBackButtonVisibility = navigationManager.AppViewBackButtonVisibility;
if (navigationManager != null)
{
_previousSystemBackButtonVisibility = navigationManager.AppViewBackButtonVisibility;

navigationManager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
navigationManager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
}
}
}
else if (previousState == ListDetailsViewState.Details)
Expand All @@ -96,7 +99,11 @@ private void SetBackButtonVisibility(ListDetailsViewState? previousState = null)
if (_previousSystemBackButtonVisibility.HasValue)
{
// Make sure we show the back button if the stack can navigate back
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = _previousSystemBackButtonVisibility.Value;
if (navigationManager != null)
{
navigationManager.AppViewBackButtonVisibility = _previousSystemBackButtonVisibility.Value;
}

_previousSystemBackButtonVisibility = null;
}
}
Expand Down

0 comments on commit 6df772b

Please sign in to comment.