Browse Source

Fix: Two-finger scroll issue when TalkBack is active (#370)

* Fix: Two-finger scroll issue when TalkBack is active

* refactor: move accessibility related code to accessibility class

* cleanup imports

Co-authored-by: Henning Hall <henning.hall@hotmail.com>
master
Mika Lindell 4 years ago
committed by GitHub
parent
commit
56738d709a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions
  1. +13
    -0
      android/src/main/java/com/henninghall/date_picker/pickers/IosClone.java
  2. +28
    -0
      android/src/main/java/com/henninghall/date_picker/ui/Accessibility.java

+ 13
- 0
android/src/main/java/com/henninghall/date_picker/pickers/IosClone.java View File

@ -4,6 +4,10 @@ import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.view.MotionEvent;
import com.henninghall.date_picker.ui.Accessibility;
import cn.carbswang.android.numberpickerview.library.NumberPickerView; import cn.carbswang.android.numberpickerview.library.NumberPickerView;
public class IosClone extends NumberPickerView implements Picker { public class IosClone extends NumberPickerView implements Picker {
@ -58,4 +62,13 @@ public class IosClone extends NumberPickerView implements Picker {
public boolean isSpinning() { public boolean isSpinning() {
return super.isScrolling(); return super.isScrolling();
} }
@Override
public boolean onTouchEvent(MotionEvent event) {
if(Accessibility.shouldAllowScroll(this)){
super.onTouchEvent(event);
return true;
}
return false;
}
} }

+ 28
- 0
android/src/main/java/com/henninghall/date_picker/ui/Accessibility.java View File

@ -1,8 +1,12 @@
package com.henninghall.date_picker.ui; package com.henninghall.date_picker.ui;
import android.content.Context;
import android.os.Build;
import android.view.View; import android.view.View;
import android.view.accessibility.AccessibilityEvent; 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.State;
import com.henninghall.date_picker.Utils; import com.henninghall.date_picker.Utils;
import com.henninghall.date_picker.wheelFunctions.WheelFunction; import com.henninghall.date_picker.wheelFunctions.WheelFunction;
@ -12,6 +16,30 @@ import java.util.Locale;
public class Accessibility { 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 { public static class SetAccessibilityDelegate implements WheelFunction {
private final Locale locale; private final Locale locale;

Loading…
Cancel
Save