Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwitchCompat in a ConstraintLayout in a NestedScrollView has inaccurate height #6043

Closed
mezpahlan opened this issue Nov 4, 2020 · 0 comments · Fixed by #6047
Closed

SwitchCompat in a ConstraintLayout in a NestedScrollView has inaccurate height #6043

mezpahlan opened this issue Nov 4, 2020 · 0 comments · Fixed by #6047

Comments

@mezpahlan
Copy link

mezpahlan commented Nov 4, 2020

Description

SwitchCompat inside a ConstraintLayout inside a NestedScrollView has a height of height=16777214 which causes operations like isCompletelyDisplayed() to fail. This also prevents clicks for a similar reason if you have several switches in the same layout.

Steps to Reproduce

  1. Checkout the git repo reproducing the problem. Specifically the MainFragmentTest class and the main_fragment layout
  2. Run the linked test.

Expected Result

The test passes and the height is reported at a sensible value.

Actual Result

The test fails and the height is reported as 16777214

androidx.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'at least 100 percent of the view's area is displayed to the user.' doesn't match the selected view.
Expected: at least 100 percent of the view's area is displayed to the user.
Got: "SwitchCompat{id=2131231095, res-name=switch_compat_2, visibility=VISIBLE, width=320, height=16777214, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=androidx.constraintlayout.widget.ConstraintLayout$LayoutParams@54738eaa, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=1.6777216E7, text=Don't Switch Me, input-type=0, ime-target=false, has-links=false, is-checked=false}"

Note that if I change the view reference to the top most SwitchCompat the test passes. This also passes if I only have a single item inside the ConstraintLayout.

Also note that in the design editor in Android Studio the SwitchCompat looks normal, as it does when you run the app on a device.

Screenshot from 2020-11-04 23-07-55

Robolectric & Android Version

Roblectric 4.4
Android 7 - SDK / API 24

Link to a public git repo demonstrating the problem:

Minimal project to reproduce a bug with SwitchCompat NestedScrollView and Robolectric

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant