Skip to content

[iOS] Swipe-back gesture on root page pops NavigationPage into a blank white screen #30

Description

@kerberosargos

Title:

[iOS] Swipe-back gesture on root page pops NavigationPage into a blank white screen

Description

On iOS, performing the native swipe-back gesture (interactive pop gesture) while on the root page of a NavigationPage causes the native UINavigationController to pop the root view controller. Since no pages remain in the navigation stack, the app displays a blank white screen.

This issue commonly occurs when initializing the app with a Splash/Initializer page and resetting the stack to MainPage via ../MainPage.


Code Changes Required

File: MPowerKit.Navigation/Platforms/iOS/Renderers/MPowerKitNavigationRenderer.cs

Target Class: SwipeBackDelegate inside MPowerKitNavigationRenderer

Proposed Fix:

Add a stack count check in ShouldBegin to prevent native popping when ViewControllers.Length <= 1.

public class SwipeBackDelegate : UIGestureRecognizerDelegate
{
    protected MPowerKitNavigationRenderer NavRenderer { get; }

    public SwipeBackDelegate(MPowerKitNavigationRenderer navRenderer)
    {
        NavRenderer = navRenderer;
    }

    public override bool ShouldBegin(UIGestureRecognizer recognizer)
    {
        // Disable gesture when on the root page (stack count <= 1)
        if (NavRenderer.ViewControllers == null || NavRenderer.ViewControllers.Length <= 1)
        {
            return false;
        }

        return NavRenderer.ShouldPopItem(default, default);
    }
}

Reproducible Example Scenario

1. Setup Initial Route in MauiProgram.cs

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();

        builder
            .UseMauiApp<App>()
            .UseMPowerKitNavigation(
                onAppStart: async (navigationService) =>
                {
                    // Start app with NavigationPage / AppInitializerPage
                    await navigationService.NavigateAsync($"NavigationPage/{nameof(AppInitializerPage)}");
                });

        return builder.Build();
    }
}

2. Reset Stack to MainPage from Splash (AppInitializerViewModel.cs)

public class AppInitializerViewModel : BindableBase
{
    private readonly INavigationService _navigationService;

    public AppInitializerViewModel(INavigationService navigationService)
    {
        _navigationService = navigationService;
    }

    public async Task OnAppInitializedAsync()
    {
        // Perform app checks, API calls, etc.
        await Task.Delay(1000);

        // Replace AppInitializerPage with MainPage in the NavigationPage stack
        var result = await _navigationService.NavigateAsync($"../{nameof(MainPage)}");
    }
}

3. Reproducing the Issue on MainPage

  1. The app successfully navigates from AppInitializerPage to MainPage.
  2. On MainPage (now the root page in NavigationPage), swipe right from the left edge of the screen (iOS Interactive Pop Gesture).
  3. Actual Result: SwipeBackDelegate.ShouldBegin returns true, popping MainPage and leaving the UINavigationController empty (blank white screen).
  4. Expected Result: The swipe gesture should be ignored because MainPage is the root page (ViewControllers.Length <= 1).
video_2026-08-24_11-04-09.mp4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions