Skip to content

Commit

Permalink
Merge pull request #14 from trafi/fix-short-content
Browse files Browse the repository at this point in the history
Accommodate short sheet content
  • Loading branch information
justasm authored Sep 11, 2018
2 parents e2e400a + 3b18426 commit 80d89de
Showing 1 changed file with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,12 @@ public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirect
} else if (mState == STATE_DRAGGING || mState == STATE_SETTLING) {
ViewCompat.offsetTopAndBottom(child, savedTop - child.getTop());
} else if (mState == STATE_ANCHORED) {
ViewCompat.offsetTopAndBottom(child, mAnchorOffset);
if (mAnchorOffset > mMinOffset) {
ViewCompat.offsetTopAndBottom(child, mAnchorOffset);
} else {
mState = STATE_EXPANDED;
ViewCompat.offsetTopAndBottom(child, mMinOffset);
}
}
if (mViewDragHelper == null) {
mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
Expand Down Expand Up @@ -749,22 +754,20 @@ private void calculateTopAndTargetState(View child, float xvel, float yvel, int[
} else {
// not scrolling much, i.e. stationary
int currentTop = child.getTop();
if (currentTop < mAnchorOffset) {
if (Math.abs(currentTop - mMinOffset) < Math.abs(currentTop - mAnchorOffset)) {
top = mMinOffset;
targetState = STATE_EXPANDED;
} else {
top = mAnchorOffset;
targetState = STATE_ANCHORED;
}
int distanceToExpanded = Math.abs(currentTop - mMinOffset);
int distanceToCollapsed = Math.abs(currentTop - mMaxOffset);
int distanceToAnchor = Math.abs(currentTop - mAnchorOffset);
if (mAnchorOffset > mMinOffset
&& distanceToAnchor < distanceToExpanded
&& distanceToAnchor < distanceToCollapsed) {
top = mAnchorOffset;
targetState = STATE_ANCHORED;
} else if (distanceToExpanded < distanceToCollapsed) {
top = mMinOffset;
targetState = STATE_EXPANDED;
} else {
if (Math.abs(currentTop - mMaxOffset) < Math.abs(currentTop - mAnchorOffset)) {
top = mMaxOffset;
targetState = STATE_COLLAPSED;
} else {
top = mAnchorOffset;
targetState = STATE_ANCHORED;
}
top = mMaxOffset;
targetState = STATE_COLLAPSED;
}
}

Expand All @@ -785,7 +788,7 @@ boolean shouldHide(View child, float yvel) {
}

boolean shouldExpand(View child, float yvel) {
if (mSkipAnchored) {
if (mSkipAnchored || mMinOffset >= mAnchorOffset) {
return true;
}
int currentTop = child.getTop();
Expand All @@ -797,7 +800,7 @@ boolean shouldExpand(View child, float yvel) {
}

boolean shouldCollapse(View child, float yvel) {
if (mSkipAnchored) {
if (mSkipAnchored || mMinOffset >= mAnchorOffset) {
return true;
}
int currentTop = child.getTop();
Expand Down Expand Up @@ -838,7 +841,12 @@ void startSettlingAnimation(View child, int state) {
} else if (state == STATE_EXPANDED) {
top = mMinOffset;
} else if (state == STATE_ANCHORED) {
top = mAnchorOffset;
if (mAnchorOffset > mMinOffset) {
top = mAnchorOffset;
} else {
state = STATE_EXPANDED;
top = mMinOffset;
}
} else if (mHideable && state == STATE_HIDDEN) {
top = mParentHeight;
} else {
Expand Down

0 comments on commit 80d89de

Please sign in to comment.