The accessibilityIgnoresInvertColors
property can be used to tell iOS whether or not to invert colors on a view (including all of its subviews) when the Invert Colors accessibility feature is enabled.
This feature can be enabled on iOS via: Settings -> General -> Accessibility -> Display Accommodations -> Invert Colors -> [Smart Invert or Classic Invert]
. Note that the Smart Invert feature will avoid inverting the colors of images and other media without need for accessibilityIgnoresInvertColors
, but Classic Invert will still invert colors on media without accessibilityIgnoresInvertColors
.
accessibilityIgnoresInvertColors
is usually used on elements like <Image />
-- however in some cases it may be used on a parent wrapper.
For example, both of the following snippets are valid (and will achieve the same result in practice).
<View>
<Image accessibilityIgnoresInvertColors={true} />
</View>
<View accessibilityIgnoresInvertColors={true}>
<Image />
</View>
true
: colors of everything in this view will not be inverted when color inversion is enabledfalse
: the default value (unless the view is nested inside a view withaccessibilityIgnoresInvertColors={true}
). Colors in everything contained in this view may be inverted
By default, the rule will only check <Image />
.
If you would like to check additional components which might require accessibilityIgnoresInvertColors
, you can pass an options object which contains invertableComponents
in your ESLint config.
invertableComponents
should be an Array of component names as strings.
"react-native-a11y/has-valid-accessibility-ignores-invert-colors": [
"error",
{
"invertableComponents": [
"FastImage",
"MyCustomComponent",
...
]
}
]
{/* invalid, rule will error */}
<FastImage />
<View>
<FastImage />
</View>
{/* valid */}
<FastImage accessibilityIgnoresInvertColors />
<View accessibilityIgnoresInvertColors>
<FastImage />
</View>
These extra invertableComponents
will also be checked in addition to <Image />
.
<View accessibilityIgnoresInvertColors={true}>
<Image
style={{width: 50, height: 50}}
source={{uri: 'https://facebook.github.io/react-native/img/tiny_logo.png'}}
/>
</View>
<View accessibilityIgnoresInvertColors></View>
<View accessibilityIgnoresInvertColors={false}></View>
<ScrollView accessibilityIgnoresInvertColors={false}></ScrollView>
<View accessibilityIgnoresInvertColors="true">
<Image
style={{width: 50, height: 50}}
source={{uri: 'https://facebook.github.io/react-native/img/tiny_logo.png'}}
/>
</View>
<View accessibilityIgnoresInvertColors={{value: true}}></View>
<View accessibilityIgnoresInvertColors={0}></View>