useAMAContext
The hook provides information on various accessibility services and can be used to trigger the AMA error banner.
Usage
import { useAMAContext } from '@react-native-ama/core';
const {
isBoldTextEnabled,
isScreenReaderEnabled,
isGrayscaleEnabled,
isInvertColorsEnabled,
isReduceMotionEnabled,
isReduceTransparencyEnabled,
isHighTextContrastEnabled,
isDarkerSystemColorsEnabled,
reactNavigationScreenOptions,
trackError, // dev mode only
} = useAMAContext();
The trackError function is available only when the DEV flag is true. It is stripped from the production code!
Properties
isReduceTransparencyEnabled
Is true if the user switched on the accessibility setting: Reduce Transparency.
isBoldTextEnabled
Is true if the user switched on the accessibility setting: Bold Text.
isGrayscaleEnabled
Is true if the user switched on the accessibility setting: Grayscale.
isInvertColorsEnabled
Is true if the user switched on the accessibility setting: Invert colors.
isReduceMotionEnabled
Is true if the user switched on the accessibility setting: Reduce motion on iOS or switches off the Animations on Android.
isScreenReaderEnabled
Is true if the user is using a screen reader, like VoiceOver or Talkback.
isHighTextContrastEnabled Android
Is true if the user switched on the accessibility setting: High Text Contrast.
isDarkerSystemColorsEnabled
Is true if the user switched on the accessibility setting: Increase Contrast (Darker System Colors).
reactNavigationScreenOptions
Returns an object to be used for the React Navigation screenOptions prop. It's an object containing the following values:
animationEnabled: boolean;
animation: 'default' | 'fade';
- animationEnabled is true when isReduceMotionEnabled is false
- animation is 'default' when isReduceMotionEnabled is false
Example
const { reactNavigationScreenOptions } = useAMAContext();
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={reactNavigationScreenOptions}>
{/* ... */}
</Stack.Navigator>
</NavigationContainer>
);
Methods
The following methods are only available when DEV is set to
true
trackError
trackError(rule: AmaRule, ref?: React.RefObject<any>): void;
Reports a JS-side accessibility rule failure into the AMA error pipeline. Highlights the offending component in the overlay (using ref to target it) and logs the failure for the given rule.
Parameters
| name | type | required | description |
|---|---|---|---|
| rule | AmaRule | Yes | The accessibility rule that failed (e.g. 'NO_KEYBOARD_TRAP') |
| ref | React.RefObject<any> | No | Ref to the component that failed; used to highlight it in the overlay. If omitted, the error is logged without field-level targeting. |