Unexpected Navigation Behaviour with HybridWebView in xamarin.forms for android

I'm facing some unexpected navigation behaviour while consuming HybridWebview control in Xamarin.Forms (PCL architrcture) for android app.

Also, for your info, this issue was reported, and respective SR number is 116070114362420.

PFA, respective sample code to replicate the issue.
Below are details to understand & replicate the scenario -

Problem statement:
For android, it’s not maintaining backstack for webview.

Scenario will be like:
1. App opens a URL in webview.
2. User starts navigating by tapping on another link inside webview.
3. User repeat above step #2 few times.
4. Afterwards, user presses hardware back button on android device.

Actual Result => Webview is closed.

Expected Result => Webview should navigate to last browsed url. If there is no historical url, then webview would be closed.

Thanks in Advance :)

Answers

  • CedGabrangCedGabrang USMember ✭✭

    Hi @AbhinavRastogi, would you try this one,

    private void backClicked(object sender, EventArgs e)
    {
    //check to see if there is anywhere to go back to
    if (Browser.CanGoBack) {
    Browser.GoBack ();
    } else { //if not, leave the view
    Navigation.PopAsync ();
    }
    }

  • Browser.CanGoBack always return false.

    Overrided the method OnBackButtonPressed() in my content page containing hybrid webview.

  • I tried to impotent a work around which opens a new instance of hybridwebview when users click on any link inside the webview.
    To get the link from webview, I override dShouldOverrideUrl method in hybridwebviewrenderer file.
    But I'm unable to launch the new instance of hybridwebview from respective renderer.

    Could anyone suggest how to achieve above work around??

    Also, any other suggestion and approach are welcome.

    Note: I wouldn't be willing to programmatically maintain a separate backstack and redirect webview by overriding a hardware back button pressed event.

    Thanks in advance :smiley:

  • DennyyDennyy Member ✭✭

    Bump

Sign In or Register to comment.