package com.bottomsheetbehavior;

import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.widget.NestedScrollView;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;

import com.facebook.react.uimanager.PixelUtil;

public class BottomSheetBehaviorView extends NestedScrollView {

    public RNBottomSheetBehavior behavior;

    private final static int DEFAULT_PEEK_HEIGHT = 50;
    private final static int DEFAULT_ANCHOR_POINT = 300;

    public BottomSheetBehaviorView(Context context) {
        super(context);

        int width  = ViewGroup.LayoutParams.WRAP_CONTENT;
        int height = ViewGroup.LayoutParams.WRAP_CONTENT;

        CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(width, height);
        params.setBehavior(new RNBottomSheetBehavior());

        this.setLayoutParams(params);

        behavior = RNBottomSheetBehavior.from(this);
        behavior.setPeekHeight((int) PixelUtil.toPixelFromDIP(DEFAULT_PEEK_HEIGHT));
        behavior.setAnchorPoint((int) PixelUtil.toPixelFromDIP(DEFAULT_ANCHOR_POINT));
        behavior.setAnchorEnabled(false);
    }

    public void setState(int state) {
        behavior.setState(state);
    }

    public void setPeekHeight(int peekHeight) {
        int peekHeightPixel = (int) PixelUtil.toPixelFromDIP(peekHeight);
        behavior.setPeekHeight(peekHeightPixel);
    }

    public void setHideable(boolean hideable) {
        behavior.setHideable(hideable);
    }

    public void setAnchorEnabled(boolean anchorEnabled) {
        behavior.setAnchorEnabled(anchorEnabled);
    }

    public void setAnchorPoint(int anchorPoint) {
        int anchorPointPixel = (int) PixelUtil.toPixelFromDIP(anchorPoint);
        behavior.setAnchorPoint(anchorPointPixel);
    }

    public void setBottomSheetElevation(float elevation) {
        if (android.os.Build.VERSION.SDK_INT >= 21) {
            this.setElevation(elevation);
            this.setOutlineProvider(ViewOutlineProvider.BOUNDS);
        }
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (!behavior.getAnchorEnabled()) {
            View child = this.getChildAt(0);
            if (child != null) {
                setMeasuredDimension(widthMeasureSpec, child.getHeight());
            }
        } else {
            setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
        }
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
    }
}

@@ -1269,24 +1269,188 @@
 ate(state);%0A
+        if (state == RNBottomSheetBehavior.STATE_COLLAPSED %7C%7C%0A            state == RNBottomSheetBehavior.STATE_ANCHOR_POINT) %7B%0A            resetScroll();%0A        %7D%0A
     %7D%0A%0A    p
@@ -2245,32 +2245,102 @@
        %7D%0A    %7D%0A%0A
+    private void resetScroll() %7B%0A        fullScroll(FOCUS_UP);%0A    %7D%0A%0A
     @Override%0A  

Reset scroll if the new state will be collpased or anchor point