Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1697] Add WebView "onlink" callback support

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2019-08-16T18:32:17.000+0000
Affected Version/sn/a
Fix Version/sCLI Release 7.1.1, Alloy 1.14.1
ComponentsXML
LabelsWebView, callback, link
ReporterGary Mathews
AssigneeEwan Harris
Created2019-07-11T23:54:48.000+0000
Updated2019-08-20T21:41:20.000+0000

Description

*Summary:* We should add Ti.UI.WebView "onlink" callback support in view XML to make it more convenient to use. Currently, Alloy users are limited to assigning the callback in their JavaScript code instead. https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView-property-onlink *Example:* index.xml
<Alloy>
	<Window class="container">
		<WebView id="webView" onlink="onLinkHandler"/>
	</Window>
</Alloy>
index.js
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("The 'onLinkHandler' callback was invoked.");
		return false;
	}
	return true;
};
$.webView.html = htmlText;
$.index.open();
*Note:* Currently, doing the above causes the "onlink" property to be assigned a string literal of the callback function like the below, which is invalid.
$.webView.onlink = 'onLinkHandler';

Comments

  1. Ewan Harris 2019-08-16

    PR: https://github.com/appcelerator/alloy/pull/936
  2. Keerthi Mahalingam 2019-08-20

    Verified the fix on CLI 7.1.1-master.5.web view onlink callback support added. Works as expected. Test Environment: Name = Mac OS X Version = 10.14.5 Architecture = 64bit Node.js Node.js Version = 10.16.2 npm Version = 6.9.0 Titanium CLI CLI Version = 5.2.1 Titanium SDK SDK Version = 8.1.1.v20190813101121 CLI = 7.1.1-MASTER.5 Studio -5.1.3.201907112159 appc npm -4.2.15-1 device -iPhone X iOS 11,oneplus 5t Android 9 Simulator/Emulator -iphone6 ios12,pixel android 8

JSON Source