Adds API 30 compatible method

This commit is contained in:
ericdecanini 2022-09-13 16:21:36 -04:00
parent 55c60c9a40
commit 85f16e8dfa
2 changed files with 19 additions and 4 deletions

View file

@ -16,13 +16,31 @@
package im.vector.app.core.extensions
import android.os.Build
import android.util.DisplayMetrics
import androidx.annotation.FloatRange
import androidx.annotation.RequiresApi
import com.google.android.material.bottomsheet.BottomSheetDialog
@Suppress("DEPRECATION")
fun BottomSheetDialog.setPeekHeightAsScreenPercentage(@FloatRange(from = 0.0, to = 1.0) percentage: Float) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
setPeekHeightPostApi30(percentage)
} else {
setPeekHeightPreApi30(percentage)
}
}
@RequiresApi(Build.VERSION_CODES.R)
private fun BottomSheetDialog.setPeekHeightPostApi30(percentage: Float) {
window?.windowManager?.currentWindowMetrics?.let { windowMetrics ->
val height = windowMetrics.bounds.height()
behavior.setPeekHeight((height * percentage).toInt(), true)
}
}
private fun BottomSheetDialog.setPeekHeightPreApi30(percentage: Float) {
val displayMetrics = DisplayMetrics()
@Suppress("DEPRECATION")
window?.windowManager?.defaultDisplay?.getMetrics(displayMetrics)
val height = displayMetrics.heightPixels
behavior.setPeekHeight((height * percentage).toInt(), true)

View file

@ -18,11 +18,9 @@ package im.vector.app.features.spaces
import android.app.Dialog
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.FloatRange
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import im.vector.app.R
@ -42,7 +40,6 @@ class SpaceListBottomSheet : BottomSheetDialogFragment() {
return binding.root
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return super.onCreateDialog(savedInstanceState).apply {
(this as BottomSheetDialog).setPeekHeightAsScreenPercentage(0.75f)