Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Android] Fixes cancel Webview Navigation #5458

Merged
merged 4 commits into from
Mar 19, 2019
Merged

Conversation

paymicro
Copy link
Contributor

@paymicro paymicro commented Mar 5, 2019

Description of Change

Call Navigating event before load Url.

Issues Resolved

API Changes

None

Platforms Affected

  • Android

Behavioral/Visual Changes

None

Testing Procedure

  • run UItest4919
  • check that the webpage does not load on init
  • click on Go to github button
  • check that the webpage does not load
  • click on Toggle cancel navigation button
  • click on Go to github button
  • webpage should load
  • all links should work
  • click on Toggle cancel navigation button
  • all links should not work

PR Checklist

  • Has automated tests
  • Rebased on top of the target branch at time of PR
  • Changes adhere to coding standard

@brackert
Copy link
Contributor

brackert commented Mar 5, 2019

This PR only fixes #4919
PR #5460 fixes issues #4919 and #4891

Copy link
Member

@samhouts samhouts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paymicro These changes look good. Can you reconcile them to #5460 and see which approach is preferable? Thanks!!

@brackert
Copy link
Contributor

@paymicro @samhouts
I don't think this fix works to fix #4891. The problem is not limited to setting the url with the Source property. The primary issue is when an embedded link in the html of the WebView is clicked on and is canceled using the Navigating event, the navigation is not canceled. In Android 9.0 (API 28), the cancel works (sort of), but in earlier API versions it does not work. See my notes in #5460. Without retesting everything, I'm pretty certain that ShouldOverrideUrlLoading must be used to trigger the Navigating event to properly cancel the navigation to an embedded link.

@brackert
Copy link
Contributor

@paymicro
Great job on incorporating the fixes for #4891. It looks like it should work perfectly.
Thanks!

Co-authored-by: Ralph Brackert <[email protected]>
@rmarinho rmarinho merged commit 6a3a10a into 4.0.0 Mar 19, 2019
@samhouts samhouts added this to the 4.0.0 milestone Mar 28, 2019
@kensykora
Copy link

Will this be included in a 3.6.X release?

@brackert
Copy link
Contributor

@kensykora
It was included in 4.0 pre8. Doesn't look like it is going to be in 3.6. I upgraded my project to pre8 and haven't had any problems... yet. (Also pre9 is now available, but I haven't installed it.)

AxelUser pushed a commit to AxelUser/Xamarin.Forms that referenced this pull request Jun 15, 2019
…n#4891 fixes xamarin#4919 closes xamarin#5460

* [Android] Fixes cancel Webview Navigation

* - added fix 4891
- refactoring

* Fix obsolete message

Co-authored-by: Ralph Brackert <[email protected]>
@samhouts samhouts added the approved Has two approvals, no pending reviews, and no changes requested label Jul 2, 2019
@chenjeff622
Copy link

chenjeff622 commented Sep 6, 2019

it still not work at Xamarin.Forms 4.2.0.709249. any fix please?
(Both Android and IOS)
// can stop load page
private void WebView_nav_Navigating(object sender, WebNavigatingEventArgs e)
{
e.Cancel = true; <-- webview stop load page .
}

// can not stop load page
private void WebView_nav_Navigating(object sender, WebNavigatingEventArgs e)
{
if (e.Url.Equals("https://XXXXX.com"))
{
e.Cancel = true; <-- webview still load page .
}
}

@marthinch
Copy link

I also get this issue on XF 3.6 and i'm not sure if i upgrade my XF version then this issue will be fixed.

@samhouts samhouts deleted the paymicro/fix-gh4919 branch June 26, 2020 00:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/webview approved Has two approvals, no pending reviews, and no changes requested e/2 🕑 2 i/regression p/Android t/bug 🐛
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants