【发布时间】:2015-12-10 15:13:01
【问题描述】:
我正在尝试在 react-native 中实现原生视图,但道具有些问题。
我有一个类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 对象中声明每个属性来修复它。
我不想手动列出所有道具,有没有办法将所有道具放在我的 iface 中而不必知道它们?
比如:
var {standardViewProps} = require('react-native');
var iface = {
name: 'CustomView',
propTypes: {
...standardViewProps,
myProp: PropTypes.string
}
}
【问题讨论】:
标签: android react-native