Implement nativeID prop to allow native code to reference react managed views in iOS

Reviewed By: javache

Differential Revision: D5228055

fbshipit-source-id: 8c934501d4ac946d80bf93d2ddb50f5fc38aea3c
This commit is contained in:
Yu Wang
2017-06-20 18:56:26 -07:00
committed by Facebook Github Bot
parent d217921b5e
commit 70e0455522
7 changed files with 54 additions and 3 deletions

View File

@@ -114,6 +114,8 @@ RCT_EXPORT_VIEW_PROPERTY(hasTVPreferredFocus, BOOL)
RCT_EXPORT_VIEW_PROPERTY(tvParallaxProperties, NSDictionary)
#endif
RCT_EXPORT_VIEW_PROPERTY(nativeID, NSString)
// Acessibility related properties
RCT_REMAP_VIEW_PROPERTY(accessible, reactAccessibilityElement.isAccessibilityElement, BOOL)
RCT_REMAP_VIEW_PROPERTY(accessibilityLabel, reactAccessibilityElement.accessibilityLabel, NSString)

View File

@@ -24,6 +24,11 @@
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex NS_REQUIRES_SUPER;
- (void)removeReactSubview:(UIView *)subview NS_REQUIRES_SUPER;
/**
* The native id of the view, used to locate view from native codes
*/
@property (nonatomic, copy) NSString *nativeID;
/**
* Layout direction of the view.
* Internally backed to `semanticContentAttribute` property.

View File

@@ -27,6 +27,16 @@
objc_setAssociatedObject(self, @selector(reactTag), reactTag, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (NSNumber *)nativeID
{
return objc_getAssociatedObject(self, _cmd);
}
- (void)setNativeID:(NSNumber *)nativeID
{
objc_setAssociatedObject(self, @selector(nativeID), nativeID, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
#if RCT_DEV
- (RCTShadowView *)_DEBUG_reactShadowView