An open API service indexing awesome lists of open source software.

https://github.com/emanprague/bottom-sheet

Implementation of Google's Bottom Sheet which was modified to fully support two peek heights.
https://github.com/emanprague/bottom-sheet

android android-library bottomsheet java

Last synced: 3 months ago
JSON representation

Implementation of Google's Bottom Sheet which was modified to fully support two peek heights.

Awesome Lists containing this project

README

          

# Bottom Sheet with two peek heights

[ ![Download](https://api.bintray.com/packages/emanprague/maven/cz.eman.bottomsheet/images/download.svg?version=1.0.0) ](https://bintray.com/emanprague/maven/cz.eman.bottomsheet/1.0.0/link)

This repository contains implementation of Google's Bottom Sheet which was modified to fully support two peek heights.

## Contents

Repository consists of two modules:
- `app` - sample application which implements required interfaces
- `sheet` - library

## Quickstart

First of all add link `bottom-sheet` library to your project.

```groovy
// Gradle Kotlin DSL
implementation("cz.eman.bottomsheet:bottomsheet:1.0.0")
// Groovy
implementation 'cz.eman.bottomsheet:bottomsheet:1.0.0'
```

Now let's create a layout for our view. You will need:
- `background_container` - container which will contain fragment that sheet will overlap (probably map)
- `coordinator_layout` - do not forget to include id of layout or `CoordinatorLayout` will not restore instance state
- `bottom_sheet` - our sheet will inflate into this layout
- `sheet_container` - place sheet container here

Here's sample:

```xml









```

Then in your code initialize your sheet. You can do it manually, or you can use our handy `SheetHelper`.
By default you'll need to just specify two peek heights - collapsed (smaller) and semi-collapsed (bigger).

```kotlin
val helper = SheetsHelper.Builder(context = this, sheetView = this).apply {
setCollapsedHeight(resources.getDimensionPixelSize(R.dimen.sheet_collapsed_height))
setSemiCollapsedHeight(resources.getDimensionPixelSize(R.dimen.sheet_semicollapsed_height))
}.build()
```

Then just attach sheet with helper depending on your desires.
- `SheetHelper#init(View, BottomSheet)` - initializes with two collapsed states as defined in builder
- `SheetHelper#initSemiCollapsed(View, BottomSheet)` - initializes with only collapsed state (semi-collapsed) as defined in builder
- `SheetHelper#initCollapsed(View, BottomSheet)` - initializes with only collapsed state (collapsed) as defined in builder

```kotlin
helper.init(bottomSheet, behavior)
helper.initSemiCollapsed(bottomSheet, behavior)
helper.initCollapsed(bottomSheet, behavior)
```

Changing states is also really easy - image that your sheet now supports two collapsed states and you want to change it to just one bigger. No problem, call one of these:
```java
helper.animateToSemiCollapsed()
helper.restoreSemiCollapsedState()
```

Want to restore two collapsed states behaviour? Pick one of these:
```kotlin
helper.animateToTwoStates()
helper.restoreTwoStates()
```