mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-11 13:29:19 +00:00
[change] move bridge code into createDOMElement
Moves event normalization and the ResponderEventPlugin injection from 'View' to 'createDOMElement'. The 'react-native-web/lite' variant is removed from the performance directory as the implementation is not substantially different. Micro-optimizations to marginally narrow the performance gap to css-modules.
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import '../injectResponderEventPlugin';
|
||||
|
||||
import normalizeNativeEvent from '../normalizeNativeEvent';
|
||||
import React from 'react';
|
||||
import StyleRegistry from '../../apis/StyleSheet/registry';
|
||||
|
||||
@@ -19,23 +22,64 @@ const roleComponents = {
|
||||
region: 'section'
|
||||
};
|
||||
|
||||
const eventHandlerNames = {
|
||||
onClick: true,
|
||||
onClickCapture: true,
|
||||
onMoveShouldSetResponder: true,
|
||||
onMoveShouldSetResponderCapture: true,
|
||||
onResponderGrant: true,
|
||||
onResponderMove: true,
|
||||
onResponderReject: true,
|
||||
onResponderRelease: true,
|
||||
onResponderTerminate: true,
|
||||
onResponderTerminationRequest: true,
|
||||
onStartShouldSetResponder: true,
|
||||
onStartShouldSetResponderCapture: true,
|
||||
onTouchCancel: true,
|
||||
onTouchCancelCapture: true,
|
||||
onTouchEnd: true,
|
||||
onTouchEndCapture: true,
|
||||
onTouchMove: true,
|
||||
onTouchMoveCapture: true,
|
||||
onTouchStart: true,
|
||||
onTouchStartCapture: true
|
||||
};
|
||||
|
||||
const wrapEventHandler = handler => e => {
|
||||
e.nativeEvent = normalizeNativeEvent(e.nativeEvent);
|
||||
return handler(e);
|
||||
};
|
||||
|
||||
const createDOMElement = (component, rnProps) => {
|
||||
const {
|
||||
accessibilityLabel,
|
||||
accessibilityLiveRegion,
|
||||
accessibilityRole,
|
||||
accessible = true,
|
||||
style: rnStyle, // we need to remove the RN styles from 'domProps'
|
||||
style: rnStyle,
|
||||
testID,
|
||||
type,
|
||||
...domProps
|
||||
} = rnProps || emptyObject;
|
||||
|
||||
// use equivalent platform elements where possible
|
||||
const accessibilityComponent = accessibilityRole && roleComponents[accessibilityRole];
|
||||
const Component = accessibilityComponent || component;
|
||||
|
||||
// convert React Native styles to DOM styles
|
||||
const { className, style } = StyleRegistry.resolve(rnStyle) || emptyObject;
|
||||
|
||||
// normalize DOM events to match React Native events
|
||||
// TODO: move this out of the render path
|
||||
for (const prop in domProps) {
|
||||
if (Object.prototype.hasOwnProperty.call(domProps, prop)) {
|
||||
const isEventHandler = typeof prop === 'function' && eventHandlerNames[prop];
|
||||
if (isEventHandler) {
|
||||
domProps[prop] = wrapEventHandler(prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!accessible) {
|
||||
domProps['aria-hidden'] = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user