package com.navigation.reactnative;

import android.content.Context;
import android.os.Build;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.widget.ScrollView;

import androidx.coordinatorlayout.widget.CoordinatorLayout;

import com.facebook.react.uimanager.events.NativeGestureUtil;

public class CoordinatorLayoutView extends CoordinatorLayout {
    int overlap = 0;
    private boolean dragging = false;
    private int touchSlop;
    private int lastMotionY;
    private int activePointerId;

    public CoordinatorLayoutView(Context context){
        super(context);
        touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        requestLayout();
        post(measureAndLayout);
    }

    final Runnable measureAndLayout = new Runnable() {
        @Override
        public void run() {
            measure(
                    MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
            layout(getLeft(), getTop(), getRight(), getBottom());
        }
    };

    ScrollView getScrollView() {
        for(int i = 0; i < getChildCount(); i++) {
            if (getChildAt(i) instanceof ScrollView)
                return (ScrollView) getChildAt(i);
        }
        return null;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        ScrollView scrollView = getScrollView();
        boolean cannotScroll = scrollView != null && scrollView.getScrollY() == 0 && !scrollView.canScrollVertically(1);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && cannotScroll) {
            int action = ev.getAction();
            switch (action & MotionEvent.ACTION_MASK) {
                case MotionEvent.ACTION_DOWN: {
                    dragging = false;
                    lastMotionY = (int) ev.getY();
                    activePointerId = ev.getPointerId(0);
                    scrollView.startNestedScroll(SCROLL_AXIS_VERTICAL);
                    break;
                }
                case MotionEvent.ACTION_MOVE:
                    dragging = true;
                    break;
                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_UP:
                    dragging = false;
                    scrollView.stopNestedScroll();
                    break;
            }
        }
        if (dragging)
            NativeGestureUtil.notifyNativeGestureStarted(this, ev);
        return super.onInterceptTouchEvent(ev) || dragging;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && dragging) {
            int action = ev.getAction();
            if (MotionEvent.ACTION_MOVE == (action & MotionEvent.ACTION_MASK)) {
                int activePointerIndex = ev.findPointerIndex(activePointerId);
                int y = (int) ev.getY(activePointerIndex);
                int deltaY = lastMotionY - y;
            }
        }
        return super.onTouchEvent(ev) || dragging;
    }
}

@@ -2870,20 +2870,33 @@
         
-if (
+switch (action & 
 MotionEv
@@ -2911,24 +2911,35 @@
 ON_M
-OVE == (action &
+ASK) %7B%0A                case
  Mot
@@ -2959,16 +2959,19 @@
 ON_M
-ASK)) %7B%0A
+OVE: %7B%0A    
     
@@ -3045,16 +3045,20 @@
 terId);%0A
+    
         
@@ -3120,24 +3120,28 @@
             
+    
 int deltaY =
@@ -3158,16 +3158,218 @@
 nY - y;%0A
+                    break;%0A                %7D%0A                case MotionEvent.ACTION_CANCEL:%0A                case MotionEvent.ACTION_UP:%0A                    dragging = false;%0A                    break;%0A
         

Reset dragging on up and cancel