Skip to content

Instantly share code, notes, and snippets.

@owaistnt
Last active July 13, 2021 18:45
Show Gist options
  • Save owaistnt/e2af268ffa5d98925c9445b17f189f6e to your computer and use it in GitHub Desktop.
Save owaistnt/e2af268ffa5d98925c9445b17f189f6e to your computer and use it in GitHub Desktop.
FullScreenBottomSheet Demo
package com.artsman.fullscreenbottomsheet
import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.LinearLayout
import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.artsman.fullscreenbottomsheet.databinding.LayoutDialogBinding
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
class BottomSheet : BottomSheetDialogFragment() {
lateinit var bottomSheetBehavior: BottomSheetBehavior<FrameLayout>
lateinit var bi: LayoutDialogBinding
private fun getWindowHeight() = resources.displayMetrics.heightPixels
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
bi=LayoutDialogBinding.inflate(layoutInflater)
bi.btnClose.setOnClickListener {
dialog?.cancel()
}
return bi.root
}
override fun onStart() {
super.onStart()
//Get the bottom_sheet of the system
val view: FrameLayout = dialog?.findViewById(R.id.design_bottom_sheet)!!
//Set the view height
view.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
//Get behavior
val behavior = BottomSheetBehavior.from(view)
//Set the pop-up height
behavior.peekHeight = getWindowHeight()
//Set the expanded state
behavior.state = BottomSheetBehavior.STATE_EXPANDED
behavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback(){
override fun onStateChanged(bottomSheet: View, newState: Int) {
if(newState==BottomSheetBehavior.STATE_COLLAPSED){
//dismiss()
}
}
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment