@@ -62,13 +62,27 @@ public class AccessibilityInfoModule(context: ReactApplicationContext) :
62
62
}
63
63
}
64
64
}
65
+ // Listener that is notified when the ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED changes.
66
+ private val highTextContrastObserver: ContentObserver =
67
+ object : ContentObserver (UiThreadUtil .getUiThreadHandler()) {
68
+ override fun onChange (selfChange : Boolean ) {
69
+ this .onChange(selfChange, null )
70
+ }
71
+
72
+ override fun onChange (selfChange : Boolean , uri : Uri ? ) {
73
+ if (getReactApplicationContext().hasActiveReactInstance()) {
74
+ updateAndSendHighTextContrastChangeEvent()
75
+ }
76
+ }
77
+ }
65
78
private val accessibilityManager: AccessibilityManager ?
66
79
private val touchExplorationStateChangeListener: ReactTouchExplorationStateChangeListener =
67
80
ReactTouchExplorationStateChangeListener ()
68
81
private val accessibilityServiceChangeListener: ReactAccessibilityServiceChangeListener =
69
82
ReactAccessibilityServiceChangeListener ()
70
83
private val contentResolver: ContentResolver
71
84
private var reduceMotionEnabled = false
85
+ private var highTextContrastEnabled = false
72
86
private var touchExplorationEnabled = false
73
87
private var accessibilityServiceEnabled = false
74
88
private var recommendedTimeout = 0
@@ -81,6 +95,7 @@ public class AccessibilityInfoModule(context: ReactApplicationContext) :
81
95
touchExplorationEnabled = accessibilityManager.isTouchExplorationEnabled
82
96
accessibilityServiceEnabled = accessibilityManager.isEnabled
83
97
reduceMotionEnabled = isReduceMotionEnabledValue
98
+ highTextContrastEnabled = isHighTextContrastEnabledValue
84
99
}
85
100
86
101
@get:TargetApi(Build .VERSION_CODES .LOLLIPOP )
@@ -96,10 +111,24 @@ public class AccessibilityInfoModule(context: ReactApplicationContext) :
96
111
return parsedValue == 0f
97
112
}
98
113
114
+ @get:TargetApi(Build .VERSION_CODES .LOLLIPOP )
115
+ private val isHighTextContrastEnabledValue: Boolean
116
+ get() {
117
+ return Settings .Secure .getInt(
118
+ contentResolver,
119
+ ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED_CONSTANT ,
120
+ 0 ,
121
+ ) != 0
122
+ }
123
+
99
124
override fun isReduceMotionEnabled (successCallback : Callback ) {
100
125
successCallback.invoke(reduceMotionEnabled)
101
126
}
102
127
128
+ override fun isHighTextContrastEnabled (successCallback : Callback ) {
129
+ successCallback.invoke(highTextContrastEnabled)
130
+ }
131
+
103
132
override fun isTouchExplorationEnabled (successCallback : Callback ) {
104
133
successCallback.invoke(touchExplorationEnabled)
105
134
}
@@ -119,6 +148,20 @@ public class AccessibilityInfoModule(context: ReactApplicationContext) :
119
148
}
120
149
}
121
150
151
+ private fun updateAndSendHighTextContrastChangeEvent () {
152
+ val isHighTextContrastEnabled = isHighTextContrastEnabledValue
153
+ if (highTextContrastEnabled != isHighTextContrastEnabled) {
154
+ highTextContrastEnabled = isHighTextContrastEnabled
155
+ val reactApplicationContext = getReactApplicationContextIfActiveOrWarn()
156
+ if (reactApplicationContext != null ) {
157
+ reactApplicationContext.emitDeviceEvent(
158
+ HIGH_TEXT_CONTRAST_EVENT_NAME ,
159
+ highTextContrastEnabled,
160
+ )
161
+ }
162
+ }
163
+ }
164
+
122
165
private fun updateAndSendTouchExplorationChangeEvent (enabled : Boolean ) {
123
166
if (touchExplorationEnabled != enabled) {
124
167
touchExplorationEnabled = enabled
@@ -148,10 +191,14 @@ public class AccessibilityInfoModule(context: ReactApplicationContext) :
148
191
accessibilityManager?.addAccessibilityStateChangeListener(accessibilityServiceChangeListener)
149
192
val transitionUri = Settings .Global .getUriFor(Settings .Global .TRANSITION_ANIMATION_SCALE )
150
193
contentResolver.registerContentObserver(transitionUri, false , animationScaleObserver)
194
+ val highTextContrastUri =
195
+ Settings .Global .getUriFor(ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED_CONSTANT )
196
+ contentResolver.registerContentObserver(highTextContrastUri, false , highTextContrastObserver)
151
197
updateAndSendTouchExplorationChangeEvent(
152
198
accessibilityManager?.isTouchExplorationEnabled == true )
153
199
updateAndSendAccessibilityServiceChangeEvent(accessibilityManager?.isEnabled == true )
154
200
updateAndSendReduceMotionChangeEvent()
201
+ updateAndSendHighTextContrastChangeEvent()
155
202
}
156
203
157
204
@TargetApi(Build .VERSION_CODES .LOLLIPOP )
@@ -160,6 +207,7 @@ public class AccessibilityInfoModule(context: ReactApplicationContext) :
160
207
touchExplorationStateChangeListener)
161
208
accessibilityManager?.removeAccessibilityStateChangeListener(accessibilityServiceChangeListener)
162
209
contentResolver.unregisterContentObserver(animationScaleObserver)
210
+ contentResolver.unregisterContentObserver(highTextContrastObserver)
163
211
}
164
212
165
213
override fun initialize () {
@@ -168,6 +216,7 @@ public class AccessibilityInfoModule(context: ReactApplicationContext) :
168
216
accessibilityManager?.isTouchExplorationEnabled == true )
169
217
updateAndSendAccessibilityServiceChangeEvent(accessibilityManager?.isEnabled == true )
170
218
updateAndSendReduceMotionChangeEvent()
219
+ updateAndSendHighTextContrastChangeEvent()
171
220
}
172
221
173
222
override fun invalidate () {
@@ -200,13 +249,18 @@ public class AccessibilityInfoModule(context: ReactApplicationContext) :
200
249
}
201
250
recommendedTimeout =
202
251
accessibilityManager?.getRecommendedTimeoutMillis(
203
- originalTimeout.toInt(), AccessibilityManager .FLAG_CONTENT_CONTROLS ) ? : 0
252
+ originalTimeout.toInt(),
253
+ AccessibilityManager .FLAG_CONTENT_CONTROLS ,
254
+ ) ? : 0
204
255
successCallback.invoke(recommendedTimeout)
205
256
}
206
257
207
258
private companion object {
208
259
private const val REDUCE_MOTION_EVENT_NAME = " reduceMotionDidChange"
260
+ private const val HIGH_TEXT_CONTRAST_EVENT_NAME = " highTextContrastDidChange"
209
261
private const val TOUCH_EXPLORATION_EVENT_NAME = " touchExplorationDidChange"
210
262
private const val ACCESSIBILITY_SERVICE_EVENT_NAME = " accessibilityServiceDidChange"
263
+ private const val ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED_CONSTANT =
264
+ " high_text_contrast_enabled" // constant is marked with @hide
211
265
}
212
266
}
0 commit comments