Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Layout] Adds peek height (min height) to new layout bottom sheets #7103

Merged
merged 7 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7103.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes space list and new chat bottom sheets showing too small in New App Layout (especially evident in landscape)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package im.vector.app.core.extensions

import android.util.DisplayMetrics
import androidx.annotation.FloatRange
import com.google.android.material.bottomsheet.BottomSheetDialog

@Suppress("DEPRECATION")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WindowManager. defaultDisplay and getMetrics are deprecated in 30. Could you add API 30 implementation? And also, please, use suppress on a line, where it's needed, not on whole function

fun BottomSheetDialog.setPeekHeightAsScreenPercentage(@FloatRange(from = 0.0, to = 1.0) percentage: Float) {
val displayMetrics = DisplayMetrics()
window?.windowManager?.defaultDisplay?.getMetrics(displayMetrics)
val height = displayMetrics.heightPixels
behavior.setPeekHeight((height * percentage).toInt(), true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@

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.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.extensions.setPeekHeightAsScreenPercentage
import im.vector.app.databinding.FragmentNewChatBottomSheetBinding
import im.vector.app.features.navigation.Navigator
import javax.inject.Inject
Expand Down Expand Up @@ -53,6 +56,12 @@ class NewChatBottomSheet @Inject constructor() : BottomSheetDialogFragment() {
}
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return super.onCreateDialog(savedInstanceState).apply {
(this as BottomSheetDialog).setPeekHeightAsScreenPercentage(0.5f)
}
}
Copy link
Member

@bmarty bmarty Sep 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All those new BottomSheet should extend VectorBaseBottomSheetDialogFragment, for analytics support and common behavior. This specific treatment could then be moved to the parent, to avoid code duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to make the changes 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!


companion object {
const val TAG = "NewChatBottomSheet"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@

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
import im.vector.app.core.extensions.replaceChildFragment
import im.vector.app.core.extensions.setPeekHeightAsScreenPercentage
import im.vector.app.databinding.FragmentSpacesBottomSheetBinding

class SpaceListBottomSheet : BottomSheetDialogFragment() {
Expand All @@ -37,6 +42,13 @@ class SpaceListBottomSheet : BottomSheetDialogFragment() {
return binding.root
}


override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return super.onCreateDialog(savedInstanceState).apply {
(this as BottomSheetDialog).setPeekHeightAsScreenPercentage(0.75f)
}
}

companion object {
const val TAG = "SpacesBottomSheet"
}
Expand Down