{"action":"closed","issue":{"url":"https://api.github.com/repos/iddan/react-native-canvas/issues/66","repository_url":"https://api.github.com/repos/iddan/react-native-canvas","labels_url":"https://api.github.com/repos/iddan/react-native-canvas/issues/66/labels{/name}","comments_url":"https://api.github.com/repos/iddan/react-native-canvas/issues/66/comments","events_url":"https://api.github.com/repos/iddan/react-native-canvas/issues/66/events","html_url":"https://github.com/iddan/react-native-canvas/issues/66","id":338734181,"node_id":"MDU6SXNzdWUzMzg3MzQxODE=","number":66,"title":"custom postMessage crashes react-native-canvas","user":{"login":"peacechen","id":6295083,"node_id":"MDQ6VXNlcjYyOTUwODM=","avatar_url":"https://avatars3.githubusercontent.com/u/6295083?v=4","gravatar_id":"","url":"https://api.github.com/users/peacechen","html_url":"https://github.com/peacechen","followers_url":"https://api.github.com/users/peacechen/followers","following_url":"https://api.github.com/users/peacechen/following{/other_user}","gists_url":"https://api.github.com/users/peacechen/gists{/gist_id}","starred_url":"https://api.github.com/users/peacechen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peacechen/subscriptions","organizations_url":"https://api.github.com/users/peacechen/orgs","repos_url":"https://api.github.com/users/peacechen/repos","events_url":"https://api.github.com/users/peacechen/events{/privacy}","received_events_url":"https://api.github.com/users/peacechen/received_events","type":"User","site_admin":false},"labels":[{"id":197531983,"node_id":"MDU6TGFiZWwxOTc1MzE5ODM=","url":"https://api.github.com/repos/iddan/react-native-canvas/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-07-05T21:37:55Z","updated_at":"2018-07-08T08:18:04Z","closed_at":"2018-07-08T08:18:04Z","author_association":"NONE","body":"I'm porting a mini-game which uses canvas.   This requires user interaction, so I injected a touch handler that posts a message to pass the event back to the RN side.\r\n\r\n```\r\n    this.onkeypress = 'window.addEventListener(\"touchstart\", function (e) { window.postMessage(\"touchstart\") } );';\r\n    canvas.webview.injectJavaScript(this.onkeypress);\r\n```\r\n\r\nHowever, handleMessage() in Canvas.js tries to parse this as JSON which crashes.\r\n```\r\n    var data = JSON.parse(e.nativeEvent.data);\r\n```\r\n\r\nI tried passing in serialized JSON, but the rest of the code needs id, meta, and payload fields in a specific way which the app has no visibility into.  I got it to work by wrapping the JSON.parse in a try-catch block, and if it catches, pass `data` directly to `listeners` and skip the rest including the `bus` call.\r\n\r\nWould you be interested in a PR?  Or is there a better way to accomplish this?"}}
{"actor":{"display_login":"iddan"}}