Skip to content

Instantly share code, notes, and snippets.

@Gozala
Last active January 24, 2018 15:55
Show Gist options
  • Save Gozala/a977973957fcee9c5671 to your computer and use it in GitHub Desktop.
Save Gozala/a977973957fcee9c5671 to your computer and use it in GitHub Desktop.
const SimpleEventPlugin = require('react/lib/SimpleEventPlugin');
const SyntheticUIEvent = require('react/lib/SyntheticUIEvent');
const EventPropagators = require('react/lib/EventPropagators');
const ReactInjection = require('react/lib/ReactInjection');
const EventConstants = require('react/lib/EventConstants');
const EventPlugin = names => names.reduce((plugin, name) => {
const topLevelType = `top${name}`;
EventConstants.topLevelTypes[topLevelType]= topLevelType;
plugin.eventTypes[name] = {
dependencies: [topLevelType],
foo: 1,
phasedRegistrationNames: {
bubbled: `on${name[0].toUpperCase()}${name.substr(1)}`,
captured: `on${name[0].toUpperCase()}${name.substr(1)}Capture`,
}
};
return plugin;
}, {
eventTypes: {},
extractEvents(topType, topTarget, topTargetID, nativeEvent) {
const config = this.eventTypes[topType] ||
this.eventTypes[topType.substr(3)];
if (config) {
const event = SyntheticUIEvent.getPooled(config,
topTargetID,
nativeEvent);
EventPropagators.accumulateTwoPhaseDispatches(event);
return event;
}
}
});
const EventPluginRegistry = require('react/lib/EventPluginRegistry');
const DefaultEventPluginOrder = require('react/lib/DefaultEventPluginOrder');
EventPluginRegistry._resetEventPlugins();
const EventPluginOrder = DefaultEventPluginOrder.concat(['MozGestureEventPlugin']);
ReactInjection.EventPluginHub.injectEventPluginOrder(EventPluginOrder);
ReactInjection.EventPluginHub.injectEventPluginsByName({
SimpleEventPlugin: require('react/lib/SimpleEventPlugin'),
EnterLeaveEventPlugin: require('react/lib/EnterLeaveEventPlugin'),
ChangeEventPlugin: require('react/lib/ChangeEventPlugin'),
SelectEventPlugin: require('react/lib/SelectEventPlugin'),
BeforeInputEventPlugin: require('react/lib/BeforeInputEventPlugin'),
MozGestureEventPlugin: EventPlugin([
'MozSwipeGestureStart',
'MozSwipeGestureUpdate',
'MozSwipeGestureEnd',
'MozMagnifyGestureStart',
'MozMagnifyGestureUpdate',
'MozRotateGestureStart',
'MozRotateGestureUpdate',
'MozRotateGesture',
'MozTapGesture',
'MozPressTapGesture',
'MozEdgeUIGesture'
])
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment