Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump micromatch and react-native in /Examples/CodePushDemoAppCpp #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12,389 changes: 4,780 additions & 7,609 deletions Examples/CodePushDemoAppCpp/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Examples/CodePushDemoAppCpp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"react": "^17.0.2",
"react-native": "^0.68.5",
"react-native": "^0.75.2",
"react-native-code-push": "^8.1.0",
"react-native-windows": "^1.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.pm.PackageManager;
import android.content.res.Resources;

import com.facebook.react.ReactHost;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
Expand Down Expand Up @@ -50,6 +51,7 @@ public class CodePush implements ReactPackage {
private static ReactInstanceHolder mReactInstanceHolder;
private static CodePush mCurrentInstance;


public CodePush(String deploymentKey, Context context) {
this(deploymentKey, context, false);
}
Expand Down Expand Up @@ -109,6 +111,20 @@ public CodePush(String deploymentKey, Context context, boolean isDebugMode, Stri
mServerUrl = serverUrl;
}

static ReactHost getReactHostFromHolder() {
if (mReactInstanceHolder == null) {
return null;
}
return mReactInstanceHolder.getReactHost();
}

public static CodePush getInstance(String deploymentKey, Context context, boolean isDebugMode) {
if (mCurrentInstance == null) {
mCurrentInstance = new CodePush(deploymentKey,context,isDebugMode);
}
return mCurrentInstance;
}

private String getPublicKeyByResourceDescriptor(int publicKeyResourceDescriptor){
String publicKey;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.view.View;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactHost;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactRootView;
import com.facebook.react.bridge.Arguments;
Expand All @@ -23,6 +24,7 @@
import com.facebook.react.modules.core.ChoreographerCompat;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.modules.core.ReactChoreographer;
import com.facebook.react.runtime.ReactHostDelegate;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -129,10 +131,30 @@ private void setJSBundle(ReactInstanceManager instanceManager, String latestJSBu
}
}

private void setJSBundle(ReactHost host, String latestJSBundleFile) throws {
try {
Field reactHostDelegate = host.getClass().getDeclaredField("mReactHostDelegate");
reactHostDelegate.setAccessible(true);
ReactHostDelegate delegate = (ReactHostDelegate) reactHostDelegate.get(host);
Field loader = delegate.getClass().getDeclaredField("jsBundleLoader");
loader.setAccessible(true);
JSBundleLoader latestJSBundleLoader;
if (latestJSBundleFile.toLowerCase().startsWith("assets://")) {
latestJSBundleLoader = JSBundleLoader.createAssetLoader(getReactApplicationContext(), latestJSBundleFile, true);
} else {
latestJSBundleLoader = JSBundleLoader.createFileLoader(latestJSBundleFile);
}
loader.set(delegate,latestJSBundleLoader);
} catch (Exception e) {
CodePushUtils.log("Unable to set JSBundle - CodePush may not support this version of React Native");
throw new IllegalAccessException("Could not setJSBundle");
}
}

private void loadBundle() {
clearLifecycleEventListener();
try {
mCodePush.clearDebugCacheIfNeeded(resolveInstanceManager());
// mCodePush.clearDebugCacheIfNeeded(resolveInstanceManager());
} catch(Exception e) {
// If we got error in out reflection we should clear debug cache anyway.
mCodePush.clearDebugCacheIfNeeded(null);
Expand All @@ -141,15 +163,15 @@ private void loadBundle() {
try {
// #1) Get the ReactInstanceManager instance, which is what includes the
// logic to reload the current React context.
final ReactInstanceManager instanceManager = resolveInstanceManager();
if (instanceManager == null) {
return;
}
// final ReactInstanceManager instanceManager = resolveInstanceManager();
// if (instanceManager == null) {
// return;
// }

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

// #2) Update the locally stored JS bundle file path
setJSBundle(instanceManager, latestJSBundleFile);
// setJSBundle(instanceManager, latestJSBundleFile);

// #3) Get the context creation method and fire it on the UI thread (which RN enforces)
new Handler(Looper.getMainLooper()).post(new Runnable() {
Expand All @@ -159,10 +181,11 @@ public void run() {
// We don't need to resetReactRootViews anymore
// due the issue https://github.com/facebook/react-native/issues/14533
// has been fixed in RN 0.46.0
//resetReactRootViews(instanceManager);

instanceManager.recreateReactContextInBackground();
mCodePush.initializeUpdateAfterRestart();
// resetReactRootViews(instanceManager);
ReactHost host = CodePush.getReactHostFromHolder();
CodePush.getReactHostFromHolder().reload("Restart-app");
// instanceManager.recreateReactContextInBackground();
// mCodePush.initializeUpdateAfterRestart();
} catch (Exception e) {
// The recreation method threw an unknown exception
// so just simply fallback to restarting the Activity (if it exists)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.microsoft.codepush.react;

import com.facebook.react.ReactHost;
import com.facebook.react.ReactInstanceManager;

/**
Expand All @@ -14,4 +15,5 @@ public interface ReactInstanceHolder {
* Get the current {@link ReactInstanceManager} instance. May return null.
*/
ReactInstanceManager getReactInstanceManager();
ReactHost getReactHost();
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
"rnpm": {
"android": {
"packageInstance": "new CodePush(getResources().getString(R.string.CodePushDeploymentKey), getApplicationContext(), BuildConfig.DEBUG)"
"packageInstance": "CodePush.getInstance(getResources().getString(R.string.CodePushDeploymentKey), getApplicationContext(), BuildConfig.DEBUG)"
},
"ios": {
"sharedLibraries": [
Expand Down
2 changes: 1 addition & 1 deletion react-native.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
platforms: {
android: {
packageInstance:
"new CodePush(getResources().getString(R.string.CodePushDeploymentKey), getApplicationContext(), BuildConfig.DEBUG)"
"CodePush.getInstance(getResources().getString(R.string.CodePushDeploymentKey), getApplicationContext(), BuildConfig.DEBUG)"
}
}
}
Expand Down