Skip to content

Commit c02c78a

Browse files
sherginfacebook-github-bot
authored andcommitted
Splitting RCTRootView.m, decoupling RCTRootContentView
Reviewed By: javache Differential Revision: D4570067 fbshipit-source-id: 91305d0c175af135ce2f22d7992bee68c13da80e
1 parent ba170ec commit c02c78a

File tree

6 files changed

+180
-122
lines changed

6 files changed

+180
-122
lines changed

React/Base/RCTRootContentView.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import <UIKit/UIKit.h>
11+
12+
#import <React/RCTInvalidating.h>
13+
#import <React/RCTRootView.h>
14+
#import <React/RCTView.h>
15+
16+
@class RCTBridge;
17+
@class RCTTouchHandler;
18+
19+
@interface RCTRootContentView : RCTView <RCTInvalidating>
20+
21+
@property (nonatomic, readonly) BOOL contentHasAppeared;
22+
@property (nonatomic, readonly, strong) RCTTouchHandler *touchHandler;
23+
@property (nonatomic, assign) BOOL passThroughTouches;
24+
@property (nonatomic, assign) RCTRootViewSizeFlexibility sizeFlexibility;
25+
26+
- (instancetype)initWithFrame:(CGRect)frame
27+
bridge:(RCTBridge *)bridge
28+
reactTag:(NSNumber *)reactTag
29+
sizeFlexiblity:(RCTRootViewSizeFlexibility)sizeFlexibility NS_DESIGNATED_INITIALIZER;
30+
31+
@end

React/Base/RCTRootContentView.m

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "RCTRootContentView.h"
11+
12+
#import "RCTBridge.h"
13+
#import "RCTPerformanceLogger.h"
14+
#import "RCTRootView.h"
15+
#import "RCTRootViewInternal.h"
16+
#import "RCTTouchHandler.h"
17+
#import "RCTUIManager.h"
18+
#import "UIView+React.h"
19+
20+
@implementation RCTRootContentView
21+
{
22+
__weak RCTBridge *_bridge;
23+
UIColor *_backgroundColor;
24+
}
25+
26+
- (instancetype)initWithFrame:(CGRect)frame
27+
bridge:(RCTBridge *)bridge
28+
reactTag:(NSNumber *)reactTag
29+
sizeFlexiblity:(RCTRootViewSizeFlexibility)sizeFlexibility
30+
{
31+
if ((self = [super initWithFrame:frame])) {
32+
_bridge = bridge;
33+
self.reactTag = reactTag;
34+
_sizeFlexibility = sizeFlexibility;
35+
_touchHandler = [[RCTTouchHandler alloc] initWithBridge:_bridge];
36+
[_touchHandler attachToView:self];
37+
[_bridge.uiManager registerRootView:self];
38+
self.layer.backgroundColor = NULL;
39+
}
40+
return self;
41+
}
42+
43+
RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame:(CGRect)frame)
44+
RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder:(nonnull NSCoder *)aDecoder)
45+
46+
- (void)layoutSubviews
47+
{
48+
[super layoutSubviews];
49+
[self updateAvailableSize];
50+
}
51+
52+
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
53+
{
54+
[super insertReactSubview:subview atIndex:atIndex];
55+
[_bridge.performanceLogger markStopForTag:RCTPLTTI];
56+
dispatch_async(dispatch_get_main_queue(), ^{
57+
if (!self->_contentHasAppeared) {
58+
self->_contentHasAppeared = YES;
59+
[[NSNotificationCenter defaultCenter] postNotificationName:RCTContentDidAppearNotification
60+
object:self.superview];
61+
}
62+
});
63+
}
64+
65+
- (void)setSizeFlexibility:(RCTRootViewSizeFlexibility)sizeFlexibility
66+
{
67+
if (_sizeFlexibility == sizeFlexibility) {
68+
return;
69+
}
70+
71+
_sizeFlexibility = sizeFlexibility;
72+
[self setNeedsLayout];
73+
}
74+
75+
- (void)updateAvailableSize
76+
{
77+
if (!self.reactTag || !_bridge.isValid) {
78+
return;
79+
}
80+
81+
CGSize size = self.bounds.size;
82+
CGSize availableSize =
83+
CGSizeMake(
84+
_sizeFlexibility & RCTRootViewSizeFlexibilityWidth ? INFINITY : size.width,
85+
_sizeFlexibility & RCTRootViewSizeFlexibilityHeight ? INFINITY : size.height
86+
);
87+
88+
[_bridge.uiManager setAvailableSize:availableSize forRootView:self];
89+
}
90+
91+
- (void)setBackgroundColor:(UIColor *)backgroundColor
92+
{
93+
_backgroundColor = backgroundColor;
94+
if (self.reactTag && _bridge.isValid) {
95+
[_bridge.uiManager setBackgroundColor:backgroundColor forView:self];
96+
}
97+
}
98+
99+
- (UIColor *)backgroundColor
100+
{
101+
return _backgroundColor;
102+
}
103+
104+
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
105+
{
106+
// The root content view itself should never receive touches
107+
UIView *hitView = [super hitTest:point withEvent:event];
108+
if (_passThroughTouches && hitView == self) {
109+
return nil;
110+
}
111+
return hitView;
112+
}
113+
114+
- (void)invalidate
115+
{
116+
if (self.userInteractionEnabled) {
117+
self.userInteractionEnabled = NO;
118+
[(RCTRootView *)self.superview contentViewInvalidated];
119+
[_bridge enqueueJSCall:@"AppRegistry"
120+
method:@"unmountApplicationComponentAtRootTag"
121+
args:@[self.reactTag]
122+
completion:NULL];
123+
}
124+
}
125+
126+
@end

