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

https://github.com/prongbang/bottomsheetdialog

Custom Bottom Sheet Dialog Example
https://github.com/prongbang/bottomsheetdialog

Last synced: 5 months ago
JSON representation

Custom Bottom Sheet Dialog Example

Awesome Lists containing this project

README

          

# BottomSheetDialog ๐Ÿ“ฑ

[![](https://jitpack.io/v/prongbang/BottomSheetDialog.svg)](https://jitpack.io/#prongbang/BottomSheetDialog)
[![](https://jitpack.io/v/prongbang/BottomSheetDialog/month.svg)](https://jitpack.io/#prongbang/BottomSheetDialog)
[![Android](https://img.shields.io/badge/platform-Android-green.svg)](https://developer.android.com)
[![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=21)
[![Kotlin](https://img.shields.io/badge/kotlin-1.5.x-orange.svg)](https://kotlinlang.org)

> Create beautiful and customizable bottom sheet dialogs for Android with minimal setup.

## โœจ Features

- ๐ŸŽจ **Fully Customizable** - Design your own bottom sheet layout
- ๐Ÿš€ **Easy Integration** - Simple builder pattern implementation
- ๐Ÿ“ฑ **Material Design** - Follows Material Design guidelines
- ๐Ÿ”„ **Lifecycle Aware** - Properly handles configuration changes
- ๐ŸŽฏ **Type-Safe** - Written in Kotlin with type safety in mind

## ๐Ÿ“ธ Preview


Bottom Sheet Dialog Demo

## ๐Ÿ“ฆ Installation

### Step 1: Add JitPack repository

Add it in your root `build.gradle` at the end of repositories:

```groovy
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
```

### Step 2: Add the dependency

For AndroidX:

```groovy
dependencies {
implementation 'com.github.prongbang:bottomsheetdialog:1.0.0'
}
```

## ๐Ÿš€ Quick Start

### 1. Create your bottom sheet layout

```xml



```

### 2. Create your BottomSheetDialogFragment

```kotlin
class MyBottomSheetDialogFragment(
supportFragmentManager: FragmentManager
) : SmartBottomSheetDialogFragment(supportFragmentManager) {

override fun tagName(): String = MyBottomSheetDialogFragment::class.java.simpleName

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.bottom_sheet_layout, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initView()
}

private fun initView() {
arguments?.let { args ->
// Get values by key
val title = args.getString(TITLE_KEY)
val subtitle = args.getString(SUBTITLE_KEY)
val avatarUrl = args.getString(AVATAR_URL_KEY)

// Set up your views
}
}

class Builder(
private val fragmentManager: FragmentManager
) : SmartBottomSheetDialogFragment.Builder() {

private var onCloseListener: (() -> Unit)? = null

fun setTitle(title: String) = apply {
argumentsBundle.putString(TITLE_KEY, title)
}

fun setSubtitle(subtitle: String) = apply {
argumentsBundle.putString(SUBTITLE_KEY, subtitle)
}

fun setAvatar(avatarUrl: String) = apply {
argumentsBundle.putString(AVATAR_URL_KEY, avatarUrl)
}

fun setOnCloseButton(listener: () -> Unit) = apply {
onCloseListener = listener
}

override fun build(): MyBottomSheetDialogFragment {
return MyBottomSheetDialogFragment(fragmentManager).apply {
arguments = argumentsBundle.apply {
onClickCloseListener = onCloseListener
}
}
}
}

companion object {
private const val TITLE_KEY = "TITLE_KEY"
private const val SUBTITLE_KEY = "SUBTITLE_KEY"
private const val AVATAR_URL_KEY = "AVATAR_URL_KEY"
}
}
```

### 3. Show the bottom sheet

```kotlin
// In your Activity or Fragment
MyBottomSheetDialogFragment.Builder(supportFragmentManager)
.setAvatar(avatarUrl)
.setTitle("เน€เธ”เธŸเน„เธ›เธงเธฑเธ™เน†")
.setSubtitle("https://prongbang.github.io")
.setOnCloseButton {
Toast.makeText(this, "Bottom Sheet Dialog Closed", Toast.LENGTH_SHORT).show()
}
.build()
.show()
```

## ๐Ÿ”ง Advanced Usage

### Custom Styling

```xml

<item name="bottomSheetStyle">@style/CustomBottomSheet</item>

<item name="android:background">@drawable/custom_bottom_sheet_background</item>

```

### Handle State Changes

```kotlin
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

// Get bottom sheet behavior
val bottomSheetBehavior = BottomSheetBehavior.from(view.parent as View)

// Set state change callback
bottomSheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {
when (newState) {
BottomSheetBehavior.STATE_EXPANDED -> {
// Handle expanded state
}
BottomSheetBehavior.STATE_COLLAPSED -> {
// Handle collapsed state
}
BottomSheetBehavior.STATE_HIDDEN -> {
dismiss()
}
}
}

override fun onSlide(bottomSheet: View, slideOffset: Float) {
// Handle slide offset
}
})
}
```

## ๐Ÿ“ Pro Tips

1. **Remember to add behavior** - Always add `app:layout_behavior="@string/bottom_sheet_behavior"` to your root layout
2. **Handle configuration changes** - The builder pattern helps maintain state across configuration changes
3. **Custom animations** - Override `setupDialog()` to customize enter/exit animations
4. **Peek height** - Adjust the initial visible height using `BottomSheetBehavior.setPeekHeight()`

## ๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ’– Support

If you find this library helpful, please consider giving it a โญ๏ธ and buying me a coffee!

[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/prongbang)

---