-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[expo-dev-launcher] take 2 at SDK 44 plugin compatibility (#15570)
Co-authored-by: Łukasz Kosmaty <lukasz.kosmaty@swmansion.com># Why when testing #15562 on the sdk-44 branch I found there were still a few issues -- (1) some expo-modules stuff would be inadvertently removed from AppDelegate, even though the project would build, and (2) tests were failing. # How (commit 1) added the correct logic for SDK 44's `initializeReactNativeApp` function (these regexes are getting so messy, we can't move to expo module initialization soon enough 😅 ), and added tests with a corresponding SDK 44 AppDelegate.m. (commit 2) fixed wrong string constant that was causing failures for SDK 43 and below (commit 3) fixed tests on the Android side that were logging warnings. @lukmccall is it correct to say that this config plugin cannot handle projects where `createReactActivityDelegate` isn't already overridden in MainActivity? I modified the tests as such, but if that isn't the case, [this warning](https://github.com/expo/expo/blob/4ca5ff72ef3abcc30cb7936eaf9c4b97fed9a5ad/packages/expo-dev-launcher/plugin/src/withDevLauncher.ts#L205-L209) needs to be changed. # Test Plan All tests pass. Manually tested in a blank SDK 44 app; cherry picked these commits onto sdk-44 and then used patch-package to patch entire the expo-dev-launcher package to match sdk-44 HEAD. Ran expo prebuild, saw no errors, eyeballed the code changes, and tested the following scenarios: ✅ project builds on iOS and Android ✅ iOS: can open app served by `expo start --dev-client` ✅ iOS: can open app served by `expo start --dev-client --force-manifest-type=expo-updates` ✅ Android: can open app served by `expo start --dev-client` ✅ Android: can open app served by `expo start --dev-client --force-manifest-type=expo-updates` ✅ expo install expo-updates@0.11.2, expo prebuild --clean, project builds ✅ iOS (with expo-updates integration): can open app served by `expo start --dev-client` ✅ iOS (with expo-updates integration): can open app served by `expo start --dev-client --force-manifest-type=expo-updates` ✅ iOS (with expo-updates integration): can open published app ✅ Android (with expo-updates integration): can open app served by `expo start --dev-client` ✅ Android (with expo-updates integration): can open app served by `expo start --dev-client --force-manifest-type=expo-updates` ✅ Android (with expo-updates integration): can open published app
- Loading branch information
Showing
9 changed files
with
263 additions
and
16 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
26 changes: 22 additions & 4 deletions
26
packages/expo-dev-launcher/plugin/build/withDevLauncherAppDelegate.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
76 changes: 76 additions & 0 deletions
76
packages/expo-dev-launcher/plugin/src/__tests__/fixtures/AppDelegate-expo-modules-sdk-44.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,76 @@ | ||
#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 |
55 changes: 55 additions & 0 deletions
55
packages/expo-dev-launcher/plugin/src/__tests__/fixtures/MainActivity-expo-modules.java
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,55 @@ | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
|
||
import com.facebook.react.ReactActivity; | ||
import com.facebook.react.ReactActivityDelegate; | ||
import com.facebook.react.ReactRootView; | ||
|
||
import expo.modules.ReactActivityDelegateWrapper; | ||
|
||
public class MainActivity extends ReactActivity { | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
// Set the theme to AppTheme BEFORE onCreate to support | ||
// coloring the background, status bar, and navigation bar. | ||
// This is required for expo-splash-screen. | ||
setTheme(R.style.AppTheme); | ||
super.onCreate(null); | ||
} | ||
|
||
/** | ||
* Returns the name of the main component registered from JavaScript. | ||
* This is used to schedule rendering of the component. | ||
*/ | ||
@Override | ||
protected String getMainComponentName() { | ||
return "main"; | ||
} | ||
|
||
@Override | ||
protected ReactActivityDelegate createReactActivityDelegate() { | ||
return new ReactActivityDelegateWrapper(this, | ||
new ReactActivityDelegate(this, getMainComponentName()) | ||
); | ||
} | ||
|
||
/** | ||
* Align the back button behavior with Android S | ||
* where moving root activities to background instead of finishing activities. | ||
* @see <a href="https://developer.android.com/reference/android/app/Activity#onBackPressed()">onBackPressed</a> | ||
*/ | ||
@Override | ||
public void invokeDefaultOnBackPressed() { | ||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) { | ||
if (!moveTaskToBack(false)) { | ||
// For non-root activities, use the default implementation to finish them. | ||
super.invokeDefaultOnBackPressed(); | ||
} | ||
return; | ||
} | ||
|
||
// Use the default back button implementation on Android S | ||
// because it's doing more than {@link Activity#moveTaskToBack} in fact. | ||
super.invokeDefaultOnBackPressed(); | ||
} | ||
} |
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
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
Oops, something went wrong.