I'm trying to implement a native view in react-native, but having some problems with the props.
I have a class CustomView
extending the android.view.View
and its ViewManager
extending com.facebook.react.uimanager.SimpleViewManager
.
The binding with React is done in this way:
'use strict';
var { requireNativeComponent, PropTypes } = require('react-native');
var iface = {
name: 'CustomView',
propTypes: {
myProp: PropTypes.string
},
};
module.exports = requireNativeComponent('CustomView', iface);
When I use it in my React app, it throws an error:
`CustomView` has no propType for native prop `CustomView.renderToHardwareTextureAndroid` of native type `boolean`
This is because SimpleViewManager
has defined some standard property like:
@ReactProp(name = PROP_BACKGROUND_COLOR, defaultInt = Color.TRANSPARENT, customType = "Color")
public void setBackgroundColor(T view, int backgroundColor) {
view.setBackgroundColor(backgroundColor);
}
I can fix it just declaring each property in my iface object.
I don't want to list manually all the props, is there a way to put all that props in my iface without have to know them?
Something like:
var {standardViewProps} = require('react-native');
var iface = {
name: 'CustomView',
propTypes: {
...standardViewProps,
myProp: PropTypes.string
}
}
EDIT 2017/06/02:
React Native 0.44 has deprecated the use of View.propTypes
. Instead, do the following:
import { ViewPropTypes } from "react-native";
/* later... */
propTypes: {
...ViewPropTypes,
myProp: PropTypes.string
}
PREVIOUS ANSWER:
Absolutely:
var View = React.View;
/* later... */
propTypes: {
...View.propTypes,
myProp: PropTypes.string
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With