Last active
April 18, 2017 14:09
-
-
Save aem/b0338630eb2352f634edcad952c1018a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { DeviceEventEmitter, NativeModules } from 'react-native' | |
const addListener = (event, callback) => { | |
DeviceEventEmitter.addListener(event, ({key, data}) => { | |
// `key` is the numeric key assigned by the native dispatcher, | |
// `data` contains the data that the native call actually wanted to pass | |
NativeModules.ReactResultRouter.routeResults({ | |
key, | |
data: callback(data) | |
}) | |
}) | |
} | |
export default class NativeEventDispatcher extends React.Component { | |
componentDidMount() { | |
addListener('DoSomething', ({prop1, prop2}) => { | |
// prop1 and prop2 are params passed in from native code | |
return doSomething(prop1, prop2) | |
}) | |
} | |
render() { | |
return null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment