Merge pull request #7103 from vector-im/bugfix/eric/landscape-bottom-sheet-peek

[New Layout] Adds peek height (min height) to new layout bottom sheets
This commit is contained in:
Eric Decanini 2022-09-15 10:03:11 -04:00 committed by GitHub
commit 01e1d74c72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 15 deletions

1
changelog.d/7103.bugfix Normal file
View file

@ -0,0 +1 @@
Fixes space list and new chat bottom sheets showing too small in New App Layout (especially evident in landscape)

View file

@ -25,6 +25,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.annotation.CallSuper
import androidx.annotation.FloatRange
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.viewbinding.ViewBinding
@ -39,6 +40,7 @@ import im.vector.app.core.extensions.toMvRxBundle
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.analytics.plan.MobileScreen
import io.github.hyuwah.draggableviewlib.Utils
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import reactivecircus.flowbinding.android.view.clicks
@ -165,6 +167,13 @@ abstract class VectorBaseBottomSheetDialogFragment<VB : ViewBinding> : BottomShe
forceExpandState()
}
protected fun setPeekHeightAsScreenPercentage(@FloatRange(from = 0.0, to = 1.0) percentage: Float) {
context?.let {
val screenHeight = Utils.getScreenHeight(it)
bottomSheetBehavior?.setPeekHeight((screenHeight * percentage).toInt(), true)
}
}
protected fun forceExpandState() {
if (showExpanded) {
// Force the bottom sheet to be expanded

View file

@ -16,43 +16,50 @@
package im.vector.app.features.home.room.list.home
import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.databinding.FragmentNewChatBottomSheetBinding
import im.vector.app.features.navigation.Navigator
import javax.inject.Inject
@AndroidEntryPoint
class NewChatBottomSheet : BottomSheetDialogFragment() {
class NewChatBottomSheet : VectorBaseBottomSheetDialogFragment<FragmentNewChatBottomSheetBinding>() {
@Inject lateinit var navigator: Navigator
private lateinit var binding: FragmentNewChatBottomSheetBinding
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentNewChatBottomSheetBinding {
return FragmentNewChatBottomSheetBinding.inflate(inflater, container, false)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = FragmentNewChatBottomSheetBinding.inflate(inflater, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
initFABs()
return binding.root
}
private fun initFABs() {
binding.startChat.setOnClickListener {
views.startChat.debouncedClicks {
navigator.openCreateDirectRoom(requireActivity())
}
binding.createRoom.setOnClickListener {
views.createRoom.debouncedClicks {
navigator.openCreateRoom(requireActivity())
}
binding.exploreRooms.setOnClickListener {
views.exploreRooms.debouncedClicks {
navigator.openRoomDirectory(requireContext())
}
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return super.onCreateDialog(savedInstanceState).apply {
setPeekHeightAsScreenPercentage(0.5f)
}
}
companion object {
const val TAG = "NewChatBottomSheet"
}

View file

@ -16,25 +16,32 @@
package im.vector.app.features.spaces
import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import im.vector.app.R
import im.vector.app.core.extensions.replaceChildFragment
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.databinding.FragmentSpacesBottomSheetBinding
class SpaceListBottomSheet : BottomSheetDialogFragment() {
class SpaceListBottomSheet : VectorBaseBottomSheetDialogFragment<FragmentSpacesBottomSheetBinding>() {
private lateinit var binding: FragmentSpacesBottomSheetBinding
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentSpacesBottomSheetBinding {
return FragmentSpacesBottomSheetBinding.inflate(inflater, container, false)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = FragmentSpacesBottomSheetBinding.inflate(inflater, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
if (savedInstanceState == null) {
replaceChildFragment(R.id.space_list, SpaceListFragment::class.java)
}
return binding.root
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return super.onCreateDialog(savedInstanceState).apply {
setPeekHeightAsScreenPercentage(0.75f)
}
}
companion object {