Add debug tool to get shadowView from UIView

Reviewed By: nicklockwood

Differential Revision: D3058618

fb-gh-sync-id: 8e6c0ad328fa767f43438c9461b8374d1279931b
shipit-source-id: 8e6c0ad328fa767f43438c9461b8374d1279931b
This commit is contained in:
Pieter De Baets 2016-03-16 10:17:09 -07:00 committed by Facebook Github Bot 3
parent 0be6031bc6
commit bebd9c423f
3 changed files with 29 additions and 0 deletions

View File

@ -905,6 +905,10 @@ RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag
[uiManager->_bridgeTransactionListeners addObject:view];
}
((NSMutableDictionary<NSNumber *, UIView *> *)viewRegistry)[reactTag] = view;
#if RCT_DEV
[view _DEBUG_setReactShadowView:shadowView];
#endif
}
}];
}

View File

@ -9,6 +9,8 @@
#import <UIKit/UIKit.h>
@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

View File

@ -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);