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

[v2] add support for react-native 0.57.0 #3851

Merged
merged 8 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions lib/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ android {
reactNative56 {
dimension "RNN.reactNativeVersion"
}
reactNative57 {
dimension "RNN.reactNativeVersion"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.reactnativenavigation.react;

import android.app.Application;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.facebook.infer.annotation.Assertions;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactInstanceManagerBuilder;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.shell.MainReactPackage;
import com.reactnativenavigation.NavigationApplication;

import java.util.ArrayList;
import java.util.List;

/**
* Default implementation of {@link ReactNativeHost} that includes {@link NavigationPackage}
* and user-defined additional packages.
*/
public class NavigationReactNativeHost extends ReactNativeHost implements BundleDownloadListenerProvider {

private final boolean isDebug;
private final List<ReactPackage> additionalReactPackages;
private @Nullable NavigationDevBundleDownloadListener bundleListener;
private final DevBundleDownloadListener bundleListenerMediator = new DevBundleDownloadListenerAdapter() {
@Override
public void onSuccess() {
if (bundleListener != null) {
bundleListener.onSuccess();
}
}
};


public NavigationReactNativeHost(NavigationApplication application) {
this(application, application.isDebug(), application.createAdditionalReactPackages());
}

@SuppressWarnings("WeakerAccess")
public NavigationReactNativeHost(Application application, boolean isDebug, final List<ReactPackage> additionalReactPackages) {
super(application);
this.isDebug = isDebug;
this.additionalReactPackages = additionalReactPackages;
}

@Override
public void setBundleLoaderListener(NavigationDevBundleDownloadListener listener) {
bundleListener = listener;
}

@Override
public boolean getUseDeveloperSupport() {
return isDebug;
}

@Override
protected List<ReactPackage> getPackages() {
List<ReactPackage> packages = new ArrayList<>();
boolean hasMainReactPackage = false;
packages.add(new NavigationPackage(this));
if (additionalReactPackages != null) {
for (ReactPackage p : additionalReactPackages) {
if (!(p instanceof NavigationPackage)) {
packages.add(p);
}
if (p instanceof MainReactPackage) hasMainReactPackage = true;
}
}
if (!hasMainReactPackage) {
packages.add(new MainReactPackage());
}
return packages;
}

protected ReactInstanceManager createReactInstanceManager() {
ReactInstanceManagerBuilder builder = ReactInstanceManager.builder()
.setApplication(getApplication())
.setJSMainModulePath(getJSMainModuleName())
.setUseDeveloperSupport(getUseDeveloperSupport())
.setRedBoxHandler(getRedBoxHandler())
.setJavaScriptExecutorFactory(getJavaScriptExecutorFactory())
.setUIImplementationProvider(getUIImplementationProvider())
.setInitialLifecycleState(LifecycleState.BEFORE_CREATE)
.setDevBundleDownloadListener(getDevBundleDownloadListener());

for (ReactPackage reactPackage : getPackages()) {
builder.addPackage(reactPackage);
}

String jsBundleFile = getJSBundleFile();
if (jsBundleFile != null) {
builder.setJSBundleFile(jsBundleFile);
} else {
builder.setBundleAssetName(Assertions.assertNotNull(getBundleAssetName()));
}
return builder.build();
}

@SuppressWarnings("WeakerAccess")
@NonNull
protected DevBundleDownloadListener getDevBundleDownloadListener() {
return bundleListenerMediator;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.reactnativenavigation.react;

import android.app.Application;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.facebook.infer.annotation.Assertions;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactInstanceManagerBuilder;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.shell.MainReactPackage;
import com.reactnativenavigation.NavigationApplication;

import java.util.ArrayList;
import java.util.List;

/**
* Default implementation of {@link ReactNativeHost} that includes {@link NavigationPackage}
* and user-defined additional packages.
*/
public class NavigationReactNativeHost extends ReactNativeHost implements BundleDownloadListenerProvider {

private final boolean isDebug;
private final List<ReactPackage> additionalReactPackages;
private @Nullable NavigationDevBundleDownloadListener bundleListener;
private final DevBundleDownloadListener bundleListenerMediator = new DevBundleDownloadListenerAdapter() {
@Override
public void onSuccess() {
if (bundleListener != null) {
bundleListener.onSuccess();
}
}
};


public NavigationReactNativeHost(NavigationApplication application) {
this(application, application.isDebug(), application.createAdditionalReactPackages());
}

@SuppressWarnings("WeakerAccess")
public NavigationReactNativeHost(Application application, boolean isDebug, final List<ReactPackage> additionalReactPackages) {
super(application);
this.isDebug = isDebug;
this.additionalReactPackages = additionalReactPackages;
}

@Override
public void setBundleLoaderListener(NavigationDevBundleDownloadListener listener) {
bundleListener = listener;
}

@Override
public boolean getUseDeveloperSupport() {
return isDebug;
}

@Override
protected List<ReactPackage> getPackages() {
List<ReactPackage> packages = new ArrayList<>();
boolean hasMainReactPackage = false;
packages.add(new NavigationPackage(this));
if (additionalReactPackages != null) {
for (ReactPackage p : additionalReactPackages) {
if (!(p instanceof NavigationPackage)) {
packages.add(p);
}
if (p instanceof MainReactPackage) hasMainReactPackage = true;
}
}
if (!hasMainReactPackage) {
packages.add(new MainReactPackage());
}
return packages;
}

protected ReactInstanceManager createReactInstanceManager() {
ReactInstanceManagerBuilder builder = ReactInstanceManager.builder()
.setApplication(getApplication())
.setJSMainModulePath(getJSMainModuleName())
.setUseDeveloperSupport(getUseDeveloperSupport())
.setRedBoxHandler(getRedBoxHandler())
.setJavaScriptExecutorFactory(getJavaScriptExecutorFactory())
.setUIImplementationProvider(getUIImplementationProvider())
.setInitialLifecycleState(LifecycleState.BEFORE_CREATE)
.setDevBundleDownloadListener(getDevBundleDownloadListener());

for (ReactPackage reactPackage : getPackages()) {
builder.addPackage(reactPackage);
}

String jsBundleFile = getJSBundleFile();
if (jsBundleFile != null) {
builder.setJSBundleFile(jsBundleFile);
} else {
builder.setBundleAssetName(Assertions.assertNotNull(getBundleAssetName()));
}
return builder.build();
}

@SuppressWarnings("WeakerAccess")
@NonNull
protected DevBundleDownloadListener getDevBundleDownloadListener() {
return bundleListenerMediator;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.reactnativenavigation.react;

import com.facebook.react.bridge.NativeDeltaClient;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;

import javax.annotation.Nullable;

public class DevBundleDownloadListenerAdapter implements DevBundleDownloadListener, NavigationDevBundleDownloadListener {
@Override
public void onSuccess(@Nullable NativeDeltaClient nativeDeltaClient) {
onSuccess();
}

@Override
public void onSuccess() {

}

@Override
public void onProgress(@Nullable String status, @Nullable Integer done, @Nullable Integer total) {

}

@Override
public void onFailure(Exception cause) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.reactnativenavigation.react;

import com.facebook.react.bridge.NativeDeltaClient;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;

import javax.annotation.Nullable;

public class JsDevReloadHandlerFacade implements DevBundleDownloadListener, NavigationDevBundleDownloadListener {
@Override
public void onSuccess(@Nullable NativeDeltaClient nativeDeltaClient) {
onSuccess();
}

@Override
public void onProgress(@Nullable String status, @Nullable Integer done, @Nullable Integer total) {

}

@Override
public void onFailure(Exception cause) {

}

@Override
public void onSuccess() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.reactnativenavigation.react;

import android.app.Application;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.facebook.infer.annotation.Assertions;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactInstanceManagerBuilder;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.shell.MainReactPackage;
import com.reactnativenavigation.NavigationApplication;

import java.util.ArrayList;
import java.util.List;

/**
* Default implementation of {@link ReactNativeHost} that includes {@link NavigationPackage}
* and user-defined additional packages.
*/
public class NavigationReactNativeHost extends ReactNativeHost implements BundleDownloadListenerProvider {

private final boolean isDebug;
private final List<ReactPackage> additionalReactPackages;
private @Nullable NavigationDevBundleDownloadListener bundleListener;
private final DevBundleDownloadListener bundleListenerMediator = new DevBundleDownloadListenerAdapter() {
@Override
public void onSuccess() {
if (bundleListener != null) {
bundleListener.onSuccess();
}
}
};


public NavigationReactNativeHost(NavigationApplication application) {
this(application, application.isDebug(), application.createAdditionalReactPackages());
}

@SuppressWarnings("WeakerAccess")
public NavigationReactNativeHost(Application application, boolean isDebug, final List<ReactPackage> additionalReactPackages) {
super(application);
this.isDebug = isDebug;
this.additionalReactPackages = additionalReactPackages;
}

@Override
public void setBundleLoaderListener(NavigationDevBundleDownloadListener listener) {
bundleListener = listener;
}

@Override
public boolean getUseDeveloperSupport() {
return isDebug;
}

@Override
protected List<ReactPackage> getPackages() {
List<ReactPackage> packages = new ArrayList<>();
boolean hasMainReactPackage = false;
packages.add(new NavigationPackage(this));
if (additionalReactPackages != null) {
for (ReactPackage p : additionalReactPackages) {
if (!(p instanceof NavigationPackage)) {
packages.add(p);
}
if (p instanceof MainReactPackage) hasMainReactPackage = true;
}
}
if (!hasMainReactPackage) {
packages.add(new MainReactPackage());
}
return packages;
}

protected ReactInstanceManager createReactInstanceManager() {
ReactInstanceManagerBuilder builder = ReactInstanceManager.builder()
.setApplication(getApplication())
.setJSMainModulePath(getJSMainModuleName())
.setUseDeveloperSupport(getUseDeveloperSupport())
.setRedBoxHandler(getRedBoxHandler())
.setJavaScriptExecutorFactory(getJavaScriptExecutorFactory())
.setInitialLifecycleState(LifecycleState.BEFORE_CREATE)
.setDevBundleDownloadListener(getDevBundleDownloadListener());

for (ReactPackage reactPackage : getPackages()) {
builder.addPackage(reactPackage);
}

String jsBundleFile = getJSBundleFile();
if (jsBundleFile != null) {
builder.setJSBundleFile(jsBundleFile);
} else {
builder.setBundleAssetName(Assertions.assertNotNull(getBundleAssetName()));
}
return builder.build();
}

@SuppressWarnings("WeakerAccess")
@NonNull
protected DevBundleDownloadListener getDevBundleDownloadListener() {
return bundleListenerMediator;
}
}
Loading