Skip to content

Commit

Permalink
RCTAllocatedRootViewTag was moved to RCTUIManagerUtils
Browse files Browse the repository at this point in the history
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 be6976d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
14 changes: 2 additions & 12 deletions React/Base/RCTRootView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 changes: 6 additions & 1 deletion React/Modules/RCTUIManagerUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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 changes: 9 additions & 0 deletions React/Modules/RCTUIManagerUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#import "RCTUIManagerUtils.h"

#import <libkern/OSAtomic.h>

#import "RCTAssert.h"

char *const RCTUIManagerQueueName = "com.facebook.react.ShadowQueue";
Expand Down Expand Up @@ -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.