Commit 5c9a571
Fix AccessibilityInfo.isHighTextContrastEnabled unresolved promise (#56066)
Summary:
This PR fixes a bug in the `AccessibilityInfo` component. This is a follow up of the work I started with the PRs I opened in the last weeks #55920 #56019.
`AccessibilityInfo` exposes the method `isHighTextContrastEnabled`. In the else 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 hangs indefinitely (in the previous PRs the same bug affected the Android branch).
This means that if a user calls this method eg. on iOS without any `Platform.OS === 'android'` guard, it will result in an unresolved promise.
I fixed the bug in the same way as in the other PRs: by aligning the implementation of `isHighTextContrastEnabled` to the one of other methods.
I also added the tests to avoid regression, and additionally verify that the Android method is doing what we are expecting (in both cases for when `NativeAccessibilityInfoAndroid.isHighTextContrastEnabled` 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 #55378).
PS I will open one (or more if I see it is too big) PR to add the missing tests for the other `AccessibilityInfo methods still not tested.
## Changelog:
[GENERAL] [FIXED] - Fix AccessibilityInfo.isHighTextContrastEnabled unresolved (never ending) promise
Pull Request resolved: #56066
Test Plan: This fix (as for the other PRs), was developed using TDD. I first added a failing test to reproduce that the iOS branch of the `isHighTextContrastEnabled` 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 Android counterpart.
Reviewed By: javache
Differential Revision: D96293309
Pulled By: vzaidman
fbshipit-source-id: 98c338039bf83bd418b563f64da80c471f70907f1 parent c625015 commit 5c9a571
2 files changed
Lines changed: 69 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 | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
217 | | - | |
| 216 | + | |
| 217 | + | |
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| |||
Lines changed: 63 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
40 | 50 | | |
41 | 51 | | |
42 | 52 | | |
43 | 53 | | |
44 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
45 | 60 | | |
46 | 61 | | |
47 | 62 | | |
| |||
53 | 68 | | |
54 | 69 | | |
55 | 70 | | |
| 71 | + | |
56 | 72 | | |
57 | 73 | | |
58 | 74 | | |
| |||
149 | 165 | | |
150 | 166 | | |
151 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
152 | 213 | | |
153 | 214 | | |
154 | 215 | | |
155 | 216 | | |
156 | 217 | | |
| 218 | + | |
| 219 | + | |
157 | 220 | | |
158 | 221 | | |
159 | 222 | | |
| |||
0 commit comments