Skip to content

Commit be7c50f

Browse files
gabrieldonadelfacebook-github-bot
authored andcommitted
feat: Add support for "Prefer Cross-Fade Transitions" into AccessibilityInfo (#34406)
Summary: This PR adds `prefersCrossFadeTransitions()` to AccessibilityInfo in order to add support for "Prefer Cross-Fade Transitions", exposing the iOS settings option as proposed here react-native-community/discussions-and-proposals#452. I believe this would be especially helpful for solving #31484 #### TODO - [ ] Submit react-native-web PR updating AccessibilityInfo documentation. ## Changelog [iOS] [Added] - Add support for "Prefer Cross-Fade Transitions" into AccessibilityInfo Pull Request resolved: #34406 Test Plan: **On iOS 14+** 1. Access Settings > "General" > "Accessibility" > "Reduce Motion", enable "Reduce Motion" then enable "Prefer Cross-Fade Transitions". 2. Open the RNTester app and navigate to the Accessibility page https://user-images.githubusercontent.com/11707729/154588402-7d050858-3c2d-4d86-9585-928b8c66941b.mov Reviewed By: cipolleschi Differential Revision: D38711316 Pulled By: makovkastar fbshipit-source-id: b9965cd4285f1aa0f1fa927080370a22329c2f62
1 parent e6ef083 commit be7c50f

File tree

7 files changed

+60
-0
lines changed

7 files changed

+60
-0
lines changed

Libraries/Components/AccessibilityInfo/AccessibilityInfo.flow.js

+10
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ export interface AccessibilityInfo {
8585
*/
8686
isReduceMotionEnabled: () => Promise<boolean>;
8787

88+
/**
89+
* Query whether reduce motion and prefer cross-fade transitions settings are currently enabled.
90+
*
91+
* Returns a promise which resolves to a boolean.
92+
* The result is `true` when prefer cross-fade transitions is enabled and `false` otherwise.
93+
*
94+
* See https://reactnative.dev/docs/accessibilityinfo#prefersCrossFadeTransitions
95+
*/
96+
prefersCrossFadeTransitions: () => Promise<boolean>;
97+
8898
/**
8999
* Query whether reduced transparency is currently enabled.
90100
*

Libraries/Components/AccessibilityInfo/AccessibilityInfo.js

+28
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,34 @@ const AccessibilityInfo: AccessibilityInfoType = {
179179
});
180180
},
181181

182+
/**
183+
* Query whether reduce motion and prefer cross-fade transitions settings are currently enabled.
184+
*
185+
* Returns a promise which resolves to a boolean.
186+
* The result is `true` when prefer cross-fade transitions is enabled and `false` otherwise.
187+
*
188+
* See https://reactnative.dev/docs/accessibilityinfo#prefersCrossFadeTransitions
189+
*/
190+
prefersCrossFadeTransitions(): Promise<boolean> {
191+
return new Promise((resolve, reject) => {
192+
if (Platform.OS === 'android') {
193+
return Promise.resolve(false);
194+
} else {
195+
if (
196+
NativeAccessibilityManagerIOS?.getCurrentPrefersCrossFadeTransitionsState !=
197+
null
198+
) {
199+
NativeAccessibilityManagerIOS.getCurrentPrefersCrossFadeTransitionsState(
200+
resolve,
201+
reject,
202+
);
203+
} else {
204+
reject(null);
205+
}
206+
}
207+
});
208+
},
209+
182210
/**
183211
* Query whether reduced transparency is currently enabled.
184212
*

Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.js

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export interface Spec extends TurboModule {
2828
onSuccess: (isReduceMotionEnabled: boolean) => void,
2929
onError: (error: Object) => void,
3030
) => void;
31+
+getCurrentPrefersCrossFadeTransitionsState?: (
32+
onSuccess: (prefersCrossFadeTransitions: boolean) => void,
33+
onError: (error: Object) => void,
34+
) => void;
3135
+getCurrentReduceTransparencyState: (
3236
onSuccess: (isReduceTransparencyEnabled: boolean) => void,
3337
onError: (error: Object) => void,

React/CoreModules/RCTAccessibilityManager.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extern NSString *const RCTAccessibilityManagerDidUpdateMultiplierNotification; /
2323
@property (nonatomic, assign) BOOL isGrayscaleEnabled;
2424
@property (nonatomic, assign) BOOL isInvertColorsEnabled;
2525
@property (nonatomic, assign) BOOL isReduceMotionEnabled;
26+
@property (nonatomic, assign) BOOL prefersCrossFadeTransitions;
2627
@property (nonatomic, assign) BOOL isReduceTransparencyEnabled;
2728
@property (nonatomic, assign) BOOL isVoiceOverEnabled;
2829

React/CoreModules/RCTAccessibilityManager.mm

+11
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,17 @@ static void setMultipliers(
358358
onSuccess(@[ @(_isReduceMotionEnabled) ]);
359359
}
360360

361+
RCT_EXPORT_METHOD(getCurrentPrefersCrossFadeTransitionsState
362+
: (RCTResponseSenderBlock)onSuccess onError
363+
: (__unused RCTResponseSenderBlock)onError)
364+
{
365+
if (@available(iOS 14.0, *)) {
366+
onSuccess(@[ @(UIAccessibilityPrefersCrossFadeTransitions()) ]);
367+
} else {
368+
onSuccess(@[ @(false) ]);
369+
}
370+
}
371+
361372
RCT_EXPORT_METHOD(getCurrentReduceTransparencyState
362373
: (RCTResponseSenderBlock)onSuccess onError
363374
: (__unused RCTResponseSenderBlock)onError)

jest/setup.js

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ jest
128128
isGrayscaleEnabled: jest.fn(),
129129
isInvertColorsEnabled: jest.fn(),
130130
isReduceMotionEnabled: jest.fn(),
131+
prefersCrossFadeTransitions: jest.fn(),
131132
isReduceTransparencyEnabled: jest.fn(),
132133
isScreenReaderEnabled: jest.fn(() => Promise.resolve(false)),
133134
setAccessibilityFocus: jest.fn(),

packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js

+5
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,11 @@ class DisplayOptionsStatusExample extends React.Component<{}> {
11831183
optionChecker={AccessibilityInfo.isReduceMotionEnabled}
11841184
notification={'reduceMotionChanged'}
11851185
/>
1186+
<DisplayOptionStatusExample
1187+
optionName={'Prefer Cross-Fade Transitions'}
1188+
optionChecker={AccessibilityInfo.prefersCrossFadeTransitions}
1189+
notification={'prefersCrossFadeTransitionsChanged'}
1190+
/>
11861191
<DisplayOptionStatusExample
11871192
optionName={'Screen Reader'}
11881193
optionChecker={AccessibilityInfo.isScreenReaderEnabled}

0 commit comments

Comments
 (0)