我试图以反应性原则来实现本机视图,但是在道具上有一些问题.
我有一个类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 } }
解决方法
绝对:
var View = React.View; /* later... */ propTypes: { ...View.propTypes,myProp: PropTypes.string }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。