Skip to content

Commit 2ec98a0

Browse files
feat: Exposes iOS prefersCrossFadeTransitions
1 parent 48f6967 commit 2ec98a0

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

Libraries/Components/AccessibilityInfo/AccessibilityInfo.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,31 @@ const AccessibilityInfo = {
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 (NativeAccessibilityManagerIOS != null) {
196+
NativeAccessibilityManagerIOS.getCurrentPrefersCrossFadeTransitionsState(
197+
resolve,
198+
reject,
199+
);
200+
} else {
201+
reject(null);
202+
}
203+
}
204+
});
205+
},
206+
182207
/**
183208
* Query whether reduced transparency is currently enabled.
184209
*

Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.js

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ - (instancetype)init
7676
name:UIAccessibilityReduceMotionStatusDidChangeNotification
7777
object:nil];
7878

79+
if (@available(iOS 14.0, *)) {
80+
[[NSNotificationCenter defaultCenter] addObserver:self
81+
selector:@selector(prefersCrossFadeTransitionsStatusDidChange:)
82+
name:UIAccessibilityPrefersCrossFadeTransitionsStatusDidChangeNotification
83+
object:nil];
84+
}
85+
7986
[[NSNotificationCenter defaultCenter] addObserver:self
8087
selector:@selector(reduceTransparencyStatusDidChange:)
8188
name:UIAccessibilityReduceTransparencyStatusDidChangeNotification
@@ -91,6 +98,7 @@ - (instancetype)init
9198
_isGrayscaleEnabled = UIAccessibilityIsGrayscaleEnabled();
9299
_isInvertColorsEnabled = UIAccessibilityIsInvertColorsEnabled();
93100
_isReduceMotionEnabled = UIAccessibilityIsReduceMotionEnabled();
101+
_prefersCrossFadeTransitions = UIAccessibilityPrefersCrossFadeTransitions();
94102
_isReduceTransparencyEnabled = UIAccessibilityIsReduceTransparencyEnabled();
95103
_isVoiceOverEnabled = UIAccessibilityIsVoiceOverRunning();
96104
}
@@ -169,6 +177,19 @@ - (void)reduceMotionStatusDidChange:(__unused NSNotification *)notification
169177
}
170178
}
171179

180+
- (void)prefersCrossFadeTransitionsStatusDidChange:(__unused NSNotification *)notification
181+
{
182+
BOOL newPrefersCrossFadeTransitionsEnabled = UIAccessibilityPrefersCrossFadeTransitions();
183+
if (_prefersCrossFadeTransitions != newPrefersCrossFadeTransitionsEnabled) {
184+
_prefersCrossFadeTransitions = newPrefersCrossFadeTransitionsEnabled;
185+
#pragma clang diagnostic push
186+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
187+
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"prefersCrossFadeTransitionsChanged"
188+
body:@(_prefersCrossFadeTransitions)];
189+
#pragma clang diagnostic pop
190+
}
191+
}
192+
172193
- (void)reduceTransparencyStatusDidChange:(__unused NSNotification *)notification
173194
{
174195
BOOL newReduceTransparencyEnabled = UIAccessibilityIsReduceTransparencyEnabled();
@@ -358,6 +379,13 @@ static void setMultipliers(
358379
onSuccess(@[ @(_isReduceMotionEnabled) ]);
359380
}
360381

382+
RCT_EXPORT_METHOD(getCurrentPrefersCrossFadeTransitionsState
383+
: (RCTResponseSenderBlock)onSuccess onError
384+
: (__unused RCTResponseSenderBlock)onError)
385+
{
386+
onSuccess(@[ @(_prefersCrossFadeTransitions) ]);
387+
}
388+
361389
RCT_EXPORT_METHOD(getCurrentReduceTransparencyState
362390
: (RCTResponseSenderBlock)onSuccess onError
363391
: (__unused RCTResponseSenderBlock)onError)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,11 @@ class DisplayOptionsStatusExample extends React.Component<{}> {
11271127
optionChecker={AccessibilityInfo.isReduceMotionEnabled}
11281128
notification={'reduceMotionChanged'}
11291129
/>
1130+
<DisplayOptionStatusExample
1131+
optionName={'Prefer Cross'}
1132+
optionChecker={AccessibilityInfo.prefersCrossFadeTransitions}
1133+
notification={'prefersCrossFadeTransitionsChanged'}
1134+
/>
11301135
<DisplayOptionStatusExample
11311136
optionName={'Screen Reader'}
11321137
optionChecker={AccessibilityInfo.isScreenReaderEnabled}

0 commit comments

Comments
 (0)