react-native-navigation的迁移库

ComponentLayout.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package com.reactnativenavigation.views;
  2. import android.annotation.SuppressLint;
  3. import android.content.Context;
  4. import android.view.MotionEvent;
  5. import android.view.View;
  6. import com.reactnativenavigation.interfaces.ScrollEventListener;
  7. import com.reactnativenavigation.parse.Options;
  8. import com.reactnativenavigation.parse.params.Bool;
  9. import com.reactnativenavigation.react.ReactView;
  10. import com.reactnativenavigation.react.events.ComponentType;
  11. import com.reactnativenavigation.viewcontrollers.TitleBarButtonController;
  12. import com.reactnativenavigation.views.touch.OverlayTouchDelegate;
  13. import androidx.coordinatorlayout.widget.CoordinatorLayout;
  14. import static com.reactnativenavigation.utils.CoordinatorLayoutUtils.matchParentLP;
  15. @SuppressLint("ViewConstructor")
  16. public class ComponentLayout extends CoordinatorLayout implements ReactComponent, TitleBarButtonController.OnClickListener {
  17. private ReactView reactView;
  18. private final OverlayTouchDelegate touchDelegate;
  19. public ComponentLayout(Context context, ReactView reactView) {
  20. super(context);
  21. this.reactView = reactView;
  22. addView(reactView.asView(), matchParentLP());
  23. touchDelegate = new OverlayTouchDelegate(reactView);
  24. }
  25. @Override
  26. public boolean isReady() {
  27. return reactView.isReady();
  28. }
  29. @Override
  30. public View asView() {
  31. return this;
  32. }
  33. @Override
  34. public void destroy() {
  35. reactView.destroy();
  36. }
  37. public void sendComponentStart() {
  38. reactView.sendComponentStart(ComponentType.Component);
  39. }
  40. public void sendComponentStop() {
  41. reactView.sendComponentStop(ComponentType.Component);
  42. }
  43. public void applyOptions(Options options) {
  44. touchDelegate.setInterceptTouchOutside(options.overlayOptions.interceptTouchOutside);
  45. }
  46. public void setInterceptTouchOutside(Bool interceptTouchOutside) {
  47. touchDelegate.setInterceptTouchOutside(interceptTouchOutside);
  48. }
  49. @Override
  50. public void sendOnNavigationButtonPressed(String buttonId) {
  51. reactView.sendOnNavigationButtonPressed(buttonId);
  52. }
  53. @Override
  54. public ScrollEventListener getScrollEventListener() {
  55. return reactView.getScrollEventListener();
  56. }
  57. @Override
  58. public void dispatchTouchEventToJs(MotionEvent event) {
  59. reactView.dispatchTouchEventToJs(event);
  60. }
  61. @Override
  62. public boolean isRendered() {
  63. return reactView.isRendered();
  64. }
  65. @Override
  66. public void onPress(String buttonId) {
  67. reactView.sendOnNavigationButtonPressed(buttonId);
  68. }
  69. @Override
  70. public boolean onInterceptTouchEvent(MotionEvent ev) {
  71. return touchDelegate.onInterceptTouchEvent(ev);
  72. }
  73. }