Skip to content

Commit 0d39eba

Browse files
authored
Merge pull request #1 from revopush/revopush-1
Revopush RNCP with new arch support
2 parents 6015386 + 8208885 commit 0d39eba

File tree

128 files changed

+712
-17385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+712
-17385
lines changed

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20.18.2

CodePush.podspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ Pod::Spec.new do |s|
99
s.author = package['author']
1010
s.license = package['license']
1111
s.homepage = package['homepage']
12-
s.source = { :git => 'https://github.com/microsoft/react-native-code-push.git', :tag => "v#{s.version}"}
12+
s.source = { :git => 'https://github.com/revopush/react-native-code-push.git', :tag => "v#{s.version}"}
1313
s.ios.deployment_target = '15.5'
1414
s.tvos.deployment_target = '15.5'
1515
s.preserve_paths = '*.js'
1616
s.library = 'z'
1717
s.source_files = 'ios/CodePush/*.{h,m}'
1818
s.public_header_files = ['ios/CodePush/CodePush.h']
19+
s.pod_target_xcconfig = { "DEFINES_MODULE" => "YES" }
1920

20-
# Note: Even though there are copy/pasted versions of some of these dependencies in the repo,
21-
# we explicitly let CocoaPods pull in the versions below so all dependencies are resolved and
21+
# Note: Even though there are copy/pasted versions of some of these dependencies in the repo,
22+
# we explicitly let CocoaPods pull in the versions below so all dependencies are resolved and
2223
# linked properly at a parent workspace level.
2324
s.dependency 'React-Core'
2425
s.dependency 'SSZipArchive', '~> 2.5.5'

README.md

Lines changed: 78 additions & 119 deletions
Large diffs are not rendered by default.

android/app/build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
apply plugin: "com.android.library"
22

3+
def isNewArchitectureEnabled() {
4+
// To opt-in for the New Architecture, you can either:
5+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
6+
// - Invoke gradle with `-newArchEnabled=true`
7+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
8+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
9+
}
10+
11+
def IS_NEW_ARCHITECTURE_ENABLED = isNewArchitectureEnabled()
12+
13+
if (IS_NEW_ARCHITECTURE_ENABLED) {
14+
apply plugin: "com.facebook.react"
15+
}
16+
317
def DEFAULT_COMPILE_SDK_VERSION = 26
418
def DEFAULT_BUILD_TOOLS_VERSION = "26.0.3"
519
def DEFAULT_TARGET_SDK_VERSION = 26
@@ -16,6 +30,7 @@ android {
1630
targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
1731
versionCode 1
1832
versionName "1.0"
33+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", IS_NEW_ARCHITECTURE_ENABLED.toString()
1934
}
2035

2136
lintOptions {

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

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
import android.content.pm.PackageManager;
66
import android.content.res.Resources;
77

8+
import com.facebook.react.ReactHost;
89
import com.facebook.react.ReactInstanceManager;
910
import com.facebook.react.ReactPackage;
1011
import com.facebook.react.bridge.JavaScriptModule;
1112
import com.facebook.react.bridge.NativeModule;
1213
import com.facebook.react.bridge.ReactApplicationContext;
13-
import com.facebook.react.devsupport.interfaces.DevSupportManager;
14-
import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
1514
import com.facebook.react.uimanager.ViewManager;
1615

1716
import org.json.JSONException;
@@ -20,9 +19,20 @@
2019
import java.io.File;
2120
import java.util.ArrayList;
2221
import java.util.List;
23-
import java.lang.reflect.Method;
2422

2523
public class CodePush implements ReactPackage {
24+
private static final Object LOCK = new Object();
25+
private static volatile CodePush mCurrentInstance;
26+
public static CodePush getInstance(String deploymentKey, Context context, boolean isDebugMode) {
27+
if (mCurrentInstance == null) {
28+
synchronized (LOCK) {
29+
if (mCurrentInstance == null) {
30+
mCurrentInstance = new CodePush(deploymentKey, context, isDebugMode);
31+
}
32+
}
33+
}
34+
return mCurrentInstance;
35+
}
2636

2737
private static boolean sIsRunningBinaryVersion = false;
2838
private static boolean sNeedToReportRollback = false;
@@ -40,15 +50,16 @@ public class CodePush implements ReactPackage {
4050

4151
// Config properties.
4252
private String mDeploymentKey;
43-
private static String mServerUrl = "https://codepush.appcenter.ms/";
53+
private static String mServerUrl = "https://api.revopush.org/";
4454

4555
private Context mContext;
4656
private final boolean mIsDebugMode;
4757

4858
private static String mPublicKey;
4959

5060
private static ReactInstanceHolder mReactInstanceHolder;
51-
private static CodePush mCurrentInstance;
61+
62+
private static ReactHostHolder mReactHostHolder;
5263

5364
public CodePush(String deploymentKey, Context context) {
5465
this(deploymentKey, context, false);
@@ -58,7 +69,7 @@ public static String getServiceUrl() {
5869
return mServerUrl;
5970
}
6071

61-
public CodePush(String deploymentKey, Context context, boolean isDebugMode) {
72+
private CodePush(String deploymentKey, Context context, boolean isDebugMode) {
6273
mContext = context.getApplicationContext();
6374

6475
mUpdateManager = new CodePushUpdateManager(context.getFilesDir().getAbsolutePath());
@@ -84,22 +95,23 @@ public CodePush(String deploymentKey, Context context, boolean isDebugMode) {
8495
String serverUrlFromStrings = getCustomPropertyFromStringsIfExist("ServerUrl");
8596
if (serverUrlFromStrings != null) mServerUrl = serverUrlFromStrings;
8697

87-
clearDebugCacheIfNeeded(null);
98+
// ignore liveReload when CodePush is initializing so that unneccessary cache could be cleared
99+
clearDebugCacheIfNeeded(false);
88100
initializeUpdateAfterRestart();
89101
}
90102

91-
public CodePush(String deploymentKey, Context context, boolean isDebugMode, String serverUrl) {
103+
private CodePush(String deploymentKey, Context context, boolean isDebugMode, String serverUrl) {
92104
this(deploymentKey, context, isDebugMode);
93105
mServerUrl = serverUrl;
94106
}
95107

96-
public CodePush(String deploymentKey, Context context, boolean isDebugMode, int publicKeyResourceDescriptor) {
108+
private CodePush(String deploymentKey, Context context, boolean isDebugMode, int publicKeyResourceDescriptor) {
97109
this(deploymentKey, context, isDebugMode);
98110

99111
mPublicKey = getPublicKeyByResourceDescriptor(publicKeyResourceDescriptor);
100112
}
101113

102-
public CodePush(String deploymentKey, Context context, boolean isDebugMode, String serverUrl, Integer publicKeyResourceDescriptor) {
114+
private CodePush(String deploymentKey, Context context, boolean isDebugMode, String serverUrl, Integer publicKeyResourceDescriptor) {
103115
this(deploymentKey, context, isDebugMode);
104116

105117
if (publicKeyResourceDescriptor != null) {
@@ -129,48 +141,27 @@ private String getPublicKeyByResourceDescriptor(int publicKeyResourceDescriptor)
129141

130142
private String getCustomPropertyFromStringsIfExist(String propertyName) {
131143
String property;
132-
144+
133145
String packageName = mContext.getPackageName();
134146
int resId = mContext.getResources().getIdentifier("CodePush" + propertyName, "string", packageName);
135-
147+
136148
if (resId != 0) {
137149
property = mContext.getString(resId);
138150

139151
if (!property.isEmpty()) {
140152
return property;
141153
} else {
142154
CodePushUtils.log("Specified " + propertyName + " is empty");
143-
}
155+
}
144156
}
145157

146158
return null;
147159
}
148160

149-
private boolean isLiveReloadEnabled(ReactInstanceManager instanceManager) {
150-
// Use instanceManager for checking if we use LiveReload mode. In this case we should not remove ReactNativeDevBundle.js file
161+
public void clearDebugCacheIfNeeded(boolean isLiveReloadEnabled) {
162+
// for checking if we use LiveReload mode. In this case we should not remove ReactNativeDevBundle.js file
151163
// because we get error with trying to get this after reloading. Issue: https://github.com/microsoft/react-native-code-push/issues/1272
152-
if (instanceManager != null) {
153-
DevSupportManager devSupportManager = instanceManager.getDevSupportManager();
154-
if (devSupportManager != null) {
155-
DeveloperSettings devSettings = devSupportManager.getDevSettings();
156-
Method[] methods = devSettings.getClass().getMethods();
157-
for (Method m : methods) {
158-
if (m.getName().equals("isReloadOnJSChangeEnabled")) {
159-
try {
160-
return (boolean) m.invoke(devSettings);
161-
} catch (Exception x) {
162-
return false;
163-
}
164-
}
165-
}
166-
}
167-
}
168-
169-
return false;
170-
}
171-
172-
public void clearDebugCacheIfNeeded(ReactInstanceManager instanceManager) {
173-
if (mIsDebugMode && mSettingsManager.isPendingUpdate(null) && !isLiveReloadEnabled(instanceManager)) {
164+
if (mIsDebugMode && mSettingsManager.isPendingUpdate(null) && !isLiveReloadEnabled) {
174165
// This needs to be kept in sync with https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java#L78
175166
File cachedDevBundle = new File(mContext.getFilesDir(), "ReactNativeDevBundle.js");
176167
if (cachedDevBundle.exists()) {
@@ -411,13 +402,25 @@ public static void setReactInstanceHolder(ReactInstanceHolder reactInstanceHolde
411402
mReactInstanceHolder = reactInstanceHolder;
412403
}
413404

405+
public static void setReactHost(ReactHostHolder reactHostHolder) {
406+
mReactHostHolder = reactHostHolder;
407+
}
408+
414409
static ReactInstanceManager getReactInstanceManager() {
415410
if (mReactInstanceHolder == null) {
416411
return null;
417412
}
418413
return mReactInstanceHolder.getReactInstanceManager();
419414
}
420415

416+
static ReactHost getReactHost() {
417+
if (mReactHostHolder == null) {
418+
return null;
419+
}
420+
421+
return mReactHostHolder.getReactHost();
422+
}
423+
421424
@Override
422425
public List<NativeModule> createNativeModules(ReactApplicationContext reactApplicationContext) {
423426
CodePushNativeModule codePushModule = new CodePushNativeModule(reactApplicationContext, this, mUpdateManager, mTelemetryManager, mSettingsManager);

android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import android.app.AlertDialog;
55
import android.content.DialogInterface;
66

7+
import com.facebook.react.bridge.BaseJavaModule;
78
import com.facebook.react.bridge.Callback;
89
import com.facebook.react.bridge.LifecycleEventListener;
910
import com.facebook.react.bridge.ReactApplicationContext;
10-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
1111
import com.facebook.react.bridge.ReactMethod;
1212

13-
public class CodePushDialog extends ReactContextBaseJavaModule{
13+
public class CodePushDialog extends BaseJavaModule {
1414

1515
public CodePushDialog(ReactApplicationContext reactContext) {
1616
super(reactContext);
@@ -19,14 +19,14 @@ public CodePushDialog(ReactApplicationContext reactContext) {
1919
@ReactMethod
2020
public void showDialog(final String title, final String message, final String button1Text,
2121
final String button2Text, final Callback successCallback, Callback errorCallback) {
22-
Activity currentActivity = getCurrentActivity();
22+
Activity currentActivity = getReactApplicationContext().getCurrentActivity();
2323
if (currentActivity == null || currentActivity.isFinishing()) {
2424
// If getCurrentActivity is null, it could be because the app is backgrounded,
2525
// so we show the dialog when the app resumes)
2626
getReactApplicationContext().addLifecycleEventListener(new LifecycleEventListener() {
2727
@Override
2828
public void onHostResume() {
29-
Activity currentActivity = getCurrentActivity();
29+
Activity currentActivity = getReactApplicationContext().getCurrentActivity();
3030
if (currentActivity != null) {
3131
getReactApplicationContext().removeLifecycleEventListener(this);
3232
showDialogInternal(title, message, button1Text, button2Text, successCallback, currentActivity);

0 commit comments

Comments
 (0)