mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: `RCTSurfaceHostingProxyRootView` surfaces are still automatically started right after the initialization to match `RCTRootView` interface, but `RCTSurfaceHostingView` must be started explicitly now. Also fixed some internal stuff so start and register are clear and distinct. Background / initial motivation: One tricky bit - we render the template as part of init`ing the rootView, so we don't know what the surfaceId will be before hand to register the UITemplate. Two possible solutions: 1) Require start be called explicitly after initializing the rootView, and setup the context in between. 2) Do something like "setUITemplateConfigForNextSurface" before creating the rootView, and have some hook when the surfaceId is assigned that associates the surfaceId with that "next" UITemplate stuff before. (1) seems a lot cleaner, but it requires ever user of rootView to explicitly call start on it - how do you feel about that? Seems like we could also use that start call to decide if the initial render should be synchronous or not? start vs. startSync? Reviewed By: mdvacca Differential Revision: D13372914 fbshipit-source-id: 6db297870610e6c231f8a78c0dd74d584cb64910
181 lines
5.4 KiB
Plaintext
181 lines
5.4 KiB
Plaintext
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "RCTSurfaceHostingProxyRootView.h"
|
|
|
|
#import <objc/runtime.h>
|
|
|
|
#import "RCTAssert.h"
|
|
#import "RCTBridge.h"
|
|
#import "RCTLog.h"
|
|
#import "RCTPerformanceLogger.h"
|
|
#import "RCTProfile.h"
|
|
#import "RCTRootContentView.h"
|
|
#import "RCTRootViewDelegate.h"
|
|
#import "RCTSurface.h"
|
|
#import "UIView+React.h"
|
|
|
|
static RCTSurfaceSizeMeasureMode convertToSurfaceSizeMeasureMode(RCTRootViewSizeFlexibility sizeFlexibility) {
|
|
switch (sizeFlexibility) {
|
|
case RCTRootViewSizeFlexibilityWidthAndHeight:
|
|
return RCTSurfaceSizeMeasureModeWidthUndefined | RCTSurfaceSizeMeasureModeHeightUndefined;
|
|
case RCTRootViewSizeFlexibilityWidth:
|
|
return RCTSurfaceSizeMeasureModeWidthUndefined | RCTSurfaceSizeMeasureModeHeightExact;
|
|
case RCTRootViewSizeFlexibilityHeight:
|
|
return RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightUndefined;
|
|
case RCTRootViewSizeFlexibilityNone:
|
|
return RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact;
|
|
}
|
|
}
|
|
|
|
static RCTRootViewSizeFlexibility convertToRootViewSizeFlexibility(RCTSurfaceSizeMeasureMode sizeMeasureMode) {
|
|
switch (sizeMeasureMode) {
|
|
case RCTSurfaceSizeMeasureModeWidthUndefined | RCTSurfaceSizeMeasureModeHeightUndefined:
|
|
return RCTRootViewSizeFlexibilityWidthAndHeight;
|
|
case RCTSurfaceSizeMeasureModeWidthUndefined | RCTSurfaceSizeMeasureModeHeightExact:
|
|
return RCTRootViewSizeFlexibilityWidth;
|
|
case RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightUndefined:
|
|
return RCTRootViewSizeFlexibilityHeight;
|
|
case RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact:
|
|
default:
|
|
return RCTRootViewSizeFlexibilityNone;
|
|
}
|
|
}
|
|
|
|
@implementation RCTSurfaceHostingProxyRootView
|
|
|
|
- (instancetype)initWithBridge:(RCTBridge *)bridge
|
|
moduleName:(NSString *)moduleName
|
|
initialProperties:(NSDictionary *)initialProperties
|
|
{
|
|
RCTAssertMainQueue();
|
|
RCTAssert(bridge, @"A bridge instance is required to create an RCTSurfaceHostingProxyRootView");
|
|
RCTAssert(moduleName, @"A moduleName is required to create an RCTSurfaceHostingProxyRootView");
|
|
|
|
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTSurfaceHostingProxyRootView init]", nil);
|
|
|
|
_bridge = bridge;
|
|
|
|
if (!bridge.isLoading) {
|
|
[bridge.performanceLogger markStartForTag:RCTPLTTI];
|
|
}
|
|
|
|
// `RCTRootViewSizeFlexibilityNone` is the RCTRootView's default.
|
|
RCTSurfaceSizeMeasureMode sizeMeasureMode = convertToSurfaceSizeMeasureMode(RCTRootViewSizeFlexibilityNone);
|
|
|
|
if (self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties sizeMeasureMode:sizeMeasureMode]) {
|
|
self.backgroundColor = [UIColor whiteColor];
|
|
[super.surface start];
|
|
}
|
|
|
|
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"");
|
|
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
|
|
moduleName:(NSString *)moduleName
|
|
initialProperties:(NSDictionary *)initialProperties
|
|
launchOptions:(NSDictionary *)launchOptions
|
|
{
|
|
RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:bundleURL
|
|
moduleProvider:nil
|
|
launchOptions:launchOptions];
|
|
|
|
return [self initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
|
|
}
|
|
|
|
RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
|
|
RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
|
|
|
# pragma mark proxy methods to RCTSurfaceHostingView
|
|
|
|
- (NSString *)moduleName
|
|
{
|
|
return super.surface.moduleName;
|
|
}
|
|
|
|
- (UIView *)contentView
|
|
{
|
|
return self;
|
|
}
|
|
|
|
- (NSNumber *)reactTag
|
|
{
|
|
return super.surface.rootViewTag;
|
|
}
|
|
|
|
- (RCTRootViewSizeFlexibility)sizeFlexibility
|
|
{
|
|
return convertToRootViewSizeFlexibility(super.sizeMeasureMode);
|
|
}
|
|
|
|
- (void)setSizeFlexibility:(RCTRootViewSizeFlexibility)sizeFlexibility
|
|
{
|
|
super.sizeMeasureMode = convertToSurfaceSizeMeasureMode(sizeFlexibility);
|
|
}
|
|
|
|
- (NSDictionary *)appProperties
|
|
{
|
|
return super.surface.properties;
|
|
}
|
|
|
|
- (void)setAppProperties:(NSDictionary *)appProperties
|
|
{
|
|
[super.surface setProperties:appProperties];
|
|
}
|
|
|
|
- (UIView *)loadingView
|
|
{
|
|
return super.activityIndicatorViewFactory ? super.activityIndicatorViewFactory() : nil;
|
|
}
|
|
|
|
- (void)setLoadingView:(UIView *)loadingView
|
|
{
|
|
super.activityIndicatorViewFactory = ^UIView *(void) {
|
|
return loadingView;
|
|
};
|
|
}
|
|
|
|
#pragma mark RCTSurfaceDelegate proxying
|
|
|
|
- (void)surface:(RCTSurface *)surface didChangeStage:(RCTSurfaceStage)stage
|
|
{
|
|
[super surface:surface didChangeStage:stage];
|
|
if (RCTSurfaceStageIsRunning(stage)) {
|
|
[_bridge.performanceLogger markStopForTag:RCTPLTTI];
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTContentDidAppearNotification
|
|
object:self];
|
|
});
|
|
}
|
|
}
|
|
|
|
- (void)surface:(RCTSurface *)surface didChangeIntrinsicSize:(CGSize)intrinsicSize
|
|
{
|
|
[super surface:surface didChangeIntrinsicSize:intrinsicSize];
|
|
|
|
[_delegate rootViewDidChangeIntrinsicSize:(RCTRootView *)self];
|
|
}
|
|
|
|
#pragma mark legacy
|
|
|
|
- (UIViewController *)reactViewController
|
|
{
|
|
return _reactViewController ?: [super reactViewController];
|
|
}
|
|
|
|
#pragma mark unsupported
|
|
|
|
- (void)cancelTouches
|
|
{
|
|
// Not supported.
|
|
}
|
|
|
|
@end
|
|
|