react-native-navigation的迁移库

NavigationApplication.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.ReactApplication;
  6. import com.facebook.react.ReactNativeHost;
  7. import com.facebook.react.ReactPackage;
  8. import com.facebook.react.bridge.ReactContext;
  9. import com.reactnativenavigation.bridge.EventEmitter;
  10. import com.reactnativenavigation.controllers.ActivityCallbacks;
  11. import com.reactnativenavigation.react.NavigationReactGateway;
  12. import com.reactnativenavigation.react.ReactGateway;
  13. import java.util.List;
  14. public abstract class NavigationApplication extends Application implements ReactApplication {
  15. public static NavigationApplication instance;
  16. private NavigationReactGateway reactGateway;
  17. private EventEmitter eventEmitter;
  18. private Handler handler;
  19. private ActivityCallbacks activityCallbacks;
  20. @Override
  21. public void onCreate() {
  22. super.onCreate();
  23. instance = this;
  24. handler = new Handler(getMainLooper());
  25. reactGateway = new NavigationReactGateway();
  26. eventEmitter = new EventEmitter(reactGateway);
  27. activityCallbacks = new ActivityCallbacks();
  28. }
  29. public void startReactContextOnceInBackgroundAndExecuteJS() {
  30. reactGateway.startReactContextOnceInBackgroundAndExecuteJS();
  31. }
  32. public void runOnMainThread(Runnable runnable) {
  33. handler.post(runnable);
  34. }
  35. public void runOnMainThread(Runnable runnable, long delay) {
  36. handler.postDelayed(runnable, delay);
  37. }
  38. public ReactGateway getReactGateway() {
  39. return reactGateway;
  40. }
  41. public ActivityCallbacks getActivityCallbacks() {
  42. return activityCallbacks;
  43. }
  44. protected void setActivityCallbacks(ActivityCallbacks activityLifecycleCallbacks) {
  45. this.activityCallbacks = activityLifecycleCallbacks;
  46. }
  47. public boolean isReactContextInitialized() {
  48. return reactGateway.isInitialized();
  49. }
  50. public void onReactInitialized(ReactContext reactContext) {
  51. // nothing
  52. }
  53. @Override
  54. public ReactNativeHost getReactNativeHost() {
  55. return reactGateway.getReactNativeHost();
  56. }
  57. public EventEmitter getEventEmitter() {
  58. return eventEmitter;
  59. }
  60. /**
  61. * @see ReactNativeHost#getJSMainModuleName()
  62. */
  63. @Nullable
  64. public String getJSMainModuleName() {
  65. return null;
  66. }
  67. /**
  68. * @see ReactNativeHost#getJSBundleFile()
  69. */
  70. @Nullable
  71. public String getJSBundleFile() {
  72. return null;
  73. }
  74. /**
  75. * @see ReactNativeHost#getBundleAssetName()
  76. */
  77. @Nullable
  78. public String getBundleAssetName() {
  79. return null;
  80. }
  81. public abstract boolean isDebug();
  82. @Nullable
  83. public abstract List<ReactPackage> createAdditionalReactPackages();
  84. }