Try to fix the bottom sheet showing expanded by default #2

Seems ok now
This commit is contained in:
Benoit Marty 2019-10-11 11:16:38 +02:00
parent b2f6fb8c91
commit 0bcc84cbd6
5 changed files with 17 additions and 4 deletions

View file

@ -21,6 +21,7 @@ import android.os.Bundle
import android.os.Parcelable
import android.view.View
import android.widget.FrameLayout
import androidx.annotation.CallSuper
import com.airbnb.mvrx.MvRx
import com.airbnb.mvrx.MvRxView
import com.airbnb.mvrx.MvRxViewModelStore
@ -41,6 +42,8 @@ abstract class VectorBaseBottomSheetDialogFragment : BottomSheetDialogFragment()
private lateinit var screenComponent: ScreenComponent
final override val mvrxViewId: String by lazy { mvrxPersistedViewId }
private var bottomSheetBehavior: BottomSheetBehavior<FrameLayout>? = null
val vectorBaseActivity: VectorBaseActivity by lazy {
activity as VectorBaseActivity
}
@ -70,7 +73,8 @@ abstract class VectorBaseBottomSheetDialogFragment : BottomSheetDialogFragment()
val d = dialog as BottomSheetDialog
val bottomSheet = d.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet) as FrameLayout?
BottomSheetBehavior.from(bottomSheet!!).state = BottomSheetBehavior.STATE_EXPANDED
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet!!)
bottomSheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED
}
}
}
@ -89,6 +93,14 @@ abstract class VectorBaseBottomSheetDialogFragment : BottomSheetDialogFragment()
postInvalidate()
}
@CallSuper
override fun invalidate() {
if (showExpanded) {
// Force the bottom sheet to be expanded
bottomSheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED
}
}
protected fun setArguments(args: Parcelable? = null) {
arguments = args?.let { Bundle().apply { putParcelable(MvRx.KEY_ARG, it) } }
}

View file

@ -73,9 +73,7 @@ class DisplayReadReceiptsBottomSheet : VectorBaseBottomSheetDialogFragment() {
epoxyController.setData(displayReadReceiptArgs.readReceipts)
}
override fun invalidate() {
// we are not using state for this one as it's static
}
// we are not using state for this one as it's static, so no need to override invalidate()
companion object {
fun newInstance(readReceipts: List<ReadReceiptData>): DisplayReadReceiptsBottomSheet {

View file

@ -70,6 +70,7 @@ class MessageActionsBottomSheet : VectorBaseBottomSheetDialogFragment(), Message
override fun invalidate() = withState(viewModel) {
messageActionsEpoxyController.setData(it)
super.invalidate()
}
companion object {

View file

@ -74,6 +74,7 @@ class ViewEditHistoryBottomSheet : VectorBaseBottomSheetDialogFragment() {
override fun invalidate() = withState(viewModel) {
epoxyController.setData(it)
super.invalidate()
}
companion object {

View file

@ -71,6 +71,7 @@ class ViewReactionsBottomSheet : VectorBaseBottomSheetDialogFragment() {
override fun invalidate() = withState(viewModel) {
epoxyController.setData(it)
super.invalidate()
}
companion object {