Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native can't find child elements when accessible is true

Tags:

react-native

With this JSX:

<View>
  <Text testID='t1'>text 1</Text>
  <Text testID='t2'>text 2</Text>
</View>

I can find the child elements by their testID (e.g. with Appium)

If I change the View to a TouchableOpacity the child elements seem to be gathered together into a single UIAElement on iOS and then can't be found.

It looks like TouchableOpacity has its accessible property hardcoded to true and that enables the gathering behaviour (see https://code.facebook.com/posts/435862739941212/making-react-native-apps-accessible/)

Is this expected behaviour? It makes testing quite difficult.

like image 885
jonesdar Avatar asked Feb 09 '16 11:02

jonesdar


1 Answers

Any element or component that is touchable is defaulted to accessible={true}. If you do not want them grouped together, try this:

<View accessible={false}>
  <Text testID='t1'>text 1</Text>
  <Text testID='t2'>text 2</Text>
</View>

This should allow the children to become their one elements, instead of one element (the view element).

like image 50
jeffbumgardner Avatar answered Nov 13 '22 14:11

jeffbumgardner