Xamarin.Forms icon indicating copy to clipboard operation
Xamarin.Forms copied to clipboard

[Bug] Shell recreates a new custom renderer when tap back

Open Erdogan34 opened this issue 5 years ago • 21 comments

Description

Shell recreates a new custom renderer for a web view when coming back instead of using the prior one.

Steps; Tab 1 name is "Web" (includes a webview) Tab 2 name is "Profile"

If I tap the Web tab, I see the home page of the webview. If I tap the "Profile" tab and then back to the "Web" tab, each time creates a new webview and fires the OnElementChanged method inside custom webview.

Erdogan34 avatar Jan 03 '20 11:01 Erdogan34

@Erdogan34 Can you please attach a small project that demonstrates this issue? Thanks!

samhouts avatar Jan 03 '20 17:01 samhouts

Please, refer problem details on the xamarin forum; https://forums.xamarin.com/discussion/176479/why-is-a-new-webview-creating-after-each-tap-on-the-tab-menu-is-it-normal#latest

demo repo; https://github.com/Erdogan34/XamAppWebViewRenderer

thanks

Erdogan34 avatar Jan 03 '20 20:01 Erdogan34

This issue is similar to this https://github.com/xamarin/Xamarin.Forms/issues/8581

But just a different version of it and I'd say worse 👎 since bottom tabs are the default so it'll just dispose the whole hierarchy as you navigate by default.

When you click between bottom tabs it swaps out the fragment instead of just retaining it and hiding it.

The tricky thing here is gauging the offscreen limit to use so that too many tabs doesn't slow down the performance too much.

But we could by default just use some basic value like 3 or so

PureWeen avatar Jan 04 '20 20:01 PureWeen

Thank you @PureWeen.

I wish a chance and an option to use the behavior for any specific tab.

For example; <Tab Title="Profile" TapDispose="false"> ... </Tab> <Tab Title="Profile"> ... </Tab>

Erdogan34 avatar Jan 05 '20 10:01 Erdogan34

@Erdogan34 Yea there was some talk here about an API for this

https://github.com/xamarin/Xamarin.Forms/issues/1897#issuecomment-367860052

Which we could generalize to any forms element which would be really useful for cases where elements are removed from the cross platform tree but you don't want the renderer to dispose

Ideally we can reinvigorate that and then apply it here

PureWeen avatar Jan 05 '20 20:01 PureWeen

My eye is on the road :)

Erdogan34 avatar Jan 06 '20 09:01 Erdogan34

I have a similar issue about this, if you have two Tabs and each one contains a WebView like this:

<TabBar>
        <Tab Title="App" Icon="tab_app.png">
            <ShellContent Title="Web1" ContentTemplate="{DataTemplate local:BrowserPage1}" />
        </Tab>
        <Tab Title="App" Icon="tab_app.png">
            <ShellContent Title="Web2" ContentTemplate="{DataTemplate local:BrowserPage2}" />
        </Tab>
</TabBar>

And then when you switch between Tabs, both Webview will reload content when it is activated and cannot keep the loaded content and scroll position.

Li-Yanzhi avatar Jan 22 '20 05:01 Li-Yanzhi

Hello @Li-Yanzhi, do you have the problem with iOS too?

Erdogan34 avatar Jan 22 '20 07:01 Erdogan34

@Erdogan34 I wish a chance and an option to use the behavior for any specific tab.

For example; <Tab Title="Profile" TapDispose="false">

TapDispose sounds to implementation specific, what about IsContentPreserved

<Tab Title="Profile" IsContentPreserved="True">

ahmedalejo avatar Mar 28 '20 10:03 ahmedalejo

TapDispose sounds to implementation specific, what about IsContentPreserved
<Tab Title="Profile" IsContentPreserved="True">

@ahmedalejo Is this behavior available with the new xf version or already has previous versions?

My xf version is 4.5.0.495 but I couldn't use the TapDispose and IsContentPreserved behaviors, not coming with IntelliSense.

Erdogan34 avatar Mar 30 '20 12:03 Erdogan34

What's new about this issue?

@samhouts Could you give us any news about this fix?

pcdus avatar Nov 05 '20 14:11 pcdus

What's new about this issue?

@samhouts Could you give us any news about this fix?

Still a mystery

Erdogan34 avatar Nov 15 '20 11:11 Erdogan34

I have the same behavior, with two page (one with webview and other without).

When webview reload, it lost all sessionstorage too.

I opened a question in microsoft q&a :

https://docs.microsoft.com/en-us/answers/questions/182375/webview-session-storage-lost-when-navigate-between.html

fernandomondo avatar Dec 01 '20 21:12 fernandomondo

I keep trying to do some workaround, especially when the app is in background, because the users loses all the data they was typing.

Someone can help me?

I tried to create a static webview, but it did'nt work.

public class WebsitePage : ContentPage
    {
        public static WebView webView;
        public WebsitePage()
        {
            Title = "My WebsitePage";

            if (webView == null)
            {
                webView = new WebView();
                Content = webView;

                webView.WidthRequest = 1000;
                webView.HeightRequest = 1000;

                webView.Navigated += WebMailView_Navigated;

                webView.PropertyChanging += WebMailView_PropertyChanging;

                webView.PropertyChanged += WebView_PropertyChanged;
            }
        }

fernandomondo avatar Dec 14 '20 18:12 fernandomondo

What's new about this issue?

kaanid avatar Mar 05 '21 08:03 kaanid

What's new about this issue?

No one doesn't fix it for a long time. I gave up to use the Shell in my project.

Erdogan34 avatar Mar 05 '21 08:03 Erdogan34

Any update on this @jfversluis ? It's been assigned to every service release since 5 but not fixed, and the board for SR11 doesn't seem to have been populated yet.

If it can't be fixed or isn't a priority I'll need to remove Shell from my project (as I need a custom renderer for webview and on Android tab navigation needs to preserve the original webview that was open when the user navigated away from the tab, not recreate it).

Would appreciate an update regarding this issue's priority, as I'll need to plan in some additional work on my project if this can't be resolved soon-ish. Many thanks!

greg84 avatar Apr 05 '22 14:04 greg84

At this moment I can't tell you when this will be fixed. So if those are your options I guess you will have to do what you have to, or of course, is this really a priority to you, feel free to provide a PR with a fix. Thanks!

jfversluis avatar Apr 07 '22 11:04 jfversluis

@jfversluis I want to fix it but I do not know how to do it.

mcguu avatar Apr 08 '22 00:04 mcguu

I have the same issue.

ronnycsharp avatar May 15 '22 20:05 ronnycsharp

So will this ever be fixed? Only the Android version does this.

rurivera6 avatar Jun 10 '22 17:06 rurivera6