Skip to content

prongbang/BottomSheetDialog

Repository files navigation

Custom Bottom Sheet Dialog Example

"Buy Me A Coffee"

Result

screenshot gif

Download

build.gradle

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

AndroidX

implementation 'com.github.prongbang:bottomsheetdialog:1.0.0'

How to use

Add in bottom_sheet_layout.xml

app:layout_behavior="@string/bottom_sheet_behavior"

MyBottomSheetDialogFragment.kt

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 value by key
		}
	}

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

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

		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"
	}
}

Use in Activity

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()

Enjoy :V

About

Custom Bottom Sheet Dialog Example

Resources

License

Stars

Watchers

Forks

Packages

No packages published