dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.99k stars 1.72k forks source link

[Android] Keeping WebView state across two pages is not working #18512

Open bojankaurin opened 10 months ago

bojankaurin commented 10 months ago

Description

Trying to reuse the same(static) WebView across two pages is working on iOS but not on Android. I know this is doable with Android native, I am just trying to figure out how to do it with MAUI.

What I am trying to do is, have one ContentPage in MAUI load the WebView. Then, navigate to another ContentPage in MAUI by using

Navigation.PushAsync(page2)

After page2 is loaded move the same WebView from page1 to page2, without reloading the WebView. I do that after page 2 has been loaded like this:

Content = StaticWebViewInstance;

This is working on iOS.

Steps to Reproduce

iOS - works as expected:

  1. Clone the project from the repository
  2. Run the project in iOS simulator
  3. The MAUI app home page will open and it will load github home page inside of the WebView
  4. Click on the menu in top right corner, or navigate to another page within WebView
  5. Click "Next page" button at the top of the screen, outside of the WebView
  6. Next page opens and if you opened menu on github page inside of the WebView, it stayed open. Also if you navigated to another page inside of the WebView it stayed on that page.
  7. Navigate back by using back button in MAUI toolbar and the WebView state is still preserved

Android - does not work as expected:

  1. Clone the project from the repository
  2. Run the project in Android emulator
  3. The MAUI app home page will open and it will load github home page inside of the WebView
  4. Click on the menu in top right corner, or navigate to another page within WebView
  5. Click "Next page" button at the top of the screen, outside of the WebView
  6. Next page opens and WebView is refreshed to github home page.
  7. Navigate back by using back button in MAUI toolbar and the WebView is refreshed again.

Link to public reproduction project repository

https://github.com/bojankaurin/maui-static-webview.git

Version with bug

8.0.0-rc.2.9373

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No.

Relevant log output

No response

bojankaurin commented 10 months ago

Hi folks, any update on this, is there any workaround to make this work, or I have to wait for the fix, and if so, any estimate on that?

I am trying to make .NET version of https://hotwired.dev/

And this part is required to be able to provide native mobile app experience for web apps, with progressive native enhancements as needed. Here's some documentation on that: https://turbo.hotwired.dev/handbook/native

This particular request is about making native navigation for web app, so that it feels really native to the end user even though most of it is just a regular web app.

I was able to make that work for iOS, but not for Android, hence this issue.

Examples for Turbo native Android: https://github.com/hotwired/turbo-android Examples for Turbo native iOS: https://github.com/hotwired/turbo-ios

XamlTest commented 9 months ago

Verified this on Visual Studio Enterprise 17.9.0 Preview 1(8.0.3). Repro on Android 14.0-API34, not repro on iOS 17.0 with below Project: TestMaui.zip

bojankaurin commented 3 months ago

Hi @Eilon, @jsuarezruiz, any update on this one?

Thanks!