Skip to content

Instantly share code, notes, and snippets.

@MrCrambo
Last active July 25, 2020 08:37
Show Gist options
  • Save MrCrambo/42c095cd0d87c5692e2efb8ecf96a72d to your computer and use it in GitHub Desktop.
Save MrCrambo/42c095cd0d87c5692e2efb8ecf96a72d to your computer and use it in GitHub Desktop.
@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child))
ViewCompat.setFitsSystemWindows(child, true);
int savedTop = child.getTop();
// First let the parent lay it out
parent.onLayoutChild(child, layoutDirection);
// Offset the top sheet
mMinOffset = Math.max(-child.getHeight(), -(child.getHeight() - mPeekHeight));
mMaxOffset = 0;
if (mState == STATE_EXPANDED)
ViewCompat.offsetTopAndBottom(child, mMaxOffset);
else if (mHideable && mState == STATE_HIDDEN)
ViewCompat.offsetTopAndBottom(child, -child.getHeight());
else if (mState == STATE_COLLAPSED)
ViewCompat.offsetTopAndBottom(child, mMinOffset);
else if (mState == STATE_DRAGGING || mState == STATE_SETTLING)
ViewCompat.offsetTopAndBottom(child, savedTop - child.getTop());
if (mViewDragHelper == null)
mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
mViewRef = new WeakReference<>(child);
mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment