Created
August 29, 2016 20:30
-
-
Save axemclion/e197255bf04aff184d4aa331e4233cdc to your computer and use it in GitHub Desktop.
ReactNative EventMirroring
This file contains 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
const EventPluginRegistry = require('react/lib/EventPluginRegistry'); | |
import ReactNativeEventEmitter from 'react/lib/ReactNativeEventEmitter'; | |
export default class Plugin { | |
extractEvents(topLevelType, targetInst, nativeEvent, nativeEventTarget) { | |
if (!nativeEvent.isMirrored) { | |
// TODO send this to a socket server so that it is propogated to other servers | |
console.log('MirrorEventPlugin:', topLevelType, targetInst, nativeEvent, nativeEventTarget); | |
nativeEvent.isMirrored = true; | |
// This will be when the call is recieved from a socket - it basically happened on another device. | |
setTimeout(() => { | |
ReactNativeEventEmitter._receiveRootNodeIDEvent(nativeEventTarget, topLevelType, nativeEvent); | |
}, 5000); | |
} | |
return null; | |
} | |
} | |
// TODO This is not the best way to inject plugins. Use public APIs instead | |
// Use EventPluginRegistry._resetEvent() and then re-inject plugins in the order specified in ReactNativeDefaultInjection | |
EventPluginRegistry.plugins.push(new Plugin()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment