package com.navigation.reactnative;

import android.content.Context;
import android.view.View;
import android.widget.ScrollView;

import androidx.coordinatorlayout.widget.CoordinatorLayout;

import com.facebook.react.uimanager.PixelUtil;

public class CoordinatorLayoutView extends CoordinatorLayout {
    int overlap = 0;
    boolean nestedScrolling = false;

    public CoordinatorLayoutView(Context context){
        super(context);
    }

    @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());
        }
    };

    private NavigationBarView getNavigationBarView() {
        for(int i = 0; i < getChildCount(); i++) {
            if (getChildAt(i) instanceof NavigationBarView)
                return (NavigationBarView) getChildAt(i);
        }
        return null;
    }

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

    @Override
    public boolean onStartNestedScroll(View child, View target, int axes, int type) {
        nestedScrolling = true;
        return super.onStartNestedScroll(child, target, axes, type);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        nestedScrolling = false;
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    /*@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int height = MeasureSpec.getSize(heightMeasureSpec);
        int contentHeight = getScrollView() != null ? getScrollView().getChildAt(0).getHeight() : 0;
        boolean collapsingBar = getNavigationBarView() != null && getNavigationBarView().getChildAt(0) instanceof CollapsingBarView;
        int navigationBarHeight = collapsingBar ? (int) PixelUtil.toPixelFromDIP(56) : 0;
        int collapsedGap = height + 2 - contentHeight - navigationBarHeight;
        if (collapsedGap > 0)
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec) - collapsedGap, MeasureSpec.EXACTLY);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }*/
}

@@ -66,34 +66,8 @@
 xt;%0A
-import android.view.View;%0A
 impo
@@ -293,45 +293,8 @@
 = 0;
-%0A    boolean nestedScrolling = false;
 %0A%0A  
@@ -1390,408 +1390,8 @@
  %7D%0A%0A
-    @Override%0A    public boolean onStartNestedScroll(View child, View target, int axes, int type) %7B%0A        nestedScrolling = true;%0A        return super.onStartNestedScroll(child, target, axes, type);%0A    %7D%0A%0A    @Override%0A    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) %7B%0A        nestedScrolling = false;%0A        super.onMeasure(widthMeasureSpec, heightMeasureSpec);%0A    %7D%0A%0A
     

Revert "Tracked if scroll content tall enough"