React/Base/RCTRootView.m

Lines changed: 1 addition & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
#import "RCTEventDispatcher.h"
2020
#import "RCTKeyCommands.h"
2121
#import "RCTLog.h"
22-
#import "RCTPerformanceLogger.h"
2322
#import "RCTTouchHandler.h"
2423
#import "RCTUIManager.h"
2524
#import "RCTUtils.h"
2625
#import "RCTView.h"
26+
#import "RCTRootContentView.h"
2727
#import "UIView+React.h"
2828
#import "RCTProfile.h"
2929

@@ -40,19 +40,6 @@ - (NSNumber *)allocateRootTag;
4040

4141
@end
4242

43-
@interface RCTRootContentView : RCTView <RCTInvalidating>
44-
45-
@property (nonatomic, readonly) BOOL contentHasAppeared;
46-
@property (nonatomic, readonly, strong) RCTTouchHandler *touchHandler;
47-
@property (nonatomic, assign) BOOL passThroughTouches;
48-
@property (nonatomic, assign) RCTRootViewSizeFlexibility sizeFlexibility;
49-
50-
- (instancetype)initWithFrame:(CGRect)frame
51-
bridge:(RCTBridge *)bridge
52-
reactTag:(NSNumber *)reactTag
53-
sizeFlexiblity:(RCTRootViewSizeFlexibility)sizeFlexibility NS_DESIGNATED_INITIALIZER;
54-
@end
55-
5643
@implementation RCTRootView
5744
{
5845
RCTBridge *_bridge;
@@ -374,111 +361,3 @@ - (NSNumber *)allocateRootTag
374361
}
375362

