From bebd9c423f44a559ce320ec032257670c183b692 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Wed, 16 Mar 2016 10:17:09 -0700 Subject: [PATCH] Add debug tool to get shadowView from UIView Reviewed By: nicklockwood Differential Revision: D3058618 fb-gh-sync-id: 8e6c0ad328fa767f43438c9461b8374d1279931b shipit-source-id: 8e6c0ad328fa767f43438c9461b8374d1279931b --- React/Modules/RCTUIManager.m | 4 ++++ React/Views/UIView+React.h | 9 +++++++++ React/Views/UIView+React.m | 16 ++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index d60cdf99d..501a68680 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -905,6 +905,10 @@ RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag [uiManager->_bridgeTransactionListeners addObject:view]; } ((NSMutableDictionary *)viewRegistry)[reactTag] = view; + +#if RCT_DEV + [view _DEBUG_setReactShadowView:shadowView]; +#endif } }]; } diff --git a/React/Views/UIView+React.h b/React/Views/UIView+React.h index 3cb442afb..794c977e9 100644 --- a/React/Views/UIView+React.h +++ b/React/Views/UIView+React.h @@ -9,6 +9,8 @@ #import +@class RCTShadowView; + #import "RCTComponent.h" //TODO: let's try to eliminate this category if possible @@ -49,4 +51,11 @@ - (void)reactDidMakeFirstResponder; - (BOOL)reactRespondsToTouch:(UITouch *)touch; +/** + Tools for debugging + */ +#if RCT_DEV +@property (nonatomic, strong, setter=_DEBUG_setReactShadowView:) RCTShadowView *_DEBUG_reactShadowView; +#endif + @end diff --git a/React/Views/UIView+React.m b/React/Views/UIView+React.m index bbc74901e..36bd37df6 100644 --- a/React/Views/UIView+React.m +++ b/React/Views/UIView+React.m @@ -13,6 +13,7 @@ #import "RCTAssert.h" #import "RCTLog.h" +#import "RCTShadowView.h" @implementation UIView (React) @@ -26,6 +27,21 @@ objc_setAssociatedObject(self, @selector(reactTag), reactTag, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } +#if RCT_DEBUG + +- (RCTShadowView *)_DEBUG_reactShadowView +{ + return objc_getAssociatedObject(self, _cmd); +} + +- (void)_DEBUG_setReactShadowView:(RCTShadowView *)shadowView +{ + // Use assign to avoid keeping the shadowView alive it if no longer exists + objc_setAssociatedObject(self, @selector(_DEBUG_reactShadowView), shadowView, OBJC_ASSOCIATION_ASSIGN); +} + +#endif + - (BOOL)isReactRootView { return RCTIsReactRootView(self.reactTag);