Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13604] iOS: Transfer of numbers from WebView to App via Ti.App.fireEvent leading to inconsistent values

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.0.2, Release 3.1.0
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterHans Joachim
AssigneeUnknown
Created2013-04-16T20:36:30.000+0000
Updated2018-02-28T20:04:22.000+0000

Description

The communication between WebView and Titanium is buggy for some numbers (doubles). Example: web/test.html:
<!DOCTYPE html>
<html lang="en">
	<head>
		<title>test</title>
	</head>

	<body>
		<a href="#" onclick="test()">click me</a>
		<script>
			function test() {
				o = {
					d : 7.747421264648438
				};
				Ti.API.info("Object to transmit: " + JSON.stringify(o));
				Ti.App.fireEvent('FromWebView:test', o);
			};
		</script>
	</body>

</html>
Titanium:
	self = ...

	var webView = Ti.UI.createWebView({
		height : Ti.UI.FILL,
		bottom : 0,
		width : Ti.UI.FILL,
		url : Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'web/test.html').nativePath
	});
	self.add(webView);

	Ti.App.addEventListener('FromWebView:test', function(o) {
		Ti.API.info("Received object: " + JSON.stringify(o));
	});
Output:
[INFO] Object to transmit: {"d":7.747421264648438}
[INFO] Received object: {"type":"FromWebView:test","d":7.7474212646484375}
No issues under Android:
[INFO][TiAPI   ( 1014)] Object to transmit: {"d":7.747421264648438}
[INFO][TiAPI   ( 1014)]  Received object: {"type":"FromWebView:test","source":{"bubbleParent":true,"id":"com.doublewebview","version":"1.0","__propertiesDefined__":true,"description":"not specified","sessionId":"ce89b50e-58da-4985-9b3b-df278a92e8b1","Properties":{"bubbleParent":true},"deployType":"development","Android":{"bubbleParent":true,"R":{"bubbleParent":true}},"name":"doublewebview","_events":{"FromWebView:test":{}},"guid":"66986468-eed6-4497-873b-bdf4add06a86","url":"http://","copyright":"2013 by ich","analytics":true,"accessibilityEnabled":false,"publisher":"ich"},"d":7.747421264648438,"bubbles":false,"cancelBubble":false}
I'm attaching a demo project.

Attachments

FileDateSize
doublewebview.zip2013-04-16T20:36:30.000+00002890853

Comments

  1. Daniel Sefton 2013-04-17

    Tested and confirmed with 3.0.2 GA and 3.1 GA on iOS 6 simulator and Android emulator 4.1.2. *iOS output*
       [INFO] :   Object to transmit: {"d":7.747421264648438}
       [INFO] :   Received object: {"type":"FromWebView:test","d":7.7474212646484375}
       
    *Android output*
       04-17 11:18:39.369: I/TiAPI(1600): Object to transmit: {"d":7.747421264648438}
       04-17 11:18:39.399: I/TiAPI(1600):  Received object: {"type":"FromWebView:test","source":{"deployType":"development","id":"com.doublewebview","name":"doublewebview","__propertiesDefined__":true,"version":"1.0","Properties":{"bubbleParent":true},"description":"not specified","Android":{"bubbleParent":true,"R":{"bubbleParent":true}},"_events":{"FromWebView:test":{}},"bubbleParent":true,"guid":"66986468-eed6-4497-873b-bdf4add06a86","copyright":"2013 by ich","url":"http://","publisher":"ich","accessibilityEnabled":false,"sessionId":"02c5bba9-fb0a-4a8b-b95c-328548603fca","analytics":true},"d":7.747421264648438,"bubbles":false,"cancelBubble":false}
       
  2. Hans Joachim 2013-04-20

    Just fired the event from the app and not from a WebView: 7.747421264648438 is received correctly as 7.747421264648438. But 49.42214071257704 is received as 49.42214071257703. So the issue isn't restricted to WebViews.

JSON Source