Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable collapsed state #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ public void onSlide(@NonNull View bottomSheet, float slideOffset) {

private boolean mSkipCollapsed;

private boolean mDisableCollapsed;

private boolean mDisableExpanded;

@AnchorBottomSheetBehavior.State
Expand Down Expand Up @@ -288,9 +290,8 @@ public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirect
peekHeight = mPeekHeight;
}
mMinOffset = Math.max(0, mParentHeight - child.getHeight());
if (mDisableExpanded) {
mMinOffset = mAnchorOffset;
}
updateConstraints();

mMaxOffset = Math.max(mParentHeight - peekHeight, mMinOffset);
if (mState == STATE_EXPANDED) {
ViewCompat.offsetTopAndBottom(child, mMinOffset);
Expand Down Expand Up @@ -534,9 +535,7 @@ public final void setAnchorOffset(int anchorOffset) {
if (mAnchorOffset != anchorOffset) {
mAnchorOffset = anchorOffset;

if (mDisableExpanded) {
mMinOffset = mAnchorOffset;
}
updateConstraints();

if (mState == STATE_ANCHORED) {
setStateInternal(STATE_SETTLING);
Expand All @@ -545,6 +544,16 @@ public final void setAnchorOffset(int anchorOffset) {
}
}

private void updateConstraints() {
if (mDisableExpanded) {
mMinOffset = mAnchorOffset;
}

if (mDisableCollapsed) {
mPeekHeight = mAnchorOffset;
}
}

/**
* Gets the offset of the bottom sheet when it is anchored.
*
Expand Down Expand Up @@ -597,6 +606,14 @@ public boolean getSkipCollapsed() {
return mSkipCollapsed;
}

public boolean isDisableCollapsed() {
return mDisableCollapsed;
}

public void setDisableCollapsed(boolean mDisableCollapsed) {
this.mDisableCollapsed = mDisableCollapsed;
}

public boolean isDisableExpanded() {
return mDisableExpanded;
}
Expand Down