Skip to content

Commit bc512c9

Browse files
committed
feat: support new arch in expo projects
1 parent e91fd34 commit bc512c9

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

android/app/src/main/java/com/appzung/codepush/react/CodePush.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public static String getJSBundleFile() {
203203

204204
public static String getJSBundleFile(String assetsBundleFileName) {
205205
if (mCurrentInstance == null) {
206+
CodePushUtils.log("A CodePush instance has not been created yet. Have you added it to your app's list of ReactPackages?");
206207
throw new CodePushNotInitializedException("A CodePush instance has not been created yet. Have you added it to your app's list of ReactPackages?");
207208
}
208209

android/app/src/main/java/com/appzung/codepush/react/CodePushNativeModule.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class CodePushNativeModule extends BaseJavaModule {
5151
private String mClientUniqueId = null;
5252
private boolean mTelemetryEnabled = true;
5353
private boolean mDataTransmissionEnabled = true;
54+
private boolean mIsExpoApp = false;
5455
private LifecycleEventListener mLifecycleEventListener = null;
5556
private int mMinimumBackgroundDuration = 0;
5657

@@ -71,6 +72,8 @@ public CodePushNativeModule(ReactApplicationContext reactContext, CodePush codeP
7172
mTelemetryManager = codePushTelemetryManager;
7273
mUpdateManager = codePushUpdateManager;
7374

75+
mIsExpoApp = ExpoUtils.detectExpoEnvironment(reactContext);
76+
7477
// Initialize module state while we have a reference to the current context.
7578
mBinaryContentsHash = CodePushUpdateUtils.getHashForBinaryContents(reactContext, mCodePush.isDebugMode());
7679

@@ -210,8 +213,11 @@ private void loadBundle() {
210213

211214
String latestJSBundleFile = mCodePush.getJSBundleFileInternal(mCodePush.getAssetsBundleFileName());
212215

213-
// #2) Update the locally stored JS bundle file path
214-
setJSBundle(getReactHostDelegate((ReactHostImpl) reactHost), latestJSBundleFile);
216+
// if expo and new arch this is unnecessary, see https://github.com/expo/expo/blob/8113ce44edaef0311e2daff3ab1a63b9731d2d6c/packages/expo-updates/android/src/main/java/expo/modules/updates/procedures/RelaunchProcedure.kt#L148
217+
if (!mIsExpoApp) {
218+
// #2) Update the locally stored JS bundle file path
219+
setJSBundle(getReactHostDelegate((ReactHostImpl) reactHost), latestJSBundleFile);
220+
}
215221

216222
// #3) Get the context creation method
217223
try {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.appzung.codepush.react;
2+
3+
import com.facebook.react.bridge.ReactApplicationContext;
4+
5+
public class ExpoUtils {
6+
7+
/**
8+
* Detects if the app is running in an Expo environment by checking for
9+
* the presence of Expo's ReactNativeHostWrapper class.
10+
*
11+
* @param reactContext The React application context
12+
* @return true if Expo environment is detected, false otherwise
13+
*/
14+
public static boolean detectExpoEnvironment(ReactApplicationContext reactContext) {
15+
try {
16+
Class.forName("expo.modules.ReactNativeHostWrapper");
17+
return true;
18+
} catch (ClassNotFoundException e) {
19+
return false;
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)