react-native-navigation的迁移库

ContentView.java 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.reactnativenavigation.views;
  2. import android.content.Context;
  3. import android.os.Bundle;
  4. import com.facebook.react.ReactInstanceManager;
  5. import com.facebook.react.ReactRootView;
  6. import com.reactnativenavigation.NavigationApplication;
  7. import com.reactnativenavigation.params.ScreenParams;
  8. import com.reactnativenavigation.react.ReactViewHacks;
  9. public class ContentView extends ReactRootView {
  10. private final String screenId;
  11. private final String navigatorEventId;
  12. private final Bundle passProps;
  13. public ContentView(Context context, ScreenParams screenParams, String screenId, Bundle passProps) {
  14. super(context);
  15. this.screenId = screenId;
  16. navigatorEventId = screenParams.navigatorEventId;
  17. this.passProps = mergePropsAndNavigationParams(screenParams, passProps);
  18. attachToJS();
  19. }
  20. public String getNavigatorEventId() {
  21. return navigatorEventId;
  22. }
  23. public void preventUnmountOnDetachedFromWindow() {
  24. ReactViewHacks.preventUnmountOnDetachedFromWindow(this);
  25. }
  26. public void ensureUnmountOnDetachedFromWindow() {
  27. ReactViewHacks.ensureUnmountOnDetachedFromWindow(this);
  28. }
  29. public void preventMountAfterReattachedToWindow() {
  30. ReactViewHacks.preventMountAfterReattachedToWindow(this);
  31. }
  32. private void attachToJS() {
  33. ReactInstanceManager react = NavigationApplication.instance.getNavigationReactInstance().getReactInstanceManager();
  34. startReactApplication(react, screenId, passProps);
  35. }
  36. private Bundle mergePropsAndNavigationParams(ScreenParams screenParams, Bundle passProps) {
  37. Bundle navigationParams = (Bundle) screenParams.navigationParams.clone();
  38. if (passProps != null) {
  39. navigationParams.putAll(passProps);
  40. }
  41. return navigationParams;
  42. }
  43. }