react-native-navigation的迁移库

NavigationApplication.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package com.reactnativenavigation;
  2. import android.app.Application;
  3. import android.os.Handler;
  4. import android.support.annotation.Nullable;
  5. import com.facebook.react.ReactPackage;
  6. import com.facebook.react.bridge.ReactContext;
  7. import com.facebook.react.bridge.WritableMap;
  8. import com.reactnativenavigation.react.NavigationReactGateway;
  9. import com.reactnativenavigation.react.ReactGateway;
  10. import java.util.List;
  11. public abstract class NavigationApplication extends Application {
  12. public static NavigationApplication instance;
  13. private ReactGateway reactGateway;
  14. private Handler handler;
  15. @Override
  16. public void onCreate() {
  17. super.onCreate();
  18. instance = this;
  19. reactGateway = new NavigationReactGateway();
  20. handler = new Handler(getMainLooper());
  21. }
  22. public void startReactContext() {
  23. reactGateway.startReactContextOnceInBackgroundAndExecuteJS();
  24. }
  25. public void runOnMainThread(Runnable runnable) {
  26. handler.post(runnable);
  27. }
  28. public void runOnMainThread(Runnable runnable, long delay) {
  29. handler.postDelayed(runnable, delay);
  30. }
  31. public ReactGateway getReactGateway() {
  32. return reactGateway;
  33. }
  34. public boolean isReactContextInitialized() {
  35. return reactGateway.isInitialized();
  36. }
  37. public void onReactInitialized(ReactContext reactContext) {
  38. // nothing
  39. }
  40. public String getJsEntryFileName() {
  41. return "index.android";
  42. }
  43. public String getBundleAssetName() {
  44. return "index.android.bundle";
  45. }
  46. public abstract boolean isDebug();
  47. @Nullable
  48. public abstract List<ReactPackage> createAdditionalReactPackages();
  49. //TODO move all these navigator junk elsewhere
  50. public void sendNavigatorEvent(String eventId, String navigatorEventId) {
  51. if (!isReactContextInitialized()) {
  52. return;
  53. }
  54. reactGateway.getReactEventEmitter().sendNavigatorEvent(eventId, navigatorEventId);
  55. }
  56. public void sendNavigatorEvent(String eventId, String navigatorEventId, WritableMap data) {
  57. if (!isReactContextInitialized()) {
  58. return;
  59. }
  60. reactGateway.getReactEventEmitter().sendNavigatorEvent(eventId, navigatorEventId, data);
  61. }
  62. public void sendEvent(String eventId, String navigatorEventId) {
  63. if (!isReactContextInitialized()) {
  64. return;
  65. }
  66. reactGateway.getReactEventEmitter().sendEvent(eventId, navigatorEventId);
  67. }
  68. public void sendNavigatorEvent(String eventId, WritableMap arguments) {
  69. if (!isReactContextInitialized()) {
  70. return;
  71. }
  72. reactGateway.getReactEventEmitter().sendEvent(eventId, arguments);
  73. }
  74. }