Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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