Created
September 24, 2022 09:42
-
-
Save stigi/e38491dff292268f790d360c3d96b0bb to your computer and use it in GitHub Desktop.
React Native upgrade diff for AppDelegate between 0.67.4 and 0.69.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- AppDelegate.m 2022-09-24 11:31:14.000000000 +0200 | |
+++ AppDelegate.mm 2022-09-24 11:29:53.000000000 +0200 | |
@@ -4,42 +4,52 @@ | |
#import <React/RCTBundleURLProvider.h> | |
#import <React/RCTRootView.h> | |
-#ifdef FB_SONARKIT_ENABLED | |
-#import <FlipperKit/FlipperClient.h> | |
-#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h> | |
-#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h> | |
-#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h> | |
-#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h> | |
-#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h> | |
- | |
-static void InitializeFlipper(UIApplication *application) { | |
- FlipperClient *client = [FlipperClient sharedClient]; | |
- SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; | |
- [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]]; | |
- [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; | |
- [client addPlugin:[FlipperKitReactPlugin new]]; | |
- [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; | |
- [client start]; | |
+#import <React/RCTAppSetupUtils.h> | |
+ | |
+#if RCT_NEW_ARCH_ENABLED | |
+#import <React/CoreModulesPlugins.h> | |
+#import <React/RCTCxxBridgeDelegate.h> | |
+#import <React/RCTFabricSurfaceHostingProxyRootView.h> | |
+#import <React/RCTSurfacePresenter.h> | |
+#import <React/RCTSurfacePresenterBridgeAdapter.h> | |
+#import <ReactCommon/RCTTurboModuleManager.h> | |
+ | |
+#import <react/config/ReactNativeConfig.h> | |
+ | |
+static NSString *const kRNConcurrentRoot = @"concurrentRoot"; | |
+ | |
+@interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate> { | |
+ RCTTurboModuleManager *_turboModuleManager; | |
+ RCTSurfacePresenterBridgeAdapter *_bridgeAdapter; | |
+ std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig; | |
+ facebook::react::ContextContainer::Shared _contextContainer; | |
} | |
+@end | |
#endif | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
-#ifdef FB_SONARKIT_ENABLED | |
- InitializeFlipper(application); | |
-#endif | |
+ RCTAppSetupPrepareApp(application); | |
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; | |
- RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge | |
- moduleName:@"RnDiffApp" | |
- initialProperties:nil]; | |
+ | |
+#if RCT_NEW_ARCH_ENABLED | |
+ _contextContainer = std::make_shared<facebook::react::ContextContainer const>(); | |
+ _reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>(); | |
+ _contextContainer->insert("ReactNativeConfig", _reactNativeConfig); | |
+ _bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer]; | |
+ bridge.surfacePresenter = _bridgeAdapter.surfacePresenter; | |
+#endif | |
+ | |
+ NSDictionary *initProps = [self prepareInitialProps]; | |
+ UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"RnDiffApp", initProps); | |
if (@available(iOS 13.0, *)) { | |
- rootView.backgroundColor = [UIColor systemBackgroundColor]; | |
+ rootView.backgroundColor = [UIColor systemBackgroundColor]; | |
} else { | |
- rootView.backgroundColor = [UIColor whiteColor]; | |
+ rootView.backgroundColor = [UIColor whiteColor]; | |
} | |
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | |
@@ -50,13 +60,74 @@ | |
return YES; | |
} | |
+/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off. | |
+/// | |
+/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html | |
+/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture). | |
+/// @return: `true` if the `concurrentRoot` feture is enabled. Otherwise, it returns `false`. | |
+- (BOOL)concurrentRootEnabled | |
+{ | |
+ // Switch this bool to turn on and off the concurrent root | |
+ return true; | |
+} | |
+ | |
+- (NSDictionary *)prepareInitialProps | |
+{ | |
+ NSMutableDictionary *initProps = [NSMutableDictionary new]; | |
+ | |
+#ifdef RCT_NEW_ARCH_ENABLED | |
+ initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]); | |
+#endif | |
+ | |
+ return initProps; | |
+} | |
+ | |
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge | |
{ | |
#if DEBUG | |
- return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; | |
+ return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; | |
#else | |
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; | |
-#endf | |
+#endif | |
+} | |
+ | |
+#if RCT_NEW_ARCH_ENABLED | |
+ | |
+#pragma mark - RCTCxxBridgeDelegate | |
+ | |
+- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge | |
+{ | |
+ _turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge | |
+ delegate:self | |
+ jsInvoker:bridge.jsCallInvoker]; | |
+ return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager); | |
+} | |
+ | |
+#pragma mark RCTTurboModuleManagerDelegate | |
+ | |
+- (Class)getModuleClassFromName:(const char *)name | |
+{ | |
+ return RCTCoreModulesClassProvider(name); | |
+} | |
+ | |
+- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name | |
+ jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker | |
+{ | |
+ return nullptr; | |
} | |
+- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name | |
+ initParams: | |
+ (const facebook::react::ObjCTurboModule::InitParams &)params | |
+{ | |
+ return nullptr; | |
+} | |
+ | |
+- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass | |
+{ | |
+ return RCTAppSetupDefaultModuleFromClass(moduleClass); | |
+} | |
+ | |
+#endif | |
+ | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment