From be6976d6faa333311405bd6184300bbd8da6cbca Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 7 Nov 2017 16:10:52 -0800 Subject: [PATCH] RCTAllocatedRootViewTag was moved to RCTUIManagerUtils Summary: This logic was decoupled from RCTRootView to make it reusable. Reviewed By: javache Differential Revision: D6214785 fbshipit-source-id: e7419be03ba0e20d95b47c11e41789636aa6e916 --- React/Base/RCTRootView.m | 14 ++------------ React/Modules/RCTUIManagerUtils.h | 7 ++++++- React/Modules/RCTUIManagerUtils.m | 9 +++++++++ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/React/Base/RCTRootView.m b/React/Base/RCTRootView.m index 20525b660..980e9e01e 100644 --- a/React/Base/RCTRootView.m +++ b/React/Base/RCTRootView.m @@ -24,6 +24,7 @@ #import "RCTRootContentView.h" #import "RCTTouchHandler.h" #import "RCTUIManager.h" +#import "RCTUIManagerUtils.h" #import "RCTUtils.h" #import "RCTView.h" #import "UIView+React.h" @@ -243,7 +244,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) * NOTE: Since the bridge persists, the RootViews might be reused, so the * react tag must be re-assigned every time a new UIManager is created. */ - self.reactTag = [_bridge.uiManager allocateRootTag]; + self.reactTag = RCTAllocateRootViewTag(); } return super.reactTag; } @@ -396,14 +397,3 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) } @end - -@implementation RCTUIManager (RCTRootView) - -- (NSNumber *)allocateRootTag -{ - NSNumber *rootTag = objc_getAssociatedObject(self, _cmd) ?: @1; - objc_setAssociatedObject(self, _cmd, @(rootTag.integerValue + 10), OBJC_ASSOCIATION_RETAIN_NONATOMIC); - return rootTag; -} - -@end diff --git a/React/Modules/RCTUIManagerUtils.h b/React/Modules/RCTUIManagerUtils.h index 8f0888f25..5858255f2 100644 --- a/React/Modules/RCTUIManagerUtils.h +++ b/React/Modules/RCTUIManagerUtils.h @@ -7,7 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -#import +#import #import #import @@ -99,3 +99,8 @@ RCT_EXTERN void RCTUnsafeExecuteOnUIManagerQueueSync(dispatch_block_t block); */ #define RCTAssertUIManagerQueue() RCTAssert(RCTIsUIManagerQueue() || RCTIsPseudoUIManagerQueue(), \ @"This function must be called on the UIManager queue") + +/** + * Returns new unique root view tag. + */ +RCT_EXTERN NSNumber *RCTAllocateRootViewTag(void); diff --git a/React/Modules/RCTUIManagerUtils.m b/React/Modules/RCTUIManagerUtils.m index c168c5d81..b6c79baa8 100644 --- a/React/Modules/RCTUIManagerUtils.m +++ b/React/Modules/RCTUIManagerUtils.m @@ -9,6 +9,8 @@ #import "RCTUIManagerUtils.h" +#import + #import "RCTAssert.h" char *const RCTUIManagerQueueName = "com.facebook.react.ShadowQueue"; @@ -93,3 +95,10 @@ void RCTUnsafeExecuteOnUIManagerQueueSync(dispatch_block_t block) } } } + +NSNumber *RCTAllocateRootViewTag() +{ + // Numbering of these tags goes from 1, 11, 21, 31, ..., 100501, ... + static int64_t rootViewTagCounter = -1; + return @(OSAtomicIncrement64(&rootViewTagCounter) * 10 + 1); +}