Commit 57c073f
Fix AccessibilityInfo.prefersCrossFadeTransitions unresolved promise (facebook#55920)
Summary:
This PR fixes a bug I found while exploring the codebase in the `Components` folder.
`AccessibilityInfo` exposes the method `prefersCrossFadeTransitions`. In the android branch, `Promise.resolve(false)` as return value was creating a new unrelated promise that never calls the resolve function provided by the promise executor constructor, so it was hangs indefinitely.
This means that if a user calls this method on android without any `Platform.OS === ios` guard, it will result in a unresolved promise.
I fixed the bug by aligning the implementation of `prefersCrossFadeTransitions` to the one of other methods (eg. `isBoldTextEnabled`).
I also added the tests to avoid regression, and additionally verify that the iOS method is doing what we are expecting (in both cases for when `NativeAccessibilityManagerIOS.getCurrentPrefersCrossFadeTransitionsState` is available or not).
The mock of the `Platform` object has been done the same way I saw while doing another contribution in the `Pressability-test` (see facebook#55378 ).
I noticed the same bug in `isHighTextContrastEnabled` and `isDarkerSystemColorsEnabled` and I plan/would like to address them in follow-up PRs (and adding all the missing tests).
## Changelog:
[GENERAL] [FIXED] - Fix AccessibilityInfo.prefersCrossFadeTransitions unresolved (never ending) promise
Pull Request resolved: facebook#55920
Test Plan:
This fix has been develop in TDD. I first added a failing test to reproduce that the android branch of the `prefersCrossFadeTransitions` method was acting as described above (resulting in failure due to jest timeout because the promise was not returning). Then I applied the fix, and finally added also the test for the iOS counterpart.
One final note: `AccessibilityInfo` is mocked globally in `setup.js` (via `setupFiles` in the Jest preset).
So to test the real implementation I had to use `jest.unmock` (pattern that I saw is already used in other component test files like View-test.js and TextInput-test.js).
Reviewed By: vzaidman
Differential Revision: D95565605
Pulled By: cipolleschi
fbshipit-source-id: c666d198de593a79324801c181d571807d874bd51 parent 3057e28 commit 57c073f
2 files changed
Lines changed: 106 additions & 6 deletions
File tree
- packages/react-native/Libraries/Components/AccessibilityInfo
- __tests__
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| |||
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
291 | | - | |
292 | | - | |
| 291 | + | |
| 292 | + | |
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
| |||
Lines changed: 100 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
0 commit comments