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 d60cdf99d51abe..501a68680f657a 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -905,6 +905,10 @@ - (void)_manageChildren:(NSNumber *)containerReactTag [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 3cb442afb5bf79..794c977e9e7413 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 bbc74901e30d91..36bd37df6b3153 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 @@ - (void)setReactTag:(NSNumber *)reactTag 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);