Skip to content

Commit f98e489

Browse files
authored
Incubator.Dialog - support reduce motion (accessibility) (#3755)
* Incubator.Dialog - support reduce motion (accessibility) * Fix tests
1 parent bc1bfdc commit f98e489

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/commons/Constants.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,24 @@ export function updateConstants(dimensions: any) {
6767
}
6868

6969
const accessibility = {
70+
isReduceMotionEnabled: false,
7071
isScreenReaderEnabled: false
7172
};
7273

74+
function handleReduceMotionChanged(isReduceMotionEnabled: AccessibilityChangeEvent) {
75+
accessibility.isReduceMotionEnabled = isReduceMotionEnabled as boolean;
76+
}
77+
7378
function handleScreenReaderChanged(isScreenReaderEnabled: AccessibilityChangeEvent) {
7479
accessibility.isScreenReaderEnabled = isScreenReaderEnabled as boolean;
7580
}
7681

82+
AccessibilityInfo.addEventListener('reduceMotionChanged', handleReduceMotionChanged);
7783
AccessibilityInfo.addEventListener('screenReaderChanged', handleScreenReaderChanged);
7884

79-
function setAccessibility() {
80-
AccessibilityInfo.isScreenReaderEnabled().then(isScreenReaderEnabled => {
81-
accessibility.isScreenReaderEnabled = isScreenReaderEnabled;
82-
});
85+
async function setAccessibility() {
86+
accessibility.isReduceMotionEnabled = await AccessibilityInfo.isReduceMotionEnabled();
87+
accessibility.isScreenReaderEnabled = await AccessibilityInfo.isScreenReaderEnabled();
8388
}
8489

8590
setAccessibility();

src/incubator/dialog/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,14 @@ const Dialog = (props: DialogProps, ref: ForwardedRef<DialogImperativeMethods>)
212212

213213
const renderDialog = () => (
214214
<GestureDetector gesture={panGesture}>
215-
<View {...containerProps} reanimated style={style} onLayout={onLayout} ref={setRef} testID={testID}>
215+
<View
216+
{...containerProps}
217+
reanimated={!Constants.accessibility.isReduceMotionEnabled}
218+
style={style}
219+
onLayout={onLayout}
220+
ref={setRef}
221+
testID={testID}
222+
>
216223
{renderDialogContent()}
217224
</View>
218225
</GestureDetector>

0 commit comments

Comments
 (0)