Reputation: 670
I have several views . one is parent, the others are children.
parent has a field eg: name
I have
RCT_EXPORT_VIEW_PROPERTY(name, NSString);
in parent.m, but it doesn't work.
I have to copy
RCT_EXPORT_VIEW_PROPERTY(name, NSString);
to all the children .
How to inherit RCT_EXPORT_VIEW_PROPERTY .
Upvotes: 0
Views: 727
Reputation: 469
No, properties cannot be inherited without source code modification of React-Native. React-Native looking only for methods implemented by concrete class without methods implemented by its superclasses.
You can define macro in superclass and use this macro inside subclasses:
#define EXPORT_COMMON_PROPERTIES \
RCT_EXPORT_VIEW_PROPERTY(propertyDefinedInParent, NSString) \
RCT_EXPORT_VIEW_PROPERTY(anotherPropertyDefinedInParent, NSString)
And then in .m file of children just use
EXPORT_COMMON_PROPERTIES;
UPDATE: We are actually not inheriting any properties from RCTViewManager. React-native exports all native props from ViewManagers as constants to js level. And then it just concatenate RCTViewManager's props with our component props:
// The ViewConfig doesn't contain any props inherited from the view manager's
// superclass, so we manually merge in the RCTView ones. Other inheritance
// patterns are currenty not supported.
const nativeProps = {
...UIManager.RCTView.NativeProps,
...viewConfig.NativeProps,
};
- source code of requireNativeComponent function. But on native level we are not inheriting any properties from RCTViewManager.
Upvotes: 2