不,如果没有源代码修改React-Native,属性将无法继承。 React-Native仅查看由具体类实现的方法,而不使用由其超类实现的方法。
可以在超微距定义和使用里面的子类此宏:
#define EXPORT_COMMON_PROPERTIES \
RCT_EXPORT_VIEW_PROPERTY(propertyDefinedInParent, NSString) \
RCT_EXPORT_VIEW_PROPERTY(anotherPropertyDefinedInParent, NSString)
然后在孩子的.m文件只使用
EXPORT_COMMON_PROPERTIES;
UPDATE: 我们实际上没有继承任何来自RCTViewManager的属性。 React-native将所有来自ViewManagers的原生道具作为常量导出到js级别。然后,它只是串连RCTViewManager的道具与我们的组件道具:
// 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,
};
- requireNativeComponent功能的源代码。 但在本机级别上,我们不从RCTViewManager继承任何属性。
这是一个好方法。 但是我们从RCTViewManager继承了很多RCT_EXPORT_VIEW_PROPERTY。像 RCT_EXPORT_SHADOW_PROPERTY(宽度,浮动) RCT_EXPORT_SHADOW_PROPERTY(高度,浮点数) 怎么反应本土制造的? –