-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app, expo): Update AppDelegate config plugin for Expo SDK 44 (#5940)
* Fix regex in AppDelegate & add fallback * Update tests * Minor regex fix * Apply suggestion Co-authored-by: Mike Hardy <[email protected]>
- Loading branch information
Showing
6 changed files
with
334 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
2 changes: 1 addition & 1 deletion
2
packages/app/plugin/__tests__/fixtures/AppDelegate_bare_sdk43.m
This file contains 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
46 changes: 46 additions & 0 deletions
46
packages/app/plugin/__tests__/fixtures/AppDelegate_fallback.m
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// This AppDelegate template is modified to have RCTBridge | ||
// created in some non-standard way or not created at all. | ||
// This should trigger the fallback regex in iOS AppDelegate Expo plugin. | ||
|
||
// some parts omitted to be short | ||
|
||
#import "AppDelegate.h" | ||
|
||
#import <React/RCTBridge.h> | ||
#import <React/RCTBundleURLProvider.h> | ||
#import <React/RCTRootView.h> | ||
#import <React/RCTLinkingManager.h> | ||
#import <React/RCTConvert.h> | ||
|
||
@implementation AppDelegate | ||
|
||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | ||
{ | ||
|
||
// The generated code should appear above ^^^ | ||
#if defined(FB_SONARKIT_ENABLED) && __has_include(<FlipperKit/FlipperClient.h>) | ||
InitializeFlipper(application); | ||
#endif | ||
|
||
// the line below is malfolmed not to be matched by the Expo plugin regex | ||
// RCTBridge* briddge = [RCTBridge new]; | ||
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:briddge moduleName:@"main" initialProperties:nil]; | ||
id rootViewBackgroundColor = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTRootViewBackgroundColor"]; | ||
if (rootViewBackgroundColor != nil) { | ||
rootView.backgroundColor = [RCTConvert UIColor:rootViewBackgroundColor]; | ||
} else { | ||
rootView.backgroundColor = [UIColor whiteColor]; | ||
} | ||
|
||
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | ||
UIViewController *rootViewController = [UIViewController new]; | ||
rootViewController.view = rootView; | ||
self.window.rootViewController = rootViewController; | ||
[self.window makeKeyAndVisible]; | ||
|
||
[super application:application didFinishLaunchingWithOptions:launchOptions]; | ||
|
||
return YES; | ||
} | ||
|
||
@end |
79 changes: 79 additions & 0 deletions
79
packages/app/plugin/__tests__/fixtures/AppDelegate_sdk44.m
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// This AppDelegate prebuild template is used in Expo SDK 44+ | ||
// It has the RCTBridge to be created by Expo ReactDelegate | ||
|
||
#import "AppDelegate.h" | ||
|
||
#import <React/RCTBridge.h> | ||
#import <React/RCTBundleURLProvider.h> | ||
#import <React/RCTRootView.h> | ||
#import <React/RCTLinkingManager.h> | ||
#import <React/RCTConvert.h> | ||
|
||
#if defined(FB_SONARKIT_ENABLED) && __has_include(<FlipperKit/FlipperClient.h>) | ||
#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]; | ||
} | ||
#endif | ||
|
||
@implementation AppDelegate | ||
|
||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | ||
{ | ||
#if defined(FB_SONARKIT_ENABLED) && __has_include(<FlipperKit/FlipperClient.h>) | ||
InitializeFlipper(application); | ||
#endif | ||
|
||
RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions]; | ||
RCTRootView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"main" initialProperties:nil]; | ||
rootView.backgroundColor = [UIColor whiteColor]; | ||
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | ||
UIViewController *rootViewController = [self.reactDelegate createRootViewController]; | ||
rootViewController.view = rootView; | ||
self.window.rootViewController = rootViewController; | ||
[self.window makeKeyAndVisible]; | ||
|
||
[super application:application didFinishLaunchingWithOptions:launchOptions]; | ||
|
||
return YES; | ||
} | ||
|
||
- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge | ||
{ | ||
// If you'd like to export some custom RCTBridgeModules, add them here! | ||
return @[]; | ||
} | ||
|
||
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { | ||
#ifdef DEBUG | ||
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; | ||
#else | ||
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; | ||
#endif | ||
} | ||
|
||
// Linking API | ||
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { | ||
return [RCTLinkingManager application:application openURL:url options:options]; | ||
} | ||
|
||
// Universal Links | ||
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler { | ||
return [RCTLinkingManager application:application | ||
continueUserActivity:userActivity | ||
restorationHandler:restorationHandler]; | ||
} | ||
|
||
@end |
This file contains 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
This file contains 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