ras*_*cio 12 android react-native
我正在尝试在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);
Run Code Online (Sandbox Code Playgroud)
当我在我的React应用程序中使用它时,它会抛出一个错误:
`CustomView` has no propType for native prop `CustomView.renderToHardwareTextureAndroid` of native type `boolean`
Run Code Online (Sandbox Code Playgroud)
这是因为SimpleViewManager定义了一些标准属性,如:
@ReactProp(name = PROP_BACKGROUND_COLOR, defaultInt = Color.TRANSPARENT, customType = "Color")
public void setBackgroundColor(T view, int backgroundColor) {
view.setBackgroundColor(backgroundColor);
}
Run Code Online (Sandbox Code Playgroud)
我可以修复它只是声明我的iface对象中的每个属性.
我不想手动列出所有的道具,有没有办法把所有的道具放在我的iface而不必知道它们?
就像是:
var {standardViewProps} = require('react-native');
var iface = {
name: 'CustomView',
propTypes: {
...standardViewProps,
myProp: PropTypes.string
}
}
Run Code Online (Sandbox Code Playgroud)
Joh*_*mas 20
编辑2017/06/02:
React Native 0.44已经弃用了View.propTypes.相反,请执行以下操作:
import { ViewPropTypes } from "react-native";
/* later... */
propTypes: {
...ViewPropTypes,
myProp: PropTypes.string
}
Run Code Online (Sandbox Code Playgroud)
以前的答案:
绝对:
var View = React.View;
/* later... */
propTypes: {
...View.propTypes,
myProp: PropTypes.string
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4229 次 |
| 最近记录: |