1212using Android . Widget ;
1313using Color = Android . Graphics . Color ;
1414using Android . Content . Res ;
15- using Android . Content ;
1615using static System . Math ;
16+ using Android . Views . Accessibility ;
17+ using Android . Content ;
1718
1819[ assembly: ResolutionGroupName ( nameof ( TouchEffect ) ) ]
1920[ assembly: ExportEffect ( typeof ( PlatformTouchEff ) , nameof ( TouchEff ) ) ]
@@ -24,7 +25,7 @@ public class PlatformTouchEff : PlatformEffect
2425 {
2526 public static void Preserve ( ) { }
2627
27-
28+ private AccessibilityManager _accessibilityManager ;
2829 private TouchEff _effect ;
2930 private bool _isHoverSupported ;
3031 private RippleDrawable _ripple ;
@@ -35,17 +36,24 @@ public static void Preserve() { }
3536 private float _startY ;
3637 private bool _canceled ;
3738
39+ private bool IsAccessibilityMode =>
40+ _accessibilityManager != null &&
41+ _accessibilityManager . IsEnabled &&
42+ _accessibilityManager . IsTouchExplorationEnabled ;
43+
3844 protected override void OnAttached ( )
3945 {
4046 if ( View == null )
4147 {
4248 return ;
4349 }
50+ _accessibilityManager = View . Context . GetSystemService ( Context . AccessibilityService ) as AccessibilityManager ;
4451 _effect = Element . GetTouchEff ( ) ;
4552 _effect . Control = Element as VisualElement ;
4653 _effect . ForceUpdateState ( false ) ;
4754
4855 View . Touch += OnTouch ;
56+ View . Click += OnClick ;
4957
5058 if ( _effect . NativeAnimation && Group != null )
5159 {
@@ -71,13 +79,15 @@ protected override void OnDetached()
7179 {
7280 try
7381 {
82+ _accessibilityManager = null ;
7483 _effect . Control = null ;
7584 _effect = null ;
7685
7786 if ( View != null )
7887 {
7988 View . LayoutChange -= LayoutChange ;
8089 View . Touch -= OnTouch ;
90+ View . Click -= OnClick ;
8191 }
8292
8393 if ( _viewOverlay != null )
@@ -102,8 +112,11 @@ protected override void OnDetached()
102112
103113 private void OnTouch ( object sender , AView . TouchEventArgs e )
104114 {
115+ if ( IsAccessibilityMode )
116+ {
117+ return ;
118+ }
105119 e . Handled = true ;
106-
107120 switch ( e . Event . ActionMasked )
108121 {
109122 case MotionEventActions . Down :
@@ -172,6 +185,15 @@ private void OnTouch(object sender, AView.TouchEventArgs e)
172185 }
173186 }
174187
188+ private void OnClick ( object sender , System . EventArgs args )
189+ {
190+ if ( ! IsAccessibilityMode )
191+ {
192+ return ;
193+ }
194+ HandleEnd ( TouchStatus . Completed ) ;
195+ }
196+
175197 private void HandleEnd ( TouchStatus status )
176198 {
177199 if ( _canceled )
@@ -254,4 +276,4 @@ private void LayoutChange(object sender, AView.LayoutChangeEventArgs e)
254276 _viewOverlay . Bottom = group . Height ;
255277 }
256278 }
257- }
279+ }
0 commit comments