Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "RCTRootViewInternal.h"

#import <objc/runtime.h>
#import <react/renderer/core/ReactRootViewTagGenerator.h>

#import "RCTAssert.h"
#import "RCTBridge+Private.h"
Expand All @@ -30,16 +31,10 @@

NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotification";

@interface RCTUIManager (RCTRootView)

- (NSNumber *)allocateRootTag;

@end

@implementation RCTRootView {
RCTBridge *_bridge;
NSString *_moduleName;
RCTRootContentView *_contentView;
UIView *_contentView;
BOOL _passThroughTouches;
CGSize _intrinsicContentSize;
}
Expand Down Expand Up @@ -125,13 +120,13 @@ - (UIView *)view

- (BOOL)passThroughTouches
{
return _contentView.passThroughTouches;
return static_cast<RCTRootContentView *>(_contentView).passThroughTouches;
}

- (void)setPassThroughTouches:(BOOL)passThroughTouches
{
_passThroughTouches = passThroughTouches;
_contentView.passThroughTouches = passThroughTouches;
static_cast<RCTRootContentView *>(_contentView).passThroughTouches = passThroughTouches;
}

#pragma mark - Layout
Expand Down Expand Up @@ -166,9 +161,9 @@ - (void)setMinimumSize:(CGSize)minimumSize
}
_minimumSize = minimumSize;
__block NSNumber *tag = self.reactTag;
__weak typeof(self) weakSelf = self;
__weak __typeof(self) weakSelf = self;
RCTExecuteOnUIManagerQueue(^{
__strong typeof(self) strongSelf = weakSelf;
__strong __typeof(self) strongSelf = weakSelf;
if (strongSelf && strongSelf->_bridge.isValid) {
RCTRootShadowView *shadowView = (RCTRootShadowView *)[strongSelf->_bridge.uiManager shadowViewForReactTag:tag];
shadowView.minimumSize = minimumSize;
Expand All @@ -189,22 +184,22 @@ - (BOOL)canBecomeFirstResponder
- (void)setLoadingView:(UIView *)loadingView
{
_loadingView = loadingView;
if (!_contentView.contentHasAppeared) {
if (!static_cast<RCTRootContentView *>(_contentView).contentHasAppeared) {
[self showLoadingView];
}
}

- (void)showLoadingView
{
if (_loadingView && !_contentView.contentHasAppeared) {
if (_loadingView && !static_cast<RCTRootContentView *>(_contentView).contentHasAppeared) {
_loadingView.hidden = NO;
[self addSubview:_loadingView];
}
}

- (void)hideLoadingView
{
if (_loadingView.superview == self && _contentView.contentHasAppeared) {
if (_loadingView.superview == self && static_cast<RCTRootContentView *>(_contentView).contentHasAppeared) {
if (_loadingViewFadeDuration > 0) {
dispatch_after(
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(_loadingViewFadeDelay * NSEC_PER_SEC)),
Expand Down Expand Up @@ -232,13 +227,10 @@ - (NSNumber *)reactTag
RCTAssertMainQueue();
if (!super.reactTag) {
/**
* Every root view that is created must have a unique react tag.
* Numbering of these tags goes from 1, 11, 21, 31, etc
*
* 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 = RCTAllocateRootViewTag();
self.reactTag = @(facebook::react::getNextRootViewTag());
}
return super.reactTag;
}
Expand All @@ -257,7 +249,7 @@ - (void)javaScriptDidLoad:(NSNotification *)notification
// Use the (batched) bridge that's sent in the notification payload, so the
// RCTRootContentView is scoped to the right bridge
RCTBridge *bridge = notification.userInfo[@"bridge"];
if (bridge != _contentView.bridge) {
if (bridge != static_cast<RCTRootContentView *>(_contentView).bridge) {
[self bundleFinishedLoading:bridge];
}
}
Expand All @@ -276,7 +268,7 @@ - (void)bundleFinishedLoading:(RCTBridge *)bridge
sizeFlexibility:_sizeFlexibility];
[self runApplication:bridge];

_contentView.passThroughTouches = _passThroughTouches;
static_cast<RCTRootContentView *>(_contentView).passThroughTouches = _passThroughTouches;
[self insertSubview:_contentView atIndex:0];

if (_sizeFlexibility == RCTRootViewSizeFlexibilityNone) {
Expand Down Expand Up @@ -304,7 +296,7 @@ - (void)setSizeFlexibility:(RCTRootViewSizeFlexibility)sizeFlexibility

_sizeFlexibility = sizeFlexibility;
[self setNeedsLayout];
_contentView.sizeFlexibility = _sizeFlexibility;
static_cast<RCTRootContentView *>(_contentView).sizeFlexibility = _sizeFlexibility;
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
Expand Down Expand Up @@ -382,7 +374,7 @@ - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection

- (void)dealloc
{
[_contentView invalidate];
[static_cast<RCTRootContentView *>(_contentView) invalidate];
}

@end
Expand All @@ -398,7 +390,7 @@ - (CGSize)intrinsicSize
- (void)cancelTouches
{
RCTLogWarn(@"`-[RCTRootView cancelTouches]` is deprecated and will be deleted soon.");
[[_contentView touchHandler] cancel];
[[static_cast<RCTRootContentView *>(_contentView) touchHandler] cancel];
}

@end
6 changes: 3 additions & 3 deletions packages/react-native/React/Base/Surface/RCTSurface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#import "RCTSurface.h"
#import "RCTSurfaceView+Internal.h"

#import <mutex>

#import <react/renderer/core/ReactRootViewTagGenerator.h>
#import <stdatomic.h>
#import <mutex>

#import "RCTAssert.h"
#import "RCTBridge+Private.h"
Expand Down Expand Up @@ -73,7 +73,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
_batchedBridge = [_bridge batchedBridge] ?: _bridge;
_moduleName = moduleName;
_properties = [initialProperties copy];
_rootViewTag = RCTAllocateRootViewTag();
_rootViewTag = @(facebook::react::getNextRootViewTag());

_rootShadowViewDidStartRenderingSemaphore = dispatch_semaphore_create(0);
_rootShadowViewDidStartLayingOutSemaphore = dispatch_semaphore_create(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import <React/RCTSurfaceView.h>
#import <React/RCTUIManagerUtils.h>
#import <React/RCTUtils.h>
#import <react/renderer/core/ReactRootViewTagGenerator.h>
#import <react/renderer/mounting/MountingCoordinator.h>

#import "RCTSurfacePresenter.h"
Expand Down Expand Up @@ -56,8 +57,7 @@ - (instancetype)initWithSurfacePresenter:(RCTSurfacePresenter *)surfacePresenter
if (self = [super init]) {
_surfacePresenter = surfacePresenter;

_surfaceHandler =
SurfaceHandler{RCTStringFromNSString(moduleName), (SurfaceId)[RCTAllocateRootViewTag() integerValue]};
_surfaceHandler = SurfaceHandler{RCTStringFromNSString(moduleName), getNextRootViewTag()};
_surfaceHandler->setProps(convertIdToFollyDynamic(initialProperties));

[_surfacePresenter registerSurface:self];
Expand Down
5 changes: 0 additions & 5 deletions packages/react-native/React/Modules/RCTUIManagerUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,3 @@ 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);
8 changes: 0 additions & 8 deletions packages/react-native/React/Modules/RCTUIManagerUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,3 @@ void RCTUnsafeExecuteOnUIManagerQueueSync(dispatch_block_t block)
}
}
}

NSNumber *RCTAllocateRootViewTag(void)
{
// Keep in sync with ReactRootViewTagGenerator.h - see that file for an explanation on why the
// increment here is 10.
static _Atomic int64_t rootViewTagCounter = 0;
return @(atomic_fetch_add_explicit(&rootViewTagCounter, 1, memory_order_relaxed) * 10 + 1);
}