1
1
import { useEffect , useState } from 'react'
2
- import { AccessibilityInfo , AccessibilityEvent } from 'react-native'
3
-
4
- type AccessibilityEventName =
5
- | 'boldTextChanged' // iOS-only Event
6
- | 'grayscaleChanged' // iOS-only Event
7
- | 'invertColorsChanged' // iOS-only Event
8
- | 'reduceMotionChanged'
9
- | 'screenReaderChanged'
10
- | 'reduceTransparencyChanged' // iOS-only Event
2
+ import { AccessibilityInfo , AccessibilityChangeEventName } from 'react-native'
11
3
12
4
type AccessibilityInfoStaticInitializers =
13
5
| 'isBoldTextEnabled'
@@ -18,7 +10,7 @@ type AccessibilityInfoStaticInitializers =
18
10
| 'isReduceTransparencyEnabled'
19
11
20
12
type AccessibilityEventToInfoStaticKeyMap = {
21
- [ K in AccessibilityEventName ] ?: AccessibilityInfoStaticInitializers
13
+ [ K in AccessibilityChangeEventName ] ?: AccessibilityInfoStaticInitializers
22
14
}
23
15
24
16
const EVENT_NAME_TO_INITIALIZER : AccessibilityEventToInfoStaticKeyMap = {
@@ -30,10 +22,8 @@ const EVENT_NAME_TO_INITIALIZER: AccessibilityEventToInfoStaticKeyMap = {
30
22
reduceTransparencyChanged : 'isReduceTransparencyEnabled' ,
31
23
}
32
24
33
- type AccessibilityInfoChangeEventHandler = ( event : AccessibilityEvent ) => void
34
-
35
25
function useAccessibilityStateListener (
36
- eventName : AccessibilityEventName ,
26
+ eventName : AccessibilityChangeEventName ,
37
27
) : boolean {
38
28
const [ isEnabled , setIsEnabled ] = useState ( false )
39
29
@@ -47,13 +37,13 @@ function useAccessibilityStateListener(
47
37
AccessibilityInfo [ initializerKey ] ( ) . then ( setIsEnabled )
48
38
AccessibilityInfo . addEventListener (
49
39
eventName ,
50
- < AccessibilityInfoChangeEventHandler > setIsEnabled ,
40
+ setIsEnabled ,
51
41
)
52
42
53
43
return ( ) =>
54
44
AccessibilityInfo . removeEventListener (
55
45
eventName ,
56
- < AccessibilityInfoChangeEventHandler > setIsEnabled ,
46
+ setIsEnabled ,
57
47
)
58
48
} , [ eventName ] )
59
49
0 commit comments