|
10 | 10 | import android.graphics.PorterDuff;
|
11 | 11 | import android.graphics.drawable.Drawable;
|
12 | 12 | import android.graphics.drawable.LayerDrawable;
|
| 13 | +import android.os.Bundle; |
13 | 14 | import android.view.View;
|
14 | 15 | import android.view.ViewGroup;
|
15 | 16 | import android.widget.SeekBar;
|
16 | 17 | import androidx.annotation.Nullable;
|
| 18 | +import androidx.core.view.AccessibilityDelegateCompat; |
| 19 | +import androidx.core.view.ViewCompat; |
| 20 | +import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat; |
17 | 21 | import com.facebook.react.bridge.ReactContext;
|
18 | 22 | import com.facebook.react.bridge.ReadableMap;
|
19 | 23 | import com.facebook.react.common.MapBuilder;
|
@@ -132,7 +136,9 @@ public Class getShadowNodeClass() {
|
132 | 136 |
|
133 | 137 | @Override
|
134 | 138 | protected ReactSlider createViewInstance(ThemedReactContext context) {
|
135 |
| - return new ReactSlider(context, null, STYLE); |
| 139 | + final ReactSlider slider = new ReactSlider(context, null, STYLE); |
| 140 | + ViewCompat.setAccessibilityDelegate(slider, sAccessibilityDelegate); |
| 141 | + return slider; |
136 | 142 | }
|
137 | 143 |
|
138 | 144 | @Override
|
@@ -256,4 +262,27 @@ public long measure(
|
256 | 262 | protected ViewManagerDelegate<ReactSlider> getDelegate() {
|
257 | 263 | return mDelegate;
|
258 | 264 | }
|
| 265 | + |
| 266 | + protected static class ReactSliderAccessibilityDelegate extends AccessibilityDelegateCompat { |
| 267 | + private static boolean isSliderAction(int action) { |
| 268 | + return (action == AccessibilityActionCompat.ACTION_SCROLL_FORWARD.getId()) |
| 269 | + || (action == AccessibilityActionCompat.ACTION_SCROLL_BACKWARD.getId()) |
| 270 | + || (action == AccessibilityActionCompat.ACTION_SET_PROGRESS.getId()); |
| 271 | + } |
| 272 | + |
| 273 | + @Override |
| 274 | + public boolean performAccessibilityAction(View host, int action, Bundle args) { |
| 275 | + if (isSliderAction(action)) { |
| 276 | + ON_CHANGE_LISTENER.onStartTrackingTouch((SeekBar) host); |
| 277 | + } |
| 278 | + final boolean rv = super.performAccessibilityAction(host, action, args); |
| 279 | + if (isSliderAction(action)) { |
| 280 | + ON_CHANGE_LISTENER.onStopTrackingTouch((SeekBar) host); |
| 281 | + } |
| 282 | + return rv; |
| 283 | + } |
| 284 | + }; |
| 285 | + |
| 286 | + protected static ReactSliderAccessibilityDelegate sAccessibilityDelegate = |
| 287 | + new ReactSliderAccessibilityDelegate(); |
259 | 288 | }
|
0 commit comments