This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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.
- Loading branch information
Showing
6 changed files
with
204 additions
and
3 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...t/java/org/mozilla/fenix/helpers/idlingresource/BottomSheetBehaviorStateIdlingResource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/androidTest/java/org/mozilla/fenix/helpers/matchers/BottomSheetBehaviorMatchers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters