Permalink
Browse files

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
  • Loading branch information...
shergin authored and facebook-github-bot committed Nov 8, 2017
1 parent 75d62bf commit be6976d6faa333311405bd6184300bbd8da6cbca
Showing with 17 additions and 13 deletions.
  1. +2 −12 React/Base/RCTRootView.m
  2. +6 −1 React/Modules/RCTUIManagerUtils.h
  3. +9 −0 React/Modules/RCTUIManagerUtils.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 @@ - (NSNumber *)reactTag
* 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 @@ - (CGSize)intrinsicSize
}
@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
@@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <React/RCTAssert.h>
#import <React/RCTDefines.h>
@@ -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);
@@ -9,6 +9,8 @@
#import "RCTUIManagerUtils.h"
#import <libkern/OSAtomic.h>
#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);
}

0 comments on commit be6976d

Please sign in to comment.