react-native-navigation的迁移库

ComponentViewController.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.reactnativenavigation.viewcontrollers;
  2. import android.app.Activity;
  3. import android.support.annotation.NonNull;
  4. import com.reactnativenavigation.parse.Options;
  5. import com.reactnativenavigation.presentation.OptionsPresenter;
  6. import com.reactnativenavigation.views.ComponentLayout;
  7. import com.reactnativenavigation.views.ReactComponent;
  8. public class ComponentViewController extends ChildController<ComponentLayout> {
  9. private final String componentName;
  10. private final ReactViewCreator viewCreator;
  11. public ComponentViewController(final Activity activity,
  12. final ChildControllersRegistry childRegistry,
  13. final String id,
  14. final String componentName,
  15. final ReactViewCreator viewCreator,
  16. final Options initialOptions,
  17. final OptionsPresenter presenter) {
  18. super(activity, childRegistry, id, presenter, initialOptions);
  19. this.componentName = componentName;
  20. this.viewCreator = viewCreator;
  21. }
  22. @Override
  23. public void onViewAppeared() {
  24. super.onViewAppeared();
  25. view.sendComponentStart();
  26. }
  27. @Override
  28. public void onViewDisappear() {
  29. view.sendComponentStop();
  30. super.onViewDisappear();
  31. }
  32. @Override
  33. public void sendOnNavigationButtonPressed(String buttonId) {
  34. getView().sendOnNavigationButtonPressed(buttonId);
  35. }
  36. @Override
  37. public void applyOptions(Options options) {
  38. super.applyOptions(options);
  39. view.applyOptions(options);
  40. }
  41. @Override
  42. protected boolean isViewShown() {
  43. return super.isViewShown() && view.isReady();
  44. }
  45. @NonNull
  46. @Override
  47. protected ComponentLayout createView() {
  48. view = (ComponentLayout) viewCreator.create(getActivity(), getId(), componentName);
  49. return (ComponentLayout) view.asView();
  50. }
  51. @Override
  52. public void mergeOptions(Options options) {
  53. applyOnParentController(parentController -> parentController.mergeChildOptions(options, getView()));
  54. super.mergeOptions(options);
  55. }
  56. ReactComponent getComponent() {
  57. return view;
  58. }
  59. }