diff --git a/android/src/main/java/com/henninghall/date_picker/pickers/IosClone.java b/android/src/main/java/com/henninghall/date_picker/pickers/IosClone.java index 5f8292be..480f2c8b 100644 --- a/android/src/main/java/com/henninghall/date_picker/pickers/IosClone.java +++ b/android/src/main/java/com/henninghall/date_picker/pickers/IosClone.java @@ -4,6 +4,10 @@ import android.graphics.Color; import android.util.AttributeSet; import android.view.View; +import android.view.MotionEvent; + +import com.henninghall.date_picker.ui.Accessibility; + import cn.carbswang.android.numberpickerview.library.NumberPickerView; public class IosClone extends NumberPickerView implements Picker { @@ -58,4 +62,13 @@ public View getView() { public boolean isSpinning() { return super.isScrolling(); } + + @Override + public boolean onTouchEvent(MotionEvent event) { + if(Accessibility.shouldAllowScroll(this)){ + super.onTouchEvent(event); + return true; + } + return false; + } } diff --git a/android/src/main/java/com/henninghall/date_picker/ui/Accessibility.java b/android/src/main/java/com/henninghall/date_picker/ui/Accessibility.java index 489b09c7..ab3dc88f 100644 --- a/android/src/main/java/com/henninghall/date_picker/ui/Accessibility.java +++ b/android/src/main/java/com/henninghall/date_picker/ui/Accessibility.java @@ -1,8 +1,12 @@ package com.henninghall.date_picker.ui; +import android.content.Context; +import android.os.Build; import android.view.View; import android.view.accessibility.AccessibilityEvent; +import android.view.accessibility.AccessibilityManager; +import com.henninghall.date_picker.DatePickerManager; import com.henninghall.date_picker.State; import com.henninghall.date_picker.Utils; import com.henninghall.date_picker.wheelFunctions.WheelFunction; @@ -12,6 +16,30 @@ public class Accessibility { + private final static AccessibilityManager systemManager = + (AccessibilityManager) DatePickerManager.context + .getApplicationContext() + .getSystemService(Context.ACCESSIBILITY_SERVICE); + + /** + When TalkBack is active, user can use one finger to explore the screen + and set focus to elements. Then user can proceed to use second finger + to scroll contents of focused element. + When there's multiple pickers next to each other horizontally, + it's easy to accidentally scroll more than one picker at a time. + Following code aims to fix this issue. + */ + public static boolean shouldAllowScroll(View view){ + // If TalkBack isn't active, always proceed without suppressing touch events + if (!systemManager.isTouchExplorationEnabled()) { + return true; + } + if (Build.VERSION.SDK_INT >= 21) { + return view.isAccessibilityFocused(); + } + return false; + } + public static class SetAccessibilityDelegate implements WheelFunction { private final Locale locale;