[TIMOB-27522] WebView: onlink and beforeload are not consistent across platforms
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2019-12-10T16:18:09.000+0000 |
Affected Version/s | Release 8.2.1 |
Fix Version/s | Release 9.0.0 |
Components | iOS |
Labels | engSchedule, parity |
Reporter | Giorgio Mandolini |
Assignee | Jan Vennemann |
Created | 2019-10-24T15:30:33.000+0000 |
Updated | 2019-12-10T16:18:09.000+0000 |
Description
What happens:
- on iOS both the
onlink
function and the beforeload
event are called when setting html
, while on Android this happens only for beforeload
.
- on iOS both the onlink
function and the beforeload
event are called also for embeds (like iframe) while on Android this not happen at all.
This is causing me some trouble working on iOS because of "false positive" events that I need to distinguish as user clicks or normal page loading.
I'd like to suggest a PR where
*solution 1:*
- iOS will send onlink
only when navigation type is WKNavigationTypeLinkActivated
- beforeload event will expose the isMainFrame
indication to indicate if it was generated on the main page or an iframe.
_or:_
*solution 2:*
- iOS will send onlink
only when navigation type is WKNavigationTypeLinkActivated
- beforeload event is generated only if navigationAction.targetFrame.isMainFrame
is true
At the moment I've implemented in the PR the first solution, since iOS is already a little different from Android because it already exposes the platform specific attribute navigationType
See the [PR](https://github.com/appcelerator/titanium_mobile/pull/11295)
Attachments
File | Date | Size |
---|---|---|
app.js | 2019-10-24T15:20:23.000+0000 | 1019 |
logs.txt | 2019-10-24T15:21:58.000+0000 | 2850 |
The "onlink" callback is only intended to be invoked when the end-user taps/click on a link. It's not supposed to be invoked when loading a page via the "url"/"html" properties or when navigation programmatically via the HTML's own JavaScript code. If this is the behavior that you are seeing on iOS, then the native iOS code needs to be changed to match Android's behavior. (Android can't replicate iOS' WebView behavior in this case anyways.)
Thanks for the clarification Joshua, actually the iOS webview calls the onlink callback too many times (details on logs), so it would be better to implement the solution #1 and stop iOS to send events when they are not user generated.
[~gmandolini]'s PR can be found here: https://github.com/appcelerator/titanium_mobile/pull/11295
FR Passed. Webview onLink is not called along with beforeLoad when setting html. It is fired when a link in the html is clicked and the link is being navigated.
Waiting for Jenkins build to pass
PR Merged.
Fix verified on build: 9.0.0.v20191209135132. onlink does not fire unnecessarily unless by manual user navigation. Ticket closed.