Skip to content

Commit

Permalink
Try to fix the bottom sheet showing expanded by default #2
Browse files Browse the repository at this point in the history
Seems ok now
  • Loading branch information
bmarty committed Oct 21, 2019
1 parent b2f6fb8 commit 0bcc84c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
}
}
Expand All @@ -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) } }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class MessageActionsBottomSheet : VectorBaseBottomSheetDialogFragment(), Message

override fun invalidate() = withState(viewModel) {
messageActionsEpoxyController.setData(it)
super.invalidate()
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ViewEditHistoryBottomSheet : VectorBaseBottomSheetDialogFragment() {

override fun invalidate() = withState(viewModel) {
epoxyController.setData(it)
super.invalidate()
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ViewReactionsBottomSheet : VectorBaseBottomSheetDialogFragment() {

override fun invalidate() = withState(viewModel) {
epoxyController.setData(it)
super.invalidate()
}

companion object {
Expand Down

0 comments on commit 0bcc84c

Please sign in to comment.