376363
@end
377-
378-
@implementation RCTRootContentView
379-
{
380-
__weak RCTBridge *_bridge;
381-
UIColor *_backgroundColor;
382-
}
383-
384-
- (instancetype)initWithFrame:(CGRect)frame
385-
bridge:(RCTBridge *)bridge
386-
reactTag:(NSNumber *)reactTag
387-
sizeFlexiblity:(RCTRootViewSizeFlexibility)sizeFlexibility
388-
{
389-
if ((self = [super initWithFrame:frame])) {
390-
_bridge = bridge;
391-
self.reactTag = reactTag;
392-
_sizeFlexibility = sizeFlexibility;
393-
_touchHandler = [[RCTTouchHandler alloc] initWithBridge:_bridge];
394-
[_touchHandler attachToView:self];
395-
[_bridge.uiManager registerRootView:self];
396-
self.layer.backgroundColor = NULL;
397-
}
398-
return self;
399-
}
400-
401-
RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame:(CGRect)frame)
402-
RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder:(nonnull NSCoder *)aDecoder)
403-
404-
- (void)layoutSubviews
405-
{
406-
[super layoutSubviews];
407-
[self updateAvailableSize];
408-
}
409-
410-
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
411-
{
412-
[super insertReactSubview:subview atIndex:atIndex];
413-
[_bridge.performanceLogger markStopForTag:RCTPLTTI];
414-
dispatch_async(dispatch_get_main_queue(), ^{
415-
if (!self->_contentHasAppeared) {
416-
self->_contentHasAppeared = YES;
417-
[[NSNotificationCenter defaultCenter] postNotificationName:RCTContentDidAppearNotification
418-
object:self.superview];
419-
}
420-
});
421-
}
422-
423-
- (void)setSizeFlexibility:(RCTRootViewSizeFlexibility)sizeFlexibility
424-
{
425-
if (_sizeFlexibility == sizeFlexibility) {
426-
return;
427-
}
428-
429-
_sizeFlexibility = sizeFlexibility;
430-
[self setNeedsLayout];
431-
}
432-
433-
- (void)updateAvailableSize
434-
{
435-
if (!self.reactTag || !_bridge.isValid) {
436-
return;
437-
}
438-
439-
CGSize size = self.bounds.size;
440-
CGSize availableSize =
441-
CGSizeMake(
442-
_sizeFlexibility & RCTRootViewSizeFlexibilityWidth ? INFINITY : size.width,
443-
_sizeFlexibility & RCTRootViewSizeFlexibilityHeight ? INFINITY : size.height
444-
);
445-
446-
[_bridge.uiManager setAvailableSize:availableSize forRootView:self];
447-
}
448-
449-
- (void)setBackgroundColor:(UIColor *)backgroundColor
450-
{
451-
_backgroundColor = backgroundColor;
452-
if (self.reactTag && _bridge.isValid) {
453-
[_bridge.uiManager setBackgroundColor:backgroundColor forView:self];
454-
}
455-
}
456-
457-
- (UIColor *)backgroundColor
458-
{
459-
return _backgroundColor;
460-
}
461-
462-
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
463-
{
464-
// The root content view itself should never receive touches
465-
UIView *hitView = [super hitTest:point withEvent:event];
466-
if (_passThroughTouches && hitView == self) {
467-
return nil;
468-
}
469-
return hitView;
470-
}
471-
472-
- (void)invalidate
473-
{
474-
if (self.userInteractionEnabled) {
475-
self.userInteractionEnabled = NO;
476-
[(RCTRootView *)self.superview contentViewInvalidated];
477-
[_bridge enqueueJSCall:@"AppRegistry"
478-
method:@"unmountApplicationComponentAtRootTag"
479-
args:@[self.reactTag]
480-
completion:NULL];
481-
}
482-
}
483-
484-
@end

React/Base/RCTRootViewInternal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@
3030
@property (nonatomic, strong) UIView *reactPreferredFocusedView;
3131
#endif
3232

33+
- (void)contentViewInvalidated;
34+
3335
@end

