STATE_HALF_EXPANDED cannot be disabled while also keeping fitToContents = true based on which the tabs tray layout is currently set. To work around this we'll set a a minuscule height for the tab tray when in this state and then immediately advance to STATE_HIDDEN so to make it imperceptible to the users. Since I couldn't write unit tests because of InflateExceptions in Robolectric I've written UI tests to protect against regressions.upstream-sync
parent
c22ffd392d
commit
172977f698
@ -0,0 +1,56 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.helpers.idlingresource
|
||||
|
||||
import android.view.View
|
||||
import androidx.test.espresso.IdlingResource
|
||||
import androidx.test.espresso.IdlingResource.ResourceCallback
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback
|
||||
|
||||
class BottomSheetBehaviorStateIdlingResource(behavior: BottomSheetBehavior<*>) :
|
||||
BottomSheetCallback(), IdlingResource {
|
||||
|
||||
private var isIdle: Boolean
|
||||
private var callback: ResourceCallback? = null
|
||||
|
||||
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
||||
val wasIdle = isIdle
|
||||
isIdle = isIdleState(newState)
|
||||
if (!wasIdle && isIdle && callback != null) {
|
||||
callback!!.onTransitionToIdle()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSlide(bottomSheet: View, slideOffset: Float) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
override fun getName(): String {
|
||||
return BottomSheetBehaviorStateIdlingResource::class.java.simpleName
|
||||
}
|
||||
|
||||
override fun isIdleNow(): Boolean {
|
||||
return isIdle
|
||||
}
|
||||
|
||||
override fun registerIdleTransitionCallback(callback: ResourceCallback) {
|
||||
this.callback = callback
|
||||
}
|
||||
|
||||
private fun isIdleState(state: Int): Boolean {
|
||||
return state != BottomSheetBehavior.STATE_DRAGGING &&
|
||||
state != BottomSheetBehavior.STATE_SETTLING &&
|
||||
// When detecting STATE_HALF_EXPANDED we immediately transit to STATE_HIDDEN.
|
||||
// Consider this also an intermediary state so not idling.
|
||||
state != BottomSheetBehavior.STATE_HALF_EXPANDED
|
||||
}
|
||||
|
||||
init {
|
||||
behavior.addBottomSheetCallback(this)
|
||||
val state = behavior.state
|
||||
isIdle = isIdleState(state)
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.helpers.matchers
|
||||
|
||||
import android.view.View
|
||||
import androidx.test.espresso.matcher.BoundedMatcher
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import org.hamcrest.Description
|
||||
|
||||
class BottomSheetBehaviorStateMatcher(private val expectedState: Int) :
|
||||
BoundedMatcher<View, View>(View::class.java) {
|
||||
|
||||
override fun describeTo(description: Description?) {
|
||||
description?.appendText("BottomSheetBehavior in state: \"$expectedState\"")
|
||||
}
|
||||
|
||||
override fun matchesSafely(item: View): Boolean {
|
||||
val behavior = BottomSheetBehavior.from(item)
|
||||
return behavior.state == expectedState
|
||||
}
|
||||
}
|
||||
|
||||
class BottomSheetBehaviorHalfExpandedMaxRatioMatcher(private val maxHalfExpandedRatio: Float) :
|
||||
BoundedMatcher<View, View>(View::class.java) {
|
||||
|
||||
override fun describeTo(description: Description?) {
|
||||
description?.appendText(
|
||||
"BottomSheetBehavior with an at max halfExpandedRation: " +
|
||||
"$maxHalfExpandedRatio"
|
||||
)
|
||||
}
|
||||
|
||||
override fun matchesSafely(item: View): Boolean {
|
||||
val behavior = BottomSheetBehavior.from(item)
|
||||
return behavior.halfExpandedRatio <= maxHalfExpandedRatio
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue