- BottomSheetBehavior에 콜백을 등록하는 setBottomSheetCallback 메서드가 deprecated 되었길래 대응했다.
- addBottomSheetCallback 및 removeBottomSheetCallback으로 대응 가능하다.
https://stackoverflow.com/questions/59343490/setbottomsheetcallback-is-deprecated
setBottomSheetCallback is deprecated
while developing an app for object detection using ml kit firebise, i've implemented my bottom sheet but it's not working,so the camera still focused on the object without any result. code: privat...
stackoverflow.com
- 단, 실제 보이는 onShow 시점에 콜백을 추가해주어야 한다.
dialog.setOnShowListener {
val layoutParams = (contentView.parent as View).layoutParams as CoordinatorLayout.LayoutParams
sheetBehavior = layoutParams.behavior as BottomSheetBehavior<*>?
if (sheetBehavior == null) return@setOnShowListener
sheetBehavior?.addBottomSheetCallback(mBottomSheetBehaviorCallback)
- BottomSheetDialog는 내부에 design_bottom_sheet라는 실제 BottomSheet 컨테이너(FrameLayout)를 만들고, 거기에 BottomSheetBehavior가 달리게 된다.
- onShow 외부인 contentView.parent의 layoutParams.behavior를 쓰면, 그 부모가 CoordinatorLayout인 경우엔 원하는 Behavior가 아닐 수 있기 때문에 add 메서드를 활용해도 실제 BottomSheet가 표시되지 않을 수 있다.
- 그리고 메모리 자원 누수를 고려하여 onDestroyView()에서 아래 코드 추가
override fun onDestroyView() {
sheetBehavior?.removeBottomSheetCallback(mBottomSheetBehaviorCallback)
sheetBehavior = null
super.onDestroyView()
}