123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package com.reactnativenavigation.views;
-
- import android.annotation.SuppressLint;
- import android.content.Context;
- import android.view.MotionEvent;
- import android.view.View;
- import android.widget.FrameLayout;
- import android.widget.RelativeLayout;
-
- import com.reactnativenavigation.interfaces.ScrollEventListener;
- import com.reactnativenavigation.parse.Options;
- import com.reactnativenavigation.utils.UiUtils;
- import com.reactnativenavigation.utils.ViewUtils;
- import com.reactnativenavigation.viewcontrollers.IReactView;
- import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
- import com.reactnativenavigation.views.topbar.TopBar;
- import com.reactnativenavigation.views.touch.OverlayTouchDelegate;
-
- import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
-
- @SuppressLint("ViewConstructor")
- public class ComponentLayout extends FrameLayout implements ReactComponent, TopBarButtonController.OnClickListener {
-
- private IReactView reactView;
- private final OverlayTouchDelegate touchDelegate;
-
- public ComponentLayout(Context context, IReactView reactView) {
- super(context);
- this.reactView = reactView;
- addView(reactView.asView(), MATCH_PARENT, MATCH_PARENT);
- setContentDescription("ComponentLayout");
- touchDelegate = new OverlayTouchDelegate(reactView);
- }
-
- @Override
- public boolean isReady() {
- return reactView.isReady();
- }
-
- @Override
- public View asView() {
- return this;
- }
-
- @Override
- public void destroy() {
- reactView.destroy();
- }
-
- @Override
- public void sendComponentStart() {
- reactView.sendComponentStart();
- }
-
- @Override
- public void sendComponentStop() {
- reactView.sendComponentStop();
- }
-
- public void applyOptions(Options options) {
- touchDelegate.setInterceptTouchOutside(options.overlayOptions.interceptTouchOutside);
- }
-
- @Override
- public void sendOnNavigationButtonPressed(String buttonId) {
- reactView.sendOnNavigationButtonPressed(buttonId);
- }
-
- @Override
- public ScrollEventListener getScrollEventListener() {
- return reactView.getScrollEventListener();
- }
-
- @Override
- public void dispatchTouchEventToJs(MotionEvent event) {
- reactView.dispatchTouchEventToJs(event);
- }
-
- @Override
- public void drawBehindTopBar() {
- if (getLayoutParams() instanceof RelativeLayout.LayoutParams) {
- RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
- layoutParams.topMargin = 0;
- setLayoutParams(layoutParams);
- }
- }
-
- @Override
- public void drawBelowTopBar(TopBar topBar) {
- if (getLayoutParams() instanceof RelativeLayout.LayoutParams) {
- RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
- int topBarHeight = ViewUtils.getPreferredHeight(topBar);
- if (topBarHeight == 0) {
- UiUtils.runOnPreDrawOnce(topBar, () -> layoutParams.topMargin = topBar.getHeight());
- } else {
- layoutParams.topMargin = topBarHeight;
- }
- setLayoutParams(layoutParams);
- }
- }
-
- @Override
- public boolean isRendered() {
- return reactView.isRendered();
- }
-
- @Override
- public void onPress(String buttonId) {
- reactView.sendOnNavigationButtonPressed(buttonId);
- }
-
- @Override
- public boolean onInterceptTouchEvent(MotionEvent ev) {
- return touchDelegate.onInterceptTouchEvent(ev);
- }
- }
|