SideSheetBehavior

public class SideSheetBehavior<V extends View>


An interaction behavior plugin for a child view of CoordinatorLayout to make it work as a side sheet.

For more information, see the component developer guidance and design guidelines.

Summary

Nested types

State persisted across instances

Constants

static final int

The sheet is based on the left edge of the screen; it slides from the left edge towards the right.

static final int

The sheet is based on the right edge of the screen; it slides from the right edge towards the left.

static final int

The sheet is dragging.

static final int

The sheet is expanded.

static final int

The sheet is hidden.

static final int

The sheet is settling.

Public fields

float
int

Public constructors

SideSheetBehavior(Context context, AttributeSet attrs)

Public methods

void

Adds a callback to be notified of side sheet events.

void

Call this method from onBackCancelled or handleOnBackCancelled so that the back handler can cancel the back animation.

void

Expand the sheet by setting the side sheet state to STATE_EXPANDED.

static SideSheetBehavior<V>
<V extends View> from(V view)

A utility function to get the SideSheetBehavior associated with the view.

View

Returns the sibling view that is used for coplanar sheet expansion.

int

Returns the sheet's offset from the inner edge when expanded.

float

Gets the friction coefficient to hide the sheet, or set it to the next closest expanded state.

int

Gets the current state of the sheet.

void

Call this method from onBackInvoked or handleOnBackPressed so that the back handler can complete the back animation, or handle back without progress in certain cases.

void

Hide the sheet by setting the sheet state to STATE_HIDDEN.

boolean
void
onAttachedToLayoutParams(LayoutParams layoutParams)
void
boolean
onInterceptTouchEvent(
    CoordinatorLayout parent,
    V child,
    MotionEvent event
)
boolean
onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection)
boolean
onMeasureChild(
    CoordinatorLayout parent,
    V child,
    int parentWidthMeasureSpec,
    int widthUsed,
    int parentHeightMeasureSpec,
    int heightUsed
)
void
onRestoreInstanceState(
    CoordinatorLayout parent,
    V child,
    Parcelable state
)
Parcelable
onSaveInstanceState(CoordinatorLayout parent, V child)
boolean
onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event)
void

Removes a previously added callback.

void
setCoplanarSiblingView(View coplanarSiblingView)

Set the sibling view to use for coplanar sheet expansion.

void
setCoplanarSiblingViewId(int coplanarSiblingViewId)

Set the sibling id to use for coplanar sheet expansion.

void
setDraggable(boolean draggable)

Sets whether this sheet is can be hidden/expanded by dragging.

void
setHideFriction(float hideFriction)

Sets the friction coefficient to hide the sheet, or set it to the next closest expanded state.

void
setState(int state)

Sets the state of the sheet.

void
startBackProgress(BackEventCompat backEvent)

Call this method from onBackStarted or handleOnBackStarted so that the back handler can initialize and start animating.

void
updateBackProgress(BackEventCompat backEvent)

Call this method from onBackProgressed or handleOnBackProgressed so that the back handler can continue animating with a new progress value.

Constants

EDGE_LEFT

public static final int EDGE_LEFT = 1

The sheet is based on the left edge of the screen; it slides from the left edge towards the right.

EDGE_RIGHT

public static final int EDGE_RIGHT = 0

The sheet is based on the right edge of the screen; it slides from the right edge towards the left.

STATE_DRAGGING

public static final int STATE_DRAGGING = 1

The sheet is dragging.

STATE_EXPANDED

public static final int STATE_EXPANDED = 3

The sheet is expanded.

STATE_HIDDEN

public static final int STATE_HIDDEN = 5

The sheet is hidden.

STATE_SETTLING

public static final int STATE_SETTLING = 2

The sheet is settling.

Public fields

hideFriction

public float hideFriction

state

@Sheet.SheetState
public int state

Public constructors

SideSheetBehavior

public SideSheetBehavior()

SideSheetBehavior

public SideSheetBehavior(Context context, AttributeSet attrs)

Public methods

addCallback

public void addCallback(SideSheetCallback callback)

Adds a callback to be notified of side sheet events.

Parameters
SideSheetCallback callback

The callback to notify when side sheet events occur.

cancelBackProgress

public void cancelBackProgress()

Call this method from onBackCancelled or handleOnBackCancelled so that the back handler can cancel the back animation.

expand

