Skip to content

Commit

Permalink
Fixes after mr
Browse files Browse the repository at this point in the history
  • Loading branch information
gosha212 committed Jul 8, 2024
1 parent 29e8e78 commit 8fc7c6e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import static androidx.test.espresso.matcher.ViewMatchers.isFocused;
import static androidx.test.espresso.matcher.ViewMatchers.isNotChecked;
import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static com.wix.detox.espresso.matcher.ViewMatchers.isDisplayingAtLeastCustom;
import static com.wix.detox.espresso.matcher.ViewMatchers.matcherForDisplayingAtLeast;
import static com.wix.detox.espresso.matcher.ViewMatchers.isMatchingAtIndex;
import static com.wix.detox.espresso.matcher.ViewMatchers.isOfClassName;
import static com.wix.detox.espresso.matcher.ViewMatchers.toHaveSliderPosition;
Expand Down Expand Up @@ -89,7 +89,7 @@ public static Matcher<View> matcherForClass(String className) {
}

public static Matcher<View> matcherForSufficientlyVisible(int pct) {
return isDisplayingAtLeastCustom(pct);
return matcherForDisplayingAtLeast(pct);
}

public static Matcher<View> matcherForNotVisible() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import kotlin.math.min
* Because of an issue with [View.getGlobalVisibleRect], the `isDisplayingAtLeast` matcher does not work
* as expected with React Native views.
* @see [React Native Issue](https://github.com/facebook/react-native/issues/23870)
* The implementation of this matcher is based on the [isDisplayingAtLeast] matcher.
*
* This hack can be removed after proper fix in React Native.
*/
class IsDisplayingAtLeastDetox(private val areaPercentage: Int) : TypeSafeDiagnosingMatcher<View>() {
class IsDisplayingAtLeastDetoxMatcher(private val areaPercentage: Int) : TypeSafeDiagnosingMatcher<View>() {

private val visibilityMatchers = ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)

Expand Down Expand Up @@ -92,25 +93,25 @@ class IsDisplayingAtLeastDetox(private val areaPercentage: Int) : TypeSafeDiagno
* @return The actual visible rectangle of the view.
*/
private fun getGlobalVisibleRectWorkaround(view: View): Rect {
var parent = view.parent as? View
var currentParent = view.parent as? View

val viewVisibleRect = Rect()
view.getGlobalVisibleRect(viewVisibleRect)
val calculatedVisibleRect = Rect()
view.getGlobalVisibleRect(calculatedVisibleRect)

while (parent != null) {
while (currentParent != null) {
val parentVisibleRectangle = Rect()
// Fill the visible rectangle of the parent view
parent.getGlobalVisibleRect(parentVisibleRectangle)
currentParent.getGlobalVisibleRect(parentVisibleRectangle)

// The viewVisibleRect will be replaced with the intersection of the viewVisibleRect and the parentVisibleRectangle
if (!viewVisibleRect.intersect(parentVisibleRectangle)) {
if (!calculatedVisibleRect.intersect(parentVisibleRectangle)) {
return Rect()
}

parent = parent.parent as? View
currentParent = currentParent.parent as? View
}

return viewVisibleRect
return calculatedVisibleRect
}

private fun getScreenWithoutStatusBarActionBar(view: View): Rect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ fun toHaveSliderPosition(expectedValuePct: Double, tolerance: Double): Matcher<V
}
}

fun isDisplayingAtLeastCustom(percents: Int): Matcher<View> =
IsDisplayingAtLeastDetox(percents)
fun matcherForDisplayingAtLeast(percents: Int): Matcher<View> =
IsDisplayingAtLeastDetoxMatcher(percents)

/**
* Same as [androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom], but accepts any class. Needed
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sdk=28
sdk=34

0 comments on commit 8fc7c6e

Please sign in to comment.