Skip to content

Commit

Permalink
Exposed getUiImplementationProvider for people to override if needed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SudoPlz authored and guyca committed Jun 5, 2018
1 parent 4c76331 commit 7a0bc3f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Expand Up @@ -12,6 +12,7 @@
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.uimanager.UIImplementationProvider;
import com.facebook.react.uimanager.UIManagerModule;
import com.reactnativenavigation.bridge.EventEmitter;
import com.reactnativenavigation.controllers.ActivityCallbacks;
Expand All @@ -34,7 +35,7 @@ public void onCreate() {
super.onCreate();
instance = this;
handler = new Handler(getMainLooper());
reactGateway = new NavigationReactGateway();
reactGateway = new NavigationReactGateway(getUIImplementationProvider());
eventEmitter = new EventEmitter(reactGateway);
activityCallbacks = new ActivityCallbacks();
}
Expand All @@ -53,6 +54,11 @@ public void startActivity(Intent intent) {
}
}

// here in case someone wants to override this
protected UIImplementationProvider getUIImplementationProvider() {
return null; // if null the default UIImplementationProvider will be used
}

public void startReactContextOnceInBackgroundAndExecuteJS() {
reactGateway.startReactContextOnceInBackgroundAndExecuteJS();
}
Expand Down
Expand Up @@ -10,6 +10,7 @@
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.react.uimanager.UIImplementationProvider;
import com.reactnativenavigation.NavigationApplication;
import com.reactnativenavigation.bridge.NavigationReactEventEmitter;
import com.reactnativenavigation.bridge.NavigationReactPackage;
Expand All @@ -28,7 +29,28 @@ public class NavigationReactGateway implements ReactGateway {
private JsDevReloadHandler jsDevReloadHandler;

public NavigationReactGateway() {
host = new ReactNativeHostImpl();
this(null);
}

public NavigationReactGateway(final UIImplementationProvider customImplProvider) {

if (customImplProvider != null) {
host = new ReactNativeHostImpl() {
/**
* This was added in case someone needs to provide a different UIImplementationProvider
* @param {UIImplementationProvider} defaultProvider
* @return {UIImplementationProvider}
*/
@Override
protected UIImplementationProvider getUIImplementationProvider() {
return customImplProvider;
}
};
} else {
host = new ReactNativeHostImpl();
}


jsDevReloadHandler = new JsDevReloadHandler();
}

Expand All @@ -41,6 +63,7 @@ public boolean isInitialized() {
return host.hasInstance() && getReactInstanceManager().getCurrentReactContext() != null;
}


@Override
public boolean hasStartedCreatingContext() {
return getReactInstanceManager().hasStartedCreatingInitialContext();
Expand Down Expand Up @@ -105,6 +128,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}


public ReactNativeHost getReactNativeHost() {
return host;
}
Expand All @@ -114,12 +138,13 @@ private void onReactContextInitialized(ReactContext context) {
reactEventEmitter = new NavigationReactEventEmitter(context);
}

private static class ReactNativeHostImpl extends ReactNativeHost implements ReactInstanceManager.ReactInstanceEventListener {
public static class ReactNativeHostImpl extends ReactNativeHost implements ReactInstanceManager.ReactInstanceEventListener {

ReactNativeHostImpl() {
public ReactNativeHostImpl() {
super(NavigationApplication.instance);
}


@Override
public boolean getUseDeveloperSupport() {
return NavigationApplication.instance.isDebug();
Expand Down

0 comments on commit 7a0bc3f

Please sign in to comment.