Skip to content

Commit c4f425d

Browse files
authored
feat: add support for @expo/config-plugins (#1033)
1 parent 98b4eee commit c4f425d

21 files changed

+530
-66
lines changed

example/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function useStyles() {
7070
groupItemContainer: {
7171
alignItems: "center",
7272
flexDirection: "row",
73-
marginHorizontal: margin,
73+
paddingHorizontal: margin,
7474
},
7575
groupItemLabel: {
7676
color: isDarkMode ? Colors.white : Colors.black,

ios/ReactTestApp/AppDelegate.swift

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313
}
1414

1515
func application(_ application: UIApplication,
16-
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
16+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
1717
{
1818
self.application = application
1919

@@ -24,21 +24,50 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2424
)
2525
}
2626

27+
// application(_:didFinishLaunchingWithOptions:)
28+
2729
return true
2830
}
2931

30-
// MARK: UISceneSession Lifecycle
32+
func applicationWillTerminate(_ application: UIApplication) {
33+
// applicationWillTerminate(_:)
34+
}
35+
36+
// MARK: Push Notifications
37+
38+
func application(_ application: UIApplication,
39+
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
40+
{
41+
// application(_:didRegisterForRemoteNotificationsWithDeviceToken:)
42+
}
3143

32-
func application(_: UIApplication,
44+
func application(_ application: UIApplication,
45+
didFailToRegisterForRemoteNotificationsWithError error: Error)
46+
{
47+
// application(_:didFailToRegisterForRemoteNotificationsWithError:)
48+
}
49+
50+
func application(_ application: UIApplication,
51+
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
52+
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
53+
{
54+
// application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
55+
}
56+
57+
// MARK: UISceneSession Support
58+
59+
func application(_ application: UIApplication,
3360
configurationForConnecting connectingSceneSession: UISceneSession,
34-
options _: UIScene.ConnectionOptions) -> UISceneConfiguration
61+
options: UIScene.ConnectionOptions) -> UISceneConfiguration
3562
{
3663
// Called when a new scene session is being created.
3764
// Use this method to select a configuration to create the new scene with.
3865
UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
3966
}
4067

41-
func application(_: UIApplication, didDiscardSceneSessions _: Set<UISceneSession>) {
68+
func application(_ application: UIApplication,
69+
didDiscardSceneSessions sceneSessions: Set<UISceneSession>)
70+
{
4271
// Called when the user discards a scene session.
4372
// If any sessions were discarded while the application was not running, this will be called shortly after
4473
// application:didFinishLaunchingWithOptions.

ios/ReactTestApp/Public/ReactTestApp-DevSupport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
NS_ASSUME_NONNULL_BEGIN
44

55
extern NSNotificationName const ReactTestAppDidInitializeNotification;
6+
67
extern NSNotificationName const ReactTestAppWillInitializeReactNativeNotification;
78
extern NSNotificationName const ReactTestAppDidInitializeReactNativeNotification;
89
extern NSNotificationName const ReactTestAppDidRegisterAppsNotification;
10+
911
extern NSNotificationName const ReactTestAppSceneDidOpenURLNotification;
1012

1113
NS_ASSUME_NONNULL_END

ios/ReactTestApp/ReactTestApp-DevSupport.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
NSNotificationName const ReactTestAppDidInitializeNotification =
44
@"ReactTestAppDidInitializeNotification";
5+
56
NSNotificationName const ReactTestAppWillInitializeReactNativeNotification =
67
@"ReactTestAppWillInitializeReactNativeNotification";
78
NSNotificationName const ReactTestAppDidInitializeReactNativeNotification =
89
@"ReactTestAppDidInitializeReactNativeNotification";
910
NSNotificationName const ReactTestAppDidRegisterAppsNotification =
1011
@"ReactTestAppDidRegisterAppsNotification";
12+
1113
NSNotificationName const ReactTestAppSceneDidOpenURLNotification =
1214
@"ReactTestAppSceneDidOpenURLNotification";

ios/ReactTestApp/SceneDelegate.swift

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,38 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
66

77
private lazy var reactInstance = ReactInstance()
88

9-
func sceneDidDisconnect(_: UIScene) {
9+
func sceneDidDisconnect(_ scene: UIScene) {
1010
// Called as the scene is being released by the system.
1111
// This occurs shortly after the scene enters the background, or when its session is discarded.
1212
// Release any resources associated with this scene that can be re-created the next time the scene connects.
1313
// The scene may re-connect later, as its session was not neccessarily discarded (see
1414
// `application:didDiscardSceneSessions` instead).
15+
// sceneDidDisconnect(_:)
1516
}
1617

17-
func sceneDidBecomeActive(_: UIScene) {
18+
func sceneDidBecomeActive(_ scene: UIScene) {
1819
// Called when the scene has moved from an inactive state to an active state.
1920
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
21+
// sceneDidBecomeActive(_:)
2022
}
2123

22-
func sceneWillResignActive(_: UIScene) {
24+
func sceneWillResignActive(_ scene: UIScene) {
2325
// Called when the scene will move from an active state to an inactive state.
2426
// This may occur due to temporary interruptions (ex. an incoming phone call).
27+
// sceneWillResignActive(_:)
2528
}
2629

27-
func sceneWillEnterForeground(_: UIScene) {
30+
func sceneWillEnterForeground(_ scene: UIScene) {
2831
// Called as the scene transitions from the background to the foreground.
2932
// Use this method to undo the changes made on entering the background.
33+
// sceneWillEnterForeground(_:)
3034
}
3135

32-
func sceneDidEnterBackground(_: UIScene) {
36+
func sceneDidEnterBackground(_ scene: UIScene) {
3337
// Called as the scene transitions from the foreground to the background.
3438
// Use this method to save data, release shared resources, and store enough scene-specific state information
3539
// to restore the scene back to its current state.
40+
// sceneDidEnterBackground(_:)
3641
}
3742

3843
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
@@ -51,6 +56,12 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
5156
"URLContexts": URLContexts,
5257
]
5358
)
59+
60+
// scene(_:openURLContexts:)
61+
}
62+
63+
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
64+
// scene(_:continue:)
5465
}
5566
}
5667

@@ -65,8 +76,8 @@ extension SceneDelegate {
6576
}
6677

6778
func scene(_ scene: UIScene,
68-
willConnectTo _: UISceneSession,
69-
options _: UIScene.ConnectionOptions)
79+
willConnectTo session: UISceneSession,
80+
options connectionOptions: UIScene.ConnectionOptions)
7081
{
7182
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene
7283
// `scene`.
@@ -86,6 +97,8 @@ extension SceneDelegate {
8697
self.window = window
8798
window.makeKeyAndVisible()
8899
}
100+
101+
// scene(_:willConnectTo:options:)
89102
}
90103
}
91104

@@ -97,8 +110,8 @@ extension SceneDelegate {
97110

98111
extension SceneDelegate {
99112
func scene(_ scene: UIScene,
100-
willConnectTo _: UISceneSession,
101-
options _: UIScene.ConnectionOptions)
113+
willConnectTo session: UISceneSession,
114+
options connectionOptions: UIScene.ConnectionOptions)
102115
{
103116
guard let windowScene = scene as? UIWindowScene else {
104117
assertionFailure("Default scene configuration should have been loaded by now")
@@ -120,6 +133,8 @@ extension SceneDelegate {
120133
self.window = window
121134

122135
window.makeKeyAndVisible()
136+
137+
// scene(_:willConnectTo:options:)
123138
}
124139
}
125140

ios/test_app.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ def app_config(project_root)
2525
[manifest['name'], manifest['displayName'], manifest['version'], manifest['singleApp']]
2626
end
2727

28+
def apply_config_plugins(project_root)
29+
begin
30+
resolve_module('@expo/config-plugins')
31+
rescue StandardError
32+
# Skip if `@expo/config-plugins` cannot be found
33+
return
34+
end
35+
36+
apply_config_plugins = File.join(__dir__, '..', 'scripts', 'apply-config-plugins.mjs')
37+
result = system("node \"#{apply_config_plugins}\" \"#{project_root}\"")
38+
raise 'Failed to apply config plugins' unless result
39+
end
40+
2841
def autolink_script_path
2942
package_path = resolve_module('@react-native-community/cli-platform-ios')
3043
File.join(package_path, 'native_modules')
@@ -465,6 +478,8 @@ def use_test_app_internal!(target_platform, options)
465478
end
466479
end
467480

481+
apply_config_plugins(project_root)
482+
468483
Pod::UI.notice(
469484
"`#{xcodeproj}` was sourced from `react-native-test-app`. " \
470485
'All modifications will be overwritten next time you run `pod install`.'

macos/ReactTestApp/AppDelegate.swift

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,42 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
2020
true
2121
}
2222

23+
func applicationDidFinishLaunching(_: Notification) {
24+
NotificationCenter.default.post(
25+
name: .ReactTestAppDidInitialize,
26+
object: nil
27+
)
28+
29+
initialize()
30+
31+
// applicationDidFinishLaunching(_:)
32+
}
33+
2334
func applicationWillTerminate(_: Notification) {
24-
// Insert code here to tear down your application
35+
// applicationWillTerminate(_:)
36+
}
37+
38+
// MARK: Push Notifications
39+
40+
func application(_ application: NSApplication,
41+
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
42+
{
43+
// application(_:didRegisterForRemoteNotificationsWithDeviceToken:)
44+
}
45+
46+
func application(_ application: NSApplication,
47+
didFailToRegisterForRemoteNotificationsWithError error: Error)
48+
{
49+
// application(_:didFailToRegisterForRemoteNotificationsWithError:)
2550
}
2651

27-
// MARK: - User interaction
52+
func application(_ application: NSApplication,
53+
didReceiveRemoteNotification userInfo: [String: Any])
54+
{
55+
// application(_:didReceiveRemoteNotification:)
56+
}
57+
58+
// MARK: User interaction
2859

2960
@IBAction
3061
func onLoadEmbeddedBundleSelected(_: NSMenuItem) {
@@ -50,7 +81,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
5081
}
5182
}
5283

53-
// MARK: - Private
84+
// MARK: Private
5485

5586
private enum WindowSize {
5687
static let defaultSize = CGSize(width: 640, height: 480)
@@ -76,22 +107,7 @@ extension AppDelegate {
76107
!(mainWindow?.contentViewController is ViewController)
77108
}
78109

79-
func applicationWillFinishLaunching(_: Notification) {
80-
if Session.shouldRememberLastComponent {
81-
rememberLastComponentMenuItem.state = .on
82-
}
83-
84-
showReactMenu()
85-
}
86-
87-
func applicationDidFinishLaunching(_: Notification) {
88-
defer {
89-
NotificationCenter.default.post(
90-
name: .ReactTestAppDidInitialize,
91-
object: nil
92-
)
93-
}
94-
110+
func initialize() {
95111
guard let (manifest, checksum) = Manifest.fromFile() else {
96112
let item = reactMenu.addItem(
97113
withTitle: "Could not load 'app.json'",
@@ -149,6 +165,14 @@ extension AppDelegate {
149165
manifestChecksum = checksum
150166
}
151167

168+
func applicationWillFinishLaunching(_: Notification) {
169+
if Session.shouldRememberLastComponent {
170+
rememberLastComponentMenuItem.state = .on
171+
}
172+
173+
showReactMenu()
174+
}
175+
152176
@objc
153177
private func onComponentSelected(menuItem: NSMenuItem) {
154178
guard let component = menuItem.representedObject as? Component else {
@@ -257,6 +281,8 @@ extension AppDelegate {
257281
#if ENABLE_SINGLE_APP_MODE
258282

259283
extension AppDelegate {
284+
func initialize() {}
285+
260286
func applicationWillFinishLaunching(_: Notification) {
261287
guard let window = mainWindow else {
262288
assertionFailure("Main window should have been instantiated by now")
@@ -282,13 +308,6 @@ extension AppDelegate {
282308
showReactMenu()
283309
#endif // DEBUG
284310
}
285-
286-
func applicationDidFinishLaunching(_: Notification) {
287-
NotificationCenter.default.post(
288-
name: .ReactTestAppDidInitialize,
289-
object: nil
290-
)
291-
}
292311
}
293312

294313
#endif // ENABLE_SINGLE_APP_MODE

0 commit comments

Comments
 (0)