unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
9.04k stars 734 forks source link

[WASM] `SystemNavigationManager.BackRequested` doesn't work. #3115

Open geolite opened 4 years ago

geolite commented 4 years ago

Current behavior

I have written the following code. The location is in the if block of the if(rootFrame == null) of the OnLanuched method in App.xaml.cs.

Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) =>
{
    if (!rootFrame.CanGoBack)
    {
        return;
    }
    rootFrame.GoBack();
    args.Handled = true;
};

I deployed it to azure and tried it on my Android Chrome, but it didn't work. I hit the back key on my Android after Navigate, resulting in the tab being closed. Chrome on Android is the latest version. (81.0.4044.117)

The above code worked fine in builds for other platforms.(ex: UWP)

[Wasm] Add support of hardware/browser back button in SystemNavigationManager.BackRequested It seems to be supported as of 1.45. Is it not working properly now?

Expected behavior

I want you to go back to the previous screen.

How to reproduce it (as minimally and precisely as possible)

I've already explained the code.

Environment

Nuget Package:Uno.UI

Package Version(s):2.3.0-dev.116

Affected platform(s):

Visual Studio:

Relevant plugins:

Anything else we need to know?

jeromelaban commented 4 years ago

It could be an issue with android, specifically. Does your sample work on a desktop machine ?

geolite commented 4 years ago

@jeromelaban No, it don't work on a desktop machine. (Windows10 Chrome 81.0.4044.129)

It does not work on desktop browsers for another reason. The back button is inactive because no browser history has been added after the screen transition by the Navigate method. This means I can't hit the back button. Originally, the Navigate method should create a browser history and allow you to hit the back button. Isn't it?

jeromelaban commented 4 years ago

The Frame control never manipulates the back button, it's only done by the Windows.UI.Core.SystemNavigationManager.

If you want to enable the back button, you'll need to handle it explicitly, using AppViewBackButtonVisibility, as demonstrated in this answer.

geolite commented 4 years ago

@jeromelaban I don't have time today, so I will read it and test it out tomorrow. Thank you for your quick response. I will let you know the results.

geolite commented 4 years ago

@jeromelaban

I added the following code and it worked fine on my smartphone. Thank you so much!

Windows.UI.Core.SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;

However, there were cases where it did not work properly on Windows Chrome. When debugging with IIS Express in VisualStudio, this is the case.

I was able to fix this by using pushState to create a browser history. However, I don't think this is the right implementation. Is there a better way to do it?

Here is the source code that I verified and the URL where I published it.

https://unoplatformissues3115.azurewebsites.net/

UnoPlatformIssues3115_code.zip

MartinZikmund commented 4 years ago

I am able to reproduce this by pinning the page to taskbar, closing browser and opening it from there. This starts the browser with no history and navigating to second page does not enable the back button.