Skip to content

Instantly share code, notes, and snippets.

@axemclion
Created August 29, 2016 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axemclion/e197255bf04aff184d4aa331e4233cdc to your computer and use it in GitHub Desktop.
Save axemclion/e197255bf04aff184d4aa331e4233cdc to your computer and use it in GitHub Desktop.
ReactNative EventMirroring
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