|
| 1 | +#import "RCTReactController.h" |
| 2 | +#import <React/RCTCxxBridgeDelegate.h> |
| 3 | +#import <React/RCTLog.h> |
| 4 | +#import <React/RCTRootView.h> |
| 5 | +#import <React/RCTSurfacePresenterBridgeAdapter.h> |
| 6 | +#import <React/RCTUtils.h> |
| 7 | +#import <react/renderer/runtimescheduler/RuntimeScheduler.h> |
| 8 | +#import "RCTAppSetupUtils.h" |
| 9 | +#import <React/RCTUtils.h> |
| 10 | + |
| 11 | +#if RN_DISABLE_OSS_PLUGIN_HEADER |
| 12 | +#import <RCTTurboModulePlugin/RCTTurboModulePlugin.h> |
| 13 | +#else |
| 14 | +#import <React/CoreModulesPlugins.h> |
| 15 | +#endif |
| 16 | +#import <React/RCTBundleURLProvider.h> |
| 17 | +#import <React/RCTComponentViewFactory.h> |
| 18 | +#import <React/RCTComponentViewProtocol.h> |
| 19 | +#import <React/RCTFabricSurface.h> |
| 20 | +#import <React/RCTSurfaceHostingProxyRootView.h> |
| 21 | +#import <React/RCTSurfacePresenter.h> |
| 22 | +#import <ReactCommon/RCTContextContainerHandling.h> |
| 23 | +#if USE_HERMES |
| 24 | +#import <ReactCommon/RCTHermesInstance.h> |
| 25 | +#else |
| 26 | +#import <ReactCommon/RCTJscInstance.h> |
| 27 | +#endif |
| 28 | +#import <ReactCommon/RCTHost+Internal.h> |
| 29 | +#import <ReactCommon/RCTHost.h> |
| 30 | +#import <ReactCommon/RCTTurboModuleManager.h> |
| 31 | +#import <react/config/ReactNativeConfig.h> |
| 32 | +#import <react/renderer/runtimescheduler/RuntimeScheduler.h> |
| 33 | +#import <react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h> |
| 34 | +#import <react/runtime/JSRuntimeFactory.h> |
| 35 | + |
| 36 | +static NSString *const kRNConcurrentRoot = @"concurrentRoot"; |
| 37 | + |
| 38 | +static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabricEnabled) |
| 39 | +{ |
| 40 | + NSMutableDictionary *mutableProps = [initialProps mutableCopy] ?: [NSMutableDictionary new]; |
| 41 | + // Hardcoding the Concurrent Root as it it not recommended to |
| 42 | + // have the concurrentRoot turned off when Fabric is enabled. |
| 43 | + mutableProps[kRNConcurrentRoot] = @(isFabricEnabled); |
| 44 | + return mutableProps; |
| 45 | +} |
| 46 | + |
| 47 | + |
| 48 | +@implementation RCTReactController |
| 49 | + |
| 50 | +- (instancetype)initWithModuleName:(NSString *)moduleName initProps:(NSDictionary *)initProps { |
| 51 | + if (self = [super init]) { |
| 52 | + _moduleName = moduleName; |
| 53 | + _initialProps = initProps; |
| 54 | + } |
| 55 | + return self; |
| 56 | +} |
| 57 | + |
| 58 | +- (void)loadView { |
| 59 | + BOOL fabricEnabled = self.fabricEnabled; |
| 60 | + BOOL enableBridgeless = self.bridgelessEnabled; |
| 61 | + |
| 62 | + NSDictionary *initProps = updateInitialProps([self prepareInitialProps], fabricEnabled); |
| 63 | + |
| 64 | + UIView *rootView; |
| 65 | + if (enableBridgeless) { |
| 66 | + // TODO: Fix Bridgeless mode |
| 67 | +// RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:self.moduleName initialProperties:initProps]; |
| 68 | + |
| 69 | +// RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc] |
| 70 | +// initWithSurface:surface |
| 71 | +// sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact]; |
| 72 | + |
| 73 | +// rootView = (RCTRootView *)surfaceHostingProxyRootView; |
| 74 | + } else { |
| 75 | + RCTBridge* bridge = [RCTSharedApplication().delegate performSelector:@selector(bridge)]; |
| 76 | + rootView = [self createRootViewWithBridge:bridge moduleName:self.moduleName initProps:initProps]; |
| 77 | + } |
| 78 | + |
| 79 | + // Set rootView to the main of this view controller. |
| 80 | + self.view = rootView; |
| 81 | +} |
| 82 | + |
| 83 | +- (UIView *)createRootViewWithBridge:(RCTBridge *)bridge |
| 84 | + moduleName:(NSString *)moduleName |
| 85 | + initProps:(NSDictionary *)initProps |
| 86 | +{ |
| 87 | + BOOL enableFabric = self.fabricEnabled; |
| 88 | + UIView *rootView = RCTAppSetupDefaultRootView(bridge, moduleName, initProps, enableFabric); |
| 89 | + |
| 90 | + rootView.backgroundColor = [UIColor systemBackgroundColor]; |
| 91 | + |
| 92 | + return rootView; |
| 93 | +} |
| 94 | + |
| 95 | +- (NSDictionary *)prepareInitialProps |
| 96 | +{ |
| 97 | + return self.initialProps; |
| 98 | +} |
| 99 | + |
| 100 | +- (BOOL)newArchEnabled |
| 101 | +{ |
| 102 | + return [RCTSharedApplication().delegate performSelector:@selector(newArchEnabled)]; |
| 103 | +} |
| 104 | + |
| 105 | +- (BOOL)turboModuleEnabled |
| 106 | +{ |
| 107 | + return [self newArchEnabled]; |
| 108 | +} |
| 109 | + |
| 110 | +- (BOOL)fabricEnabled |
| 111 | +{ |
| 112 | + return [self newArchEnabled]; |
| 113 | +} |
| 114 | + |
| 115 | +- (BOOL)bridgelessEnabled |
| 116 | +{ |
| 117 | + return [RCTSharedApplication().delegate performSelector:@selector(bridgelessEnabled)]; |
| 118 | +} |
| 119 | + |
| 120 | +@end |
0 commit comments