[TIMOB-27238] Android: Allow "onlink" property to be set for first time after creating WebView
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Low |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2019-10-03T13:22:26.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 8.3.0 |
Components | Android |
Labels | WebView, android, callback, link, parity |
Reporter | Joshua Quick |
Assignee | Yordan Banev |
Created | 2019-07-11T23:02:09.000+0000 |
Updated | 2019-10-03T13:22:26.000+0000 |
Description
*Summary:*
On Android, the
WebView
"onlink" callback property currently must be assigned upon creation in order for it to work. It cannot be set after creation. (However, the "onlink" property can be changed after assigned upon creation.)
Note that iOS supports setting "onlink" for the 1st time after creation and our API docs do not document it as a creation-only property. We should do this for convenience and parity.
https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView-property-onlink
*Test case:*
Build and run the below code on Android.
Tap on the WebView's "Show Alert" link.
Notice that a "Webpage not available" appears onscreen.
Build and run on iOS.
Tap on the WebView's "Show Alert" link.
Notice that an alert dialog is displayed. (The "onlink" callback was invoked.)
var htmlText =
'<!DOCTYPE html>\n' +
'<html>\n' +
' <head>\n' +
' <meta name="viewport" content="width=device-width, initial-scale=1.0">\n' +
' </head>\n' +
' <body>\n' +
' <p>WebView "onlink" Test</p>\n' +
' <br/>\n' +
' <br/>\n' +
' <a href="mylink://show/alert">Show Alert</a>\n' +
' </body>\n' +
'</html>\n';
function onLinkHandler(e) {
if (e.url === "mylink://show/alert") {
alert("'onlink' callback invoked.");
return false;
}
return true;
}
var window = Ti.UI.createWindow();
var webView = Ti.UI.createWebView({
html: htmlText,
// onlink: onLinkHandler, // <- Must be set upon creation to work.
});
webView.onlink = onLinkHandler;
window.add(webView);
window.open();
PR: https://github.com/appcelerator/titanium_mobile/pull/11176
FR passed, Waiting on Jenkins build.
merged to master
Improvement verified in SDK version 8.3.0.v20191002165629