我试图在react native中实现原生视图,但在props 方面存在一些问题.
我有一个CustomView
班延伸android.view.View
班,ViewManager
班延伸com.facebook.react.uimanager.SimpleViewManager
班.
通过以下方式与React绑定:
'use strict';
var { requireNativeComponent, PropTypes } = require('react-native');
var iface = {
name: 'CustomView',
propTypes: {
myProp: PropTypes.string
},
};
module.exports = requireNativeComponent('CustomView', iface);
当我在React应用程序中使用它时,它会抛出一个错误:
`CustomView` has no propType for native prop `CustomView.renderToHardwareTextureAndroid` of native type `boolean`
这是因为SimpleViewManager
定义了一些标准属性,如:
@ReactProp(name = PROP_BACKGROUND_COLOR, defaultInt = Color.TRANSPARENT, customType = "Color")
public void setBackgroundColor(T view, int backgroundColor) {
view.setBackgroundColor(backgroundColor);
}
我只需在iface对象中声明每个属性就可以修复它.
我不想手动列出所有props ,有没有办法在我的iface中放置所有props 而不必知道它们
var {standardViewProps} = require('react-native');
var iface = {
name: 'CustomView',
propTypes: {
...standardViewProps,
myProp: PropTypes.string
}
}