[TIMOB-13604] iOS: Transfer of numbers from WebView to App via Ti.App.fireEvent leading to inconsistent values
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Open |
Resolution | Unresolved |
Affected Version/s | Release 3.0.2, Release 3.1.0 |
Fix Version/s | n/a |
Components | iOS |
Labels | n/a |
Reporter | Hans Joachim |
Assignee | Unknown |
Created | 2013-04-16T20:36:30.000+0000 |
Updated | 2018-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
File | Date | Size |
---|---|---|
doublewebview.zip | 2013-04-16T20:36:30.000+0000 | 2890853 |
Tested and confirmed with 3.0.2 GA and 3.1 GA on iOS 6 simulator and Android emulator 4.1.2. *iOS output*
*Android output*
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.