Skip to content

Commit 6824e47

Browse files
committed
Re-integrate Expo with our native code
1 parent 92828b6 commit 6824e47

File tree

7 files changed

+51
-27
lines changed

7 files changed

+51
-27
lines changed

android/app/src/main/java/co/edgesecure/app/MainActivity.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.facebook.react.ReactActivityDelegate
88
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
99
import com.facebook.react.defaults.DefaultReactActivityDelegate
1010
import com.zoontek.rnbootsplash.RNBootSplash
11+
import expo.modules.ReactActivityDelegateWrapper
1112

1213
class MainActivity : ReactActivity() {
1314
/**
@@ -21,7 +22,11 @@ class MainActivity : ReactActivity() {
2122
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
2223
*/
2324
override fun createReactActivityDelegate(): ReactActivityDelegate =
24-
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
25+
ReactActivityDelegateWrapper(
26+
this,
27+
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED,
28+
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
29+
)
2530

2631
// Edge addition
2732
override fun onCreate(savedInstanceState: Bundle?) {

android/app/src/main/java/co/edgesecure/app/MainApplication.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ import com.facebook.react.ReactHost
88
import com.facebook.react.ReactNativeHost
99
import com.facebook.react.ReactPackage
1010
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
11-
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
1211
import com.facebook.react.defaults.DefaultReactNativeHost
1312
import com.facebook.react.modules.i18nmanager.I18nUtil
1413
import com.facebook.react.soloader.OpenSourceMergedSoMapping
1514
import com.facebook.soloader.SoLoader
16-
import expo.modules.ApplicationLifecycleDispatcher.onApplicationCreate
17-
import expo.modules.ApplicationLifecycleDispatcher.onConfigurationChanged
15+
import expo.modules.ApplicationLifecycleDispatcher
1816
import expo.modules.ReactNativeHostWrapper
1917
import io.sentry.Hint
2018
import io.sentry.SentryEvent
@@ -24,12 +22,10 @@ import io.sentry.SentryOptions.BeforeSendCallback
2422
import io.sentry.android.core.SentryAndroid
2523

2624
class MainApplication : Application(), ReactApplication {
27-
2825
override val reactNativeHost: ReactNativeHost =
2926
ReactNativeHostWrapper(
3027
this,
3128
object : DefaultReactNativeHost(this) {
32-
3329
override fun getPackages(): List<ReactPackage> {
3430
// Packages that cannot be autolinked yet can be added manually here, for
3531
// example:
@@ -47,7 +43,7 @@ class MainApplication : Application(), ReactApplication {
4743
)
4844

4945
override val reactHost: ReactHost
50-
get() = getDefaultReactHost(applicationContext, reactNativeHost)
46+
get() = ReactNativeHostWrapper.createReactHost(applicationContext, reactNativeHost)
5147

5248
override fun onCreate() {
5349
super.onCreate()
@@ -101,17 +97,23 @@ class MainApplication : Application(), ReactApplication {
10197
// Background task:
10298
MessagesWorker.ensureScheduled(context)
10399
// MessagesWorker.testRun(context);
100+
101+
// React Native template code:
104102
SoLoader.init(this, OpenSourceMergedSoMapping)
105103
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
106104
// If you opted-in for the New Architecture, we load the native entry point for this
107105
// app.
108106
load()
109107
}
110-
onApplicationCreate(this)
108+
109+
// Expo integration:
110+
ApplicationLifecycleDispatcher.onApplicationCreate(this)
111111
}
112112

113113
override fun onConfigurationChanged(newConfig: Configuration) {
114114
super.onConfigurationChanged(newConfig)
115-
onConfigurationChanged(this, newConfig)
115+
116+
// Expo integration:
117+
ApplicationLifecycleDispatcher.onConfigurationChanged(this, newConfig)
116118
}
117119
}

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ buildscript {
2929
}
3030

3131
apply plugin: "com.facebook.react.rootproject"
32+
apply plugin: "expo-root-project"

android/settings.gradle

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") }
2-
plugins { id("com.facebook.react.settings") }
3-
extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() }
1+
// Expo integration:
2+
pluginManagement {
3+
includeBuild("../node_modules/@react-native/gradle-plugin")
4+
includeBuild("../node_modules/expo-modules-autolinking/android/expo-gradle-plugin")
5+
}
6+
plugins {
7+
id("com.facebook.react.settings")
8+
id("expo-autolinking-settings")
9+
}
10+
extensions.configure(com.facebook.react.ReactSettingsExtension) {
11+
ex -> ex.autolinkLibrariesFromCommand(expoAutolinking.rnConfigCommand)
12+
}
13+
14+
// React template code:
415
rootProject.name = 'co.edgesecure.app'
516
include ':app'
617
includeBuild('../node_modules/@react-native/gradle-plugin')
718

8-
apply from: new File(["node", "--print", "require.resolve('expo/package.json')"].execute(null, rootDir).text.trim(), "../scripts/autolinking.gradle")
9-
useExpoModules()
19+
// Expo integration:
20+
expoAutolinking.useExpoModules()
21+
expoAutolinking.useExpoVersionCatalog()
22+
includeBuild(expoAutolinking.reactNativeGradlePlugin)

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
presets: ['module:@react-native/babel-preset'],
2+
presets: ['babel-preset-expo'],
33
plugins: ['react-native-reanimated/plugin']
44
}

ios/edge/AppDelegate.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Expo
12
import Firebase
23
import FirebaseMessaging
34
import RNBootSplash
@@ -8,7 +9,7 @@ import UIKit
89
import UserNotifications
910

1011
@main
11-
class AppDelegate: UIResponder, UIApplicationDelegate {
12+
class AppDelegate: ExpoAppDelegate {
1213
var window: UIWindow?
1314
var securityView: UIView?
1415

@@ -19,7 +20,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1920
* Handles deep links.
2021
* From https://reactnative.dev/docs/0.79/linking?ios-language=swift#enabling-deep-links
2122
*/
22-
func application(
23+
override func application(
2324
_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]
2425
) -> Bool {
2526
return RCTLinkingManager.application(app, open: url, options: options)
@@ -29,7 +30,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2930
* Handles deep links.
3031
* From https://reactnative.dev/docs/0.79/linking?ios-language=swift#enabling-deep-links
3132
*/
32-
func application(
33+
override func application(
3334
_ application: UIApplication,
3435
continue userActivity: NSUserActivity,
3536
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
@@ -45,7 +46,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4546
* Handles app start-up.
4647
* React Native template code.
4748
*/
48-
func application(
49+
override func application(
4950
_ application: UIApplication,
5051
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
5152
) -> Bool {
@@ -58,11 +59,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5859

5960
// React Native template code:
6061
let delegate = ReactNativeDelegate()
61-
let factory = RCTReactNativeFactory(delegate: delegate)
62+
let factory = ExpoReactNativeFactory(delegate: delegate)
6263
delegate.dependencyProvider = RCTAppDependencyProvider()
6364

6465
reactNativeDelegate = delegate
6566
reactNativeFactory = factory
67+
bindReactNativeFactory(factory)
6668

6769
window = UIWindow(frame: UIScreen.main.bounds)
6870

@@ -72,14 +74,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
7274
launchOptions: launchOptions
7375
)
7476

75-
return true
77+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
7678
}
7779

7880
/**
7981
* Periodic background fetch logic.
8082
* Edge addition.
8183
*/
82-
func application(
84+
override func application(
8385
_ application: UIApplication,
8486
performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
8587
) {
@@ -128,7 +130,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
128130
* Hides the app when we go into the background.
129131
* Edge addition.
130132
*/
131-
func applicationDidEnterBackground(_ application: UIApplication) {
133+
override func applicationDidEnterBackground(_ application: UIApplication) {
132134
guard
133135
let storyboard = UIStoryboard(name: "LaunchScreen", bundle: nil) as UIStoryboard?,
134136
let launchScreen = storyboard.instantiateInitialViewController(),
@@ -148,7 +150,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
148150
* Shows the app when we come into the foreground.
149151
* Edge addition.
150152
*/
151-
func applicationWillEnterForeground(_ application: UIApplication) {
153+
override func applicationWillEnterForeground(_ application: UIApplication) {
152154
if let view = securityView {
153155
view.removeFromSuperview()
154156
securityView = nil
@@ -158,13 +160,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
158160

159161
/// Configures the React Native instance.
160162
/// React Native template code.
161-
class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate {
163+
class ReactNativeDelegate: ExpoReactNativeFactoryDelegate {
162164
override func sourceURL(for bridge: RCTBridge) -> URL? {
163165
self.bundleURL()
164166
}
165167

166168
// react-native-bootsplash integration:
167-
override func customize(_ rootView: RCTRootView) {
169+
override func customize(_ rootView: UIView) {
168170
super.customize(rootView)
169171
RNBootSplash.initWithStoryboard("LaunchScreen", rootView: rootView)
170172
}

metro.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config')
1+
const { getDefaultConfig } = require('expo/metro-config')
2+
const { mergeConfig } = require('@react-native/metro-config')
23
const {
34
wrapWithReanimatedMetroConfig
45
} = require('react-native-reanimated/metro-config')

0 commit comments

Comments
 (0)