React/React.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,10 @@
713713
594AD5D21E46D87500B07237 /* RCTScrollContentViewManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 594AD5CB1E46D87500B07237 /* RCTScrollContentViewManager.h */; };
714714
594AD5D31E46D87500B07237 /* RCTScrollContentViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 594AD5CC1E46D87500B07237 /* RCTScrollContentViewManager.m */; };
715715
594AD5D41E46D87500B07237 /* RCTScrollContentViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 594AD5CC1E46D87500B07237 /* RCTScrollContentViewManager.m */; };
716+
597AD1BD1E577D7800152581 /* RCTRootContentView.h in Headers */ = {isa = PBXBuildFile; fileRef = 597AD1BB1E577D7800152581 /* RCTRootContentView.h */; };
717+
597AD1BE1E577D7800152581 /* RCTRootContentView.h in Headers */ = {isa = PBXBuildFile; fileRef = 597AD1BB1E577D7800152581 /* RCTRootContentView.h */; };
718+
597AD1BF1E577D7800152581 /* RCTRootContentView.m in Sources */ = {isa = PBXBuildFile; fileRef = 597AD1BC1E577D7800152581 /* RCTRootContentView.m */; };
719+
597AD1C01E577D7800152581 /* RCTRootContentView.m in Sources */ = {isa = PBXBuildFile; fileRef = 597AD1BC1E577D7800152581 /* RCTRootContentView.m */; };
716720
68EFE4EE1CF6EB3900A1DE13 /* RCTBundleURLProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 68EFE4ED1CF6EB3900A1DE13 /* RCTBundleURLProvider.m */; };
717721
830A229E1A66C68A008503DA /* RCTRootView.m in Sources */ = {isa = PBXBuildFile; fileRef = 830A229D1A66C68A008503DA /* RCTRootView.m */; };
718722
83392EB31B6634E10013B15F /* RCTModalHostViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 83392EB21B6634E10013B15F /* RCTModalHostViewController.m */; };
@@ -1335,6 +1339,8 @@
13351339
594AD5CA1E46D87500B07237 /* RCTScrollContentShadowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTScrollContentShadowView.m; sourceTree = "<group>"; };
13361340
594AD5CB1E46D87500B07237 /* RCTScrollContentViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTScrollContentViewManager.h; sourceTree = "<group>"; };
13371341
594AD5CC1E46D87500B07237 /* RCTScrollContentViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTScrollContentViewManager.m; sourceTree = "<group>"; };
1342+
597AD1BB1E577D7800152581 /* RCTRootContentView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTRootContentView.h; sourceTree = "<group>"; };
1343+
597AD1BC1E577D7800152581 /* RCTRootContentView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTRootContentView.m; sourceTree = "<group>"; };
13381344
68EFE4EC1CF6EB3000A1DE13 /* RCTBundleURLProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTBundleURLProvider.h; sourceTree = "<group>"; };
13391345
68EFE4ED1CF6EB3900A1DE13 /* RCTBundleURLProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTBundleURLProvider.m; sourceTree = "<group>"; };
13401346
6A15FB0C1BDF663500531DFB /* RCTRootViewInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTRootViewInternal.h; sourceTree = "<group>"; };
@@ -1771,6 +1777,8 @@
17711777
3D7749431DC1065C007EC8D8 /* RCTPlatform.m */,
17721778
A2440AA01DF8D854006E7BFC /* RCTReloadCommand.h */,
17731779
A2440AA11DF8D854006E7BFC /* RCTReloadCommand.m */,
1780+
597AD1BB1E577D7800152581 /* RCTRootContentView.h */,
1781+
597AD1BC1E577D7800152581 /* RCTRootContentView.m */,
17741782
830A229C1A66C68A008503DA /* RCTRootView.h */,
17751783
830A229D1A66C68A008503DA /* RCTRootView.m */,
17761784
13AFBCA21C07287B00BBAEAA /* RCTRootViewDelegate.h */,
@@ -1880,6 +1888,7 @@
18801888
3D302F681DF828F800D6DDAE /* RCTMacros.h in Headers */,
18811889
3D302F691DF828F800D6DDAE /* RCTProfile.h in Headers */,
18821890
3D302F6A1DF828F800D6DDAE /* RCTActivityIndicatorView.h in Headers */,
1891+
597AD1BE1E577D7800152581 /* RCTRootContentView.h in Headers */,
18831892
3D302F6B1DF828F800D6DDAE /* RCTActivityIndicatorViewManager.h in Headers */,
18841893
3D302F6C1DF828F800D6DDAE /* RCTAnimationType.h in Headers */,
18851894
3D302F6D1DF828F800D6DDAE /* RCTAutoInsetsProtocol.h in Headers */,
@@ -2016,6 +2025,7 @@
20162025
3D80DA2B1DF820620028D040 /* RCTErrorInfo.h in Headers */,
20172026
3D80DA2C1DF820620028D040 /* RCTEventDispatcher.h in Headers */,
20182027
3D80DA2D1DF820620028D040 /* RCTFrameUpdate.h in Headers */,
2028+
597AD1BD1E577D7800152581 /* RCTRootContentView.h in Headers */,
20192029
3D80DA2E1DF820620028D040 /* RCTImageSource.h in Headers */,
20202030
3D80DA2F1DF820620028D040 /* RCTInvalidating.h in Headers */,
20212031
3D80DA301DF820620028D040 /* RCTJavaScriptExecutor.h in Headers */,
@@ -2467,6 +2477,7 @@
24672477
2D3B5ED91D9B098E00451313 /* RCTNavItem.m in Sources */,
24682478
2D74EAFA1DAE9590003B751B /* RCTMultipartDataTask.m in Sources */,
24692479
2D3B5EC51D9B094D00451313 /* RCTProfileTrampoline-i386.S in Sources */,
2480+
597AD1C01E577D7800152581 /* RCTRootContentView.m in Sources */,
24702481
2D3B5EC41D9B094B00451313 /* RCTProfileTrampoline-arm64.S in Sources */,
24712482
2D3B5EBB1D9B092300451313 /* RCTI18nManager.m in Sources */,
24722483
2D3B5EBE1D9B092D00451313 /* RCTUIManager.m in Sources */,
@@ -2537,6 +2548,7 @@
25372548
isa = PBXSourcesBuildPhase;
25382549
buildActionMask = 2147483647;
25392550
files = (
2551+
597AD1BF1E577D7800152581 /* RCTRootContentView.m in Sources */,
25402552
13456E961ADAD482009F94A7 /* RCTConvert+MapKit.m in Sources */,
25412553
13723B501A82FD3C00F88898 /* RCTStatusBarManager.m in Sources */,
25422554
000E6CEB1AB0E980000CDF4D /* RCTSourceCode.m in Sources */,

0 commit comments

Comments
 (0)