@srcpush/react-native-code-push 1.0.3-develop.5 → 1.0.3-feat-new-arch.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AlertAdapter.js +21 -2
- package/CodePush.js +16 -1
- package/android/app/build.gradle +24 -9
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +52 -10
- package/android/app/src/main/java/com/microsoft/codepush/react/{CodePushDialog.java → CodePushDialogImpl.java} +28 -28
- package/android/app/src/main/java/com/microsoft/codepush/react/{CodePushNativeModule.java → CodePushNativeModuleImpl.java} +94 -198
- package/android/app/src/newarch/java/com/microsoft/codepush/react/CodePushDialog.java +49 -0
- package/android/app/src/newarch/java/com/microsoft/codepush/react/CodePushNativeModule.java +143 -0
- package/android/app/src/oldarch/java/com/microsoft/codepush/react/CodePushDialog.java +49 -0
- package/android/app/src/oldarch/java/com/microsoft/codepush/react/CodePushNativeModule.java +141 -0
- package/package.json +9 -1
- package/src/specs/NativeCodePush.ts +56 -0
- package/src/specs/NativeCodePushDialog.ts +19 -0
package/AlertAdapter.js
CHANGED
|
@@ -2,7 +2,22 @@ import React, { Platform } from "react-native";
|
|
|
2
2
|
let { Alert } = React;
|
|
3
3
|
|
|
4
4
|
if (Platform.OS === "android") {
|
|
5
|
-
|
|
5
|
+
function resolveNativeModule(name) {
|
|
6
|
+
const ReactNative = require("react-native");
|
|
7
|
+
try {
|
|
8
|
+
const turboModule =
|
|
9
|
+
ReactNative.TurboModuleRegistry && ReactNative.TurboModuleRegistry.get
|
|
10
|
+
? ReactNative.TurboModuleRegistry.get(name)
|
|
11
|
+
: null;
|
|
12
|
+
if (turboModule) return turboModule;
|
|
13
|
+
} catch (_e) {
|
|
14
|
+
// Ignore and fall back to legacy NativeModules.
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return ReactNative.NativeModules ? ReactNative.NativeModules[name] : null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const CodePushDialog = resolveNativeModule("CodePushDialog");
|
|
6
21
|
|
|
7
22
|
Alert = {
|
|
8
23
|
alert(title, message, buttons) {
|
|
@@ -13,6 +28,10 @@ if (Platform.OS === "android") {
|
|
|
13
28
|
const button1Text = buttons[0] ? buttons[0].text : null,
|
|
14
29
|
button2Text = buttons[1] ? buttons[1].text : null;
|
|
15
30
|
|
|
31
|
+
if (!CodePushDialog) {
|
|
32
|
+
throw "CodePushDialog native module is not installed.";
|
|
33
|
+
}
|
|
34
|
+
|
|
16
35
|
CodePushDialog.showDialog(
|
|
17
36
|
title, message, button1Text, button2Text,
|
|
18
37
|
(buttonId) => { buttons[buttonId].onPress && buttons[buttonId].onPress(); },
|
|
@@ -21,4 +40,4 @@ if (Platform.OS === "android") {
|
|
|
21
40
|
};
|
|
22
41
|
}
|
|
23
42
|
|
|
24
|
-
module.exports = { Alert };
|
|
43
|
+
module.exports = { Alert };
|
package/CodePush.js
CHANGED
|
@@ -5,7 +5,22 @@ import { AppState, Platform } from "react-native";
|
|
|
5
5
|
import log from "./logging";
|
|
6
6
|
import hoistStatics from 'hoist-non-react-statics';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
function resolveNativeModule(name) {
|
|
9
|
+
const ReactNative = require("react-native");
|
|
10
|
+
try {
|
|
11
|
+
const turboModule =
|
|
12
|
+
ReactNative.TurboModuleRegistry && ReactNative.TurboModuleRegistry.get
|
|
13
|
+
? ReactNative.TurboModuleRegistry.get(name)
|
|
14
|
+
: null;
|
|
15
|
+
if (turboModule) return turboModule;
|
|
16
|
+
} catch (_e) {
|
|
17
|
+
// Ignore and fall back to legacy NativeModules.
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return ReactNative.NativeModules ? ReactNative.NativeModules[name] : null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let NativeCodePush = resolveNativeModule("CodePush");
|
|
9
24
|
const PackageMixins = require("./package-mixins")(NativeCodePush);
|
|
10
25
|
|
|
11
26
|
async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchCallback = null) {
|
package/android/app/build.gradle
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
apply plugin: "com.android.library"
|
|
2
2
|
|
|
3
|
+
def safeExtGet(prop, fallback) {
|
|
4
|
+
return rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
5
|
+
}
|
|
6
|
+
|
|
3
7
|
def isNewArchitectureEnabled() {
|
|
4
8
|
// To opt-in for the New Architecture, you can either:
|
|
5
9
|
// - Set `newArchEnabled` to true inside the `gradle.properties` file
|
|
@@ -22,27 +26,38 @@ def DEFAULT_MIN_SDK_VERSION = 16
|
|
|
22
26
|
android {
|
|
23
27
|
namespace "com.microsoft.codepush.react"
|
|
24
28
|
|
|
25
|
-
compileSdkVersion
|
|
26
|
-
buildToolsVersion
|
|
29
|
+
compileSdkVersion safeExtGet("compileSdkVersion", DEFAULT_COMPILE_SDK_VERSION)
|
|
30
|
+
buildToolsVersion safeExtGet("buildToolsVersion", DEFAULT_BUILD_TOOLS_VERSION)
|
|
31
|
+
|
|
32
|
+
buildFeatures {
|
|
33
|
+
buildConfig true
|
|
34
|
+
}
|
|
27
35
|
|
|
28
36
|
defaultConfig {
|
|
29
|
-
minSdkVersion
|
|
30
|
-
targetSdkVersion
|
|
37
|
+
minSdkVersion safeExtGet("minSdkVersion", DEFAULT_MIN_SDK_VERSION)
|
|
38
|
+
targetSdkVersion safeExtGet("targetSdkVersion", DEFAULT_TARGET_SDK_VERSION)
|
|
31
39
|
versionCode 1
|
|
32
40
|
versionName "1.0"
|
|
33
41
|
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", IS_NEW_ARCHITECTURE_ENABLED.toString()
|
|
42
|
+
consumerProguardFiles 'proguard-rules.pro'
|
|
34
43
|
}
|
|
35
44
|
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
sourceSets {
|
|
46
|
+
main {
|
|
47
|
+
if (IS_NEW_ARCHITECTURE_ENABLED) {
|
|
48
|
+
java.srcDirs += ["src/newarch/java"]
|
|
49
|
+
} else {
|
|
50
|
+
java.srcDirs += ["src/oldarch/java"]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
38
53
|
}
|
|
39
54
|
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
lintOptions {
|
|
56
|
+
abortOnError false
|
|
42
57
|
}
|
|
43
58
|
}
|
|
44
59
|
|
|
45
60
|
dependencies {
|
|
46
|
-
implementation
|
|
61
|
+
implementation("com.facebook.react:react-android")
|
|
47
62
|
implementation 'com.nimbusds:nimbus-jose-jwt:9.37.3'
|
|
48
63
|
}
|
|
@@ -7,10 +7,12 @@ import android.content.res.Resources;
|
|
|
7
7
|
|
|
8
8
|
import com.facebook.react.ReactHost;
|
|
9
9
|
import com.facebook.react.ReactInstanceManager;
|
|
10
|
-
import com.facebook.react.
|
|
10
|
+
import com.facebook.react.BaseReactPackage;
|
|
11
11
|
import com.facebook.react.bridge.JavaScriptModule;
|
|
12
12
|
import com.facebook.react.bridge.NativeModule;
|
|
13
13
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
14
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
15
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
14
16
|
import com.facebook.react.uimanager.ViewManager;
|
|
15
17
|
|
|
16
18
|
import org.json.JSONException;
|
|
@@ -18,9 +20,11 @@ import org.json.JSONObject;
|
|
|
18
20
|
|
|
19
21
|
import java.io.File;
|
|
20
22
|
import java.util.ArrayList;
|
|
23
|
+
import java.util.HashMap;
|
|
21
24
|
import java.util.List;
|
|
25
|
+
import java.util.Map;
|
|
22
26
|
|
|
23
|
-
public class CodePush
|
|
27
|
+
public class CodePush extends BaseReactPackage {
|
|
24
28
|
private static final Object LOCK = new Object();
|
|
25
29
|
private static volatile CodePush mCurrentInstance;
|
|
26
30
|
public static CodePush getInstance(String deploymentKey, Context context, boolean isDebugMode) {
|
|
@@ -422,14 +426,14 @@ public class CodePush implements ReactPackage {
|
|
|
422
426
|
}
|
|
423
427
|
|
|
424
428
|
@Override
|
|
425
|
-
public
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
return
|
|
429
|
+
public NativeModule getModule(String name, ReactApplicationContext reactApplicationContext) {
|
|
430
|
+
if (CodePushNativeModule.NAME.equals(name)) {
|
|
431
|
+
return new CodePushNativeModule(reactApplicationContext, this, mUpdateManager, mTelemetryManager, mSettingsManager);
|
|
432
|
+
}
|
|
433
|
+
if (CodePushDialog.NAME.equals(name)) {
|
|
434
|
+
return new CodePushDialog(reactApplicationContext);
|
|
435
|
+
}
|
|
436
|
+
return null;
|
|
433
437
|
}
|
|
434
438
|
|
|
435
439
|
// Deprecated in RN v0.47.
|
|
@@ -441,4 +445,42 @@ public class CodePush implements ReactPackage {
|
|
|
441
445
|
public List<ViewManager> createViewManagers(ReactApplicationContext reactApplicationContext) {
|
|
442
446
|
return new ArrayList<>();
|
|
443
447
|
}
|
|
448
|
+
|
|
449
|
+
@Override
|
|
450
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
451
|
+
return new ReactModuleInfoProvider() {
|
|
452
|
+
@Override
|
|
453
|
+
public Map<String, ReactModuleInfo> getReactModuleInfos() {
|
|
454
|
+
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
|
|
455
|
+
|
|
456
|
+
Map<String, ReactModuleInfo> map = new HashMap<>();
|
|
457
|
+
map.put(
|
|
458
|
+
CodePushNativeModule.NAME,
|
|
459
|
+
new ReactModuleInfo(
|
|
460
|
+
CodePushNativeModule.NAME,
|
|
461
|
+
CodePushNativeModule.NAME,
|
|
462
|
+
false,
|
|
463
|
+
false,
|
|
464
|
+
true,
|
|
465
|
+
false,
|
|
466
|
+
isTurboModule
|
|
467
|
+
)
|
|
468
|
+
);
|
|
469
|
+
map.put(
|
|
470
|
+
CodePushDialog.NAME,
|
|
471
|
+
new ReactModuleInfo(
|
|
472
|
+
CodePushDialog.NAME,
|
|
473
|
+
CodePushDialog.NAME,
|
|
474
|
+
false,
|
|
475
|
+
false,
|
|
476
|
+
false,
|
|
477
|
+
false,
|
|
478
|
+
isTurboModule
|
|
479
|
+
)
|
|
480
|
+
);
|
|
481
|
+
|
|
482
|
+
return map;
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
}
|
|
444
486
|
}
|
|
@@ -4,43 +4,43 @@ import android.app.Activity;
|
|
|
4
4
|
import android.app.AlertDialog;
|
|
5
5
|
import android.content.DialogInterface;
|
|
6
6
|
|
|
7
|
-
import com.facebook.react.bridge.BaseJavaModule;
|
|
8
7
|
import com.facebook.react.bridge.Callback;
|
|
9
8
|
import com.facebook.react.bridge.LifecycleEventListener;
|
|
10
9
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
11
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
final class CodePushDialogImpl {
|
|
12
|
+
private final ReactApplicationContext reactContext;
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
CodePushDialogImpl(ReactApplicationContext reactContext) {
|
|
15
|
+
this.reactContext = reactContext;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
void showDialog(
|
|
19
|
+
final String title,
|
|
20
|
+
final String message,
|
|
21
|
+
final String button1Text,
|
|
22
|
+
final String button2Text,
|
|
23
|
+
final Callback successCallback,
|
|
24
|
+
final Callback errorCallback
|
|
25
|
+
) {
|
|
26
|
+
Activity currentActivity = reactContext.getCurrentActivity();
|
|
23
27
|
if (currentActivity == null || currentActivity.isFinishing()) {
|
|
24
|
-
|
|
25
|
-
// so we show the dialog when the app resumes)
|
|
26
|
-
getReactApplicationContext().addLifecycleEventListener(new LifecycleEventListener() {
|
|
28
|
+
reactContext.addLifecycleEventListener(new LifecycleEventListener() {
|
|
27
29
|
@Override
|
|
28
30
|
public void onHostResume() {
|
|
29
|
-
Activity
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
showDialogInternal(title, message, button1Text, button2Text, successCallback,
|
|
31
|
+
Activity resumedActivity = reactContext.getCurrentActivity();
|
|
32
|
+
if (resumedActivity != null && !resumedActivity.isFinishing()) {
|
|
33
|
+
reactContext.removeLifecycleEventListener(this);
|
|
34
|
+
showDialogInternal(title, message, button1Text, button2Text, successCallback, resumedActivity);
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
@Override
|
|
37
39
|
public void onHostPause() {
|
|
38
|
-
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
@Override
|
|
42
43
|
public void onHostDestroy() {
|
|
43
|
-
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
} else {
|
|
@@ -48,10 +48,15 @@ public class CodePushDialog extends BaseJavaModule {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
private void showDialogInternal(
|
|
52
|
-
|
|
51
|
+
private void showDialogInternal(
|
|
52
|
+
String title,
|
|
53
|
+
String message,
|
|
54
|
+
String button1Text,
|
|
55
|
+
String button2Text,
|
|
56
|
+
final Callback successCallback,
|
|
57
|
+
Activity currentActivity
|
|
58
|
+
) {
|
|
53
59
|
AlertDialog.Builder builder = new AlertDialog.Builder(currentActivity);
|
|
54
|
-
|
|
55
60
|
builder.setCancelable(false);
|
|
56
61
|
|
|
57
62
|
DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
|
|
@@ -61,10 +66,10 @@ public class CodePushDialog extends BaseJavaModule {
|
|
|
61
66
|
dialog.cancel();
|
|
62
67
|
switch (which) {
|
|
63
68
|
case DialogInterface.BUTTON_POSITIVE:
|
|
64
|
-
successCallback.invoke(0);
|
|
69
|
+
if (successCallback != null) successCallback.invoke(0);
|
|
65
70
|
break;
|
|
66
71
|
case DialogInterface.BUTTON_NEGATIVE:
|
|
67
|
-
successCallback.invoke(1);
|
|
72
|
+
if (successCallback != null) successCallback.invoke(1);
|
|
68
73
|
break;
|
|
69
74
|
default:
|
|
70
75
|
throw new CodePushUnknownException("Unknown button ID pressed.");
|
|
@@ -94,9 +99,4 @@ public class CodePushDialog extends BaseJavaModule {
|
|
|
94
99
|
AlertDialog dialog = builder.create();
|
|
95
100
|
dialog.show();
|
|
96
101
|
}
|
|
97
|
-
|
|
98
|
-
@Override
|
|
99
|
-
public String getName() {
|
|
100
|
-
return "CodePushDialog";
|
|
101
|
-
}
|
|
102
102
|
}
|