build(metro): add web shims for native React Native API compatibility
Add Metro configuration to resolve native-only React Native APIs with web-compatible shims. This enables packages like react-native-pager-view to work on the web platform by providing shim implementations for codegenNativeComponent, codegenNativeCommands, and CodegenTypes that are unavailable in react-native-web. Also simplify Android signing configuration in CI by using standard Gradle property names (MYAPP_UPLOAD_*) and remove the build.gradle patching step.
This commit is contained in:
17
web-shims/react-native/Libraries/Types/CodegenTypes.js
vendored
Normal file
17
web-shims/react-native/Libraries/Types/CodegenTypes.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
const Double = Number;
|
||||
const Int32 = Number;
|
||||
const Float = Number;
|
||||
const WithDefault = (type, defaultValue) => type;
|
||||
|
||||
module.exports = {
|
||||
Double,
|
||||
Float,
|
||||
Int32,
|
||||
WithDefault,
|
||||
DirectEventHandler: () => null,
|
||||
BubblingEventHandler: () => null,
|
||||
Stringish: String,
|
||||
ColorValue: null,
|
||||
HandledState: String,
|
||||
WithSpringAnimation: (type) => type,
|
||||
};
|
||||
15
web-shims/react-native/Libraries/Utilities/codegenNativeCommands.js
vendored
Normal file
15
web-shims/react-native/Libraries/Utilities/codegenNativeCommands.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
function codegenNativeCommands(options) {
|
||||
const commands = {};
|
||||
if (options && options.supportedCommands) {
|
||||
options.supportedCommands.forEach((commandName) => {
|
||||
commands[commandName] = (ref, ...args) => {
|
||||
if (ref && ref.current && typeof ref.current[commandName] === 'function') {
|
||||
ref.current[commandName](...args);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
module.exports = codegenNativeCommands;
|
||||
18
web-shims/react-native/Libraries/Utilities/codegenNativeComponent.js
vendored
Normal file
18
web-shims/react-native/Libraries/Utilities/codegenNativeComponent.js
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
const React = require('react');
|
||||
|
||||
function codegenNativeComponent(componentName, options) {
|
||||
const componentNameClean = componentName
|
||||
.replace(/^RNC/, '')
|
||||
.replace(/^RNS/, '')
|
||||
.replace(/^RN/, '');
|
||||
|
||||
const NativeComponent = React.forwardRef((props, ref) => {
|
||||
const { children, ...rest } = props;
|
||||
return React.createElement('div', { ...rest, ref, 'data-native-component': componentNameClean }, children);
|
||||
});
|
||||
NativeComponent.displayName = componentName;
|
||||
|
||||
return NativeComponent;
|
||||
}
|
||||
|
||||
module.exports = codegenNativeComponent;
|
||||
Reference in New Issue
Block a user