我正在为 android react native 创建一个本地模块,用 java 编写。如何将组件传递给 native 模块,例如我有一个使用 MaterialStyledDialogs
的自定义对话框( link ) 我想设置一个 custom view对于它,该 View 是一个 react 原生组件。这可能吗?
我可以毫无问题地传递字符串,但不能使用组件。例如
我有一个名为 <CustomListForDialog/>
的组件然后我将通过这样的方式将它传递给 native 模块
...
import { NativeModules } from 'react-native';
...
// the custom function inside the class
showCustomDIalog() {
NativeModules.MyNativeDialog.show('Header Title', <CustomListForDialog/>);
}
...
如何从 native 模块接收组件?提前致谢。
最佳答案
您无法在 react-native
中发送或接收组件. React Native Native 模块只能获取以下数据类型作为参数。
Boolean -> Bool
Integer -> Number
Double -> Number
Float -> Number
String -> String
ReadableMap -> Object
ReadableArray -> Array
阅读更多关于 ReadableMap和 ReadableArray
关于react-native - 如何将 react 原生组件传递给 Android 的原生模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38673169/