Skip to content

Commit

Permalink
Add ability to skip the anchored state.
Browse files Browse the repository at this point in the history
  • Loading branch information
justasm committed Sep 10, 2018
1 parent 8422ceb commit e2e400a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
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 mSkipAnchored;

private boolean mDisableExpanded;

@AnchorBottomSheetBehavior.State
Expand Down Expand Up @@ -232,6 +234,7 @@ public AnchorBottomSheetBehavior(Context context, AttributeSet attrs) {
setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false));
setSkipCollapsed(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed,
false));
setSkipAnchored(a.getBoolean(R.styleable.AnchorBottomSheetBehavior_Layout_behavior_skipAnchored, false));
a.recycle();

a = context.obtainStyledAttributes(attrs, R.styleable.AnchorBottomSheetBehavior_Layout);
Expand Down Expand Up @@ -597,6 +600,28 @@ public boolean getSkipCollapsed() {
return mSkipCollapsed;
}

/**
* Sets whether this bottom sheet should skip the anchored state when it is being collapsed from
* an expanded state or when it is being expanded from a collapsed state.
*
* @param skipAnchored True if the bottom sheet should skip the anchored state.
* @attr ref R.styleable#AnchorBottomSheetBehavior_Layout_behavior_skipAnchored
*/
public void setSkipAnchored(boolean skipAnchored) {
mSkipAnchored = skipAnchored;
}

/**
* Sets whether this bottom sheet should skip the anchored state when it is being collapsed from
* an expanded state or when it is being expanded from a collapsed state.
*
* @return Whether the bottom sheet should skip the anchored state.
* @attr ref R.styleable#AnchorBottomSheetBehavior_Layout_behavior_skipAnchored
*/
public boolean getSkipAnchored() {
return mSkipAnchored;
}

public boolean isDisableExpanded() {
return mDisableExpanded;
}
Expand Down Expand Up @@ -760,6 +785,9 @@ boolean shouldHide(View child, float yvel) {
}

boolean shouldExpand(View child, float yvel) {
if (mSkipAnchored) {
return true;
}
int currentTop = child.getTop();
if (currentTop < mAnchorOffset) {
return true;
Expand All @@ -769,6 +797,9 @@ boolean shouldExpand(View child, float yvel) {
}

boolean shouldCollapse(View child, float yvel) {
if (mSkipAnchored) {
return true;
}
int currentTop = child.getTop();
if (currentTop > mAnchorOffset) {
return true;
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<enum name="hidden" value="5" />
<enum name="anchored" value="6" />
</attr>
<attr name="behavior_skipAnchored" format="boolean" />
</declare-styleable>
</resources>

0 comments on commit e2e400a

Please sign in to comment.