Skip to content

Commit be6976d

Browse files
sherginfacebook-github-bot
authored andcommittedNov 8, 2017
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
1 parent 75d62bf commit be6976d

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed
 

‎React/Base/RCTRootView.m

+2-12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#import "RCTRootContentView.h"
2525
#import "RCTTouchHandler.h"
2626
#import "RCTUIManager.h"
27+
#import "RCTUIManagerUtils.h"
2728
#import "RCTUtils.h"
2829
#import "RCTView.h"
2930
#import "UIView+React.h"
@@ -243,7 +244,7 @@ - (NSNumber *)reactTag
243244
* NOTE: Since the bridge persists, the RootViews might be reused, so the
244245
* react tag must be re-assigned every time a new UIManager is created.
245246
*/
246-
self.reactTag = [_bridge.uiManager allocateRootTag];
247+
self.reactTag = RCTAllocateRootViewTag();
247248
}
248249
return super.reactTag;
249250
}
@@ -396,14 +397,3 @@ - (CGSize)intrinsicSize
396397
}
397398

398399
@end
399-
400-
@implementation RCTUIManager (RCTRootView)
401-
402-
- (NSNumber *)allocateRootTag
403-
{
404-
NSNumber *rootTag = objc_getAssociatedObject(self, _cmd) ?: @1;
405-
objc_setAssociatedObject(self, _cmd, @(rootTag.integerValue + 10), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
406-
return rootTag;
407-
}
408-
409-
@end

‎React/Modules/RCTUIManagerUtils.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
#import <UIKit/UIKit.h>
10+
#import <Foundation/Foundation.h>
1111

1212
#import <React/RCTAssert.h>
1313
#import <React/RCTDefines.h>
@@ -99,3 +99,8 @@ RCT_EXTERN void RCTUnsafeExecuteOnUIManagerQueueSync(dispatch_block_t block);
9999
*/
100100
#define RCTAssertUIManagerQueue() RCTAssert(RCTIsUIManagerQueue() || RCTIsPseudoUIManagerQueue(), \
101101
@"This function must be called on the UIManager queue")
102+
103+
/**
104+
* Returns new unique root view tag.
105+
*/
106+
RCT_EXTERN NSNumber *RCTAllocateRootViewTag(void);

‎React/Modules/RCTUIManagerUtils.m

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#import "RCTUIManagerUtils.h"
1111

12+
#import <libkern/OSAtomic.h>
13+
1214
#import "RCTAssert.h"
1315

1416
char *const RCTUIManagerQueueName = "com.facebook.react.ShadowQueue";
@@ -93,3 +95,10 @@ void RCTUnsafeExecuteOnUIManagerQueueSync(dispatch_block_t block)
9395
}
9496
}
9597
}
98+
99+
NSNumber *RCTAllocateRootViewTag()
100+
{
101+
// Numbering of these tags goes from 1, 11, 21, 31, ..., 100501, ...
102+
static int64_t rootViewTagCounter = -1;
103+
return @(OSAtomicIncrement64(&rootViewTagCounter) * 10 + 1);
104+
}

0 commit comments

Comments
 (0)
Please sign in to comment.