| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- package com.reactnativenavigation;
-
- import android.app.Application;
- import android.os.Handler;
- import android.support.annotation.Nullable;
-
- import com.facebook.react.ReactPackage;
- import com.facebook.react.bridge.ReactContext;
- import com.facebook.react.bridge.WritableMap;
- import com.reactnativenavigation.react.NavigationReactGateway;
- import com.reactnativenavigation.react.ReactGateway;
-
- import java.util.List;
-
- public abstract class NavigationApplication extends Application {
-
- public static NavigationApplication instance;
-
- private ReactGateway reactGateway;
- private Handler handler;
-
- @Override
- public void onCreate() {
- super.onCreate();
- instance = this;
- reactGateway = new NavigationReactGateway();
- handler = new Handler(getMainLooper());
- }
-
- public void startReactContext() {
- reactGateway.startReactContextOnceInBackgroundAndExecuteJS();
- }
-
- public void runOnMainThread(Runnable runnable) {
- handler.post(runnable);
- }
-
- public void runOnMainThread(Runnable runnable, long delay) {
- handler.postDelayed(runnable, delay);
- }
-
- public ReactGateway getReactGateway() {
- return reactGateway;
- }
-
- public boolean isReactContextInitialized() {
- return reactGateway.isInitialized();
- }
-
- public void onReactInitialized(ReactContext reactContext) {
- // nothing
- }
-
- public String getJsEntryFileName() {
- return "index.android";
- }
-
- public String getBundleAssetName() {
- return "index.android.bundle";
- }
-
- public abstract boolean isDebug();
-
-
- @Nullable
- public abstract List<ReactPackage> createAdditionalReactPackages();
-
- //TODO move all these navigator junk elsewhere
- public void sendNavigatorEvent(String eventId, String navigatorEventId) {
- if (!isReactContextInitialized()) {
- return;
- }
- reactGateway.getReactEventEmitter().sendNavigatorEvent(eventId, navigatorEventId);
- }
-
- public void sendNavigatorEvent(String eventId, String navigatorEventId, WritableMap data) {
- if (!isReactContextInitialized()) {
- return;
- }
- reactGateway.getReactEventEmitter().sendNavigatorEvent(eventId, navigatorEventId, data);
- }
-
- public void sendEvent(String eventId, String navigatorEventId) {
- if (!isReactContextInitialized()) {
- return;
- }
- reactGateway.getReactEventEmitter().sendEvent(eventId, navigatorEventId);
- }
-
- public void sendNavigatorEvent(String eventId, WritableMap arguments) {
- if (!isReactContextInitialized()) {
- return;
- }
- reactGateway.getReactEventEmitter().sendEvent(eventId, arguments);
- }
-
- }
|