public void expand()

Expand the sheet by setting the side sheet state to STATE_EXPANDED. This is a convenience method for setState.

from

public static SideSheetBehavior<V> <V extends View> from(V view)

A utility function to get the SideSheetBehavior associated with the view.

Parameters
V view

The View with SideSheetBehavior.

Returns
SideSheetBehavior<V>

The SideSheetBehavior associated with the view.

getCoplanarSiblingView

public View getCoplanarSiblingView()

Returns the sibling view that is used for coplanar sheet expansion.

getExpandedOffset

public int getExpandedOffset()

Returns the sheet's offset from the inner edge when expanded. It will calculate the offset based on the width of the content.

getHideFriction

public float getHideFriction()

Gets the friction coefficient to hide the sheet, or set it to the next closest expanded state.

Returns
float

The friction coefficient that determines the swipe velocity needed to hide or set the sheet to the closest expanded state.

getState

@Sheet.SheetState
public int getState()

Gets the current state of the sheet.

handleBackInvoked

public void handleBackInvoked()

Call this method from onBackInvoked or handleOnBackPressed so that the back handler can complete the back animation, or handle back without progress in certain cases.

hide

public void hide()

Hide the sheet by setting the sheet state to STATE_HIDDEN. This is a convenience method for setState.

isDraggable

public boolean isDraggable()

onAttachedToLayoutParams

public void onAttachedToLayoutParams(LayoutParams layoutParams)

onDetachedFromLayoutParams

public void onDetachedFromLayoutParams()

onInterceptTouchEvent

public boolean onInterceptTouchEvent(
    CoordinatorLayout parent,
    V child,
    MotionEvent event
)

onLayoutChild

public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection)

onMeasureChild

public boolean onMeasureChild(
    CoordinatorLayout parent,
    V child,
    int parentWidthMeasureSpec,
    int widthUsed,
    int parentHeightMeasureSpec,
    int heightUsed
)

onRestoreInstanceState

public void onRestoreInstanceState(
    CoordinatorLayout parent,
    V child,
    Parcelable state
)

onSaveInstanceState

public Parcelable onSaveInstanceState(CoordinatorLayout parent, V child)

onTouchEvent

public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event)

removeCallback

public void removeCallback(SideSheetCallback callback)

Removes a previously added callback.

Parameters
SideSheetCallback callback

The callback to remove.

setCoplanarSiblingView

public void setCoplanarSiblingView(View coplanarSiblingView)

Set the sibling view to use for coplanar sheet expansion. If a coplanar sibling has previously been set either by this method or via setCoplanarSiblingViewId, that reference will be cleared in favor of this new coplanar sibling reference.

Parameters
View coplanarSiblingView

the sibling view to squash during coplanar expansion

setCoplanarSiblingViewId

public void setCoplanarSiblingViewId(int coplanarSiblingViewId)

Set the sibling id to use for coplanar sheet expansion. If a coplanar sibling has previously been set either by this method or via setCoplanarSiblingView, that View reference will be cleared in favor of this new coplanar sibling reference.

Parameters
int coplanarSiblingViewId

the id of the coplanar sibling

setDraggable

public void setDraggable(boolean draggable)

Sets whether this sheet is can be hidden/expanded by dragging. Note: When disabling dragging, an app will require to implement a custom way to expand/collapse the sheet

ref com.google.android.material.R.styleable#SideSheetBehavior_Layout_behavior_draggable

Parameters
boolean draggable

false to prevent dragging the sheet to collapse and expand

setHideFriction

public void setHideFriction(float hideFriction)

Sets the friction coefficient to hide the sheet, or set it to the next closest expanded state.

Parameters
float hideFriction

The friction coefficient that determines the swipe velocity needed to hide or set the sheet to the closest expanded state.

setState

public void setState(int state)

Sets the state of the sheet. The sheet will transition to that state with animation.

Parameters
int state

One of STATE_EXPANDED or STATE_HIDDEN.

startBackProgress

public void startBackProgress(BackEventCompat backEvent)

Call this method from onBackStarted or handleOnBackStarted so that the back handler can initialize and start animating.

Note that this must be called prior to calling updateBackProgress.

updateBackProgress

public void updateBackProgress(BackEventCompat backEvent)

Call this method from onBackProgressed or handleOnBackProgressed so that the back handler can continue animating with a new progress value.