Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 01bfcdf

Browse files
Fix Java.Lang.NoSuchMethodError in TouchEffect (#971)
* Fixes #969 * Fixed #853
1 parent 2d93dcb commit 01bfcdf

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.android.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Xamarin.CommunityToolkit.Effects;
1212
using Xamarin.Forms;
1313
using Xamarin.Forms.Platform.Android;
14-
using AndroidOS = Android.OS;
1514
using AView = Android.Views.View;
1615
using Color = Android.Graphics.Color;
1716

@@ -76,7 +75,9 @@ protected override void OnAttached()
7675

7776
if (Group == null)
7877
{
79-
View.Foreground = ripple;
78+
if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
79+
View.Foreground = ripple;
80+
8081
return;
8182
}
8283

@@ -115,7 +116,7 @@ protected override void OnDetached()
115116
View.Touch -= OnTouch;
116117
View.Click -= OnClick;
117118

118-
if (View.Foreground == ripple)
119+
if (Build.VERSION.SdkInt >= BuildVersionCodes.M && View.Foreground == ripple)
119120
View.Foreground = null;
120121
}
121122

@@ -316,7 +317,10 @@ void EndRipple()
316317

317318
void CreateRipple()
318319
{
319-
var drawable = Group != null ? View?.Background : View?.Foreground;
320+
var drawable = Build.VERSION.SdkInt >= BuildVersionCodes.M && Group == null
321+
? View?.Foreground
322+
: View?.Background;
323+
320324
var isEmptyDrawable = Element is Layout || drawable == null;
321325

322326
if (drawable is RippleDrawable)
@@ -355,12 +359,11 @@ ColorStateList GetColorStateList()
355359

356360
void OnLayoutChange(object sender, AView.LayoutChangeEventArgs e)
357361
{
358-
var group = (ViewGroup)sender;
359-
if (group == null || (Group as IVisualElementRenderer)?.Element == null || rippleView == null)
362+
if (!(sender is AView view) || (Group as IVisualElementRenderer)?.Element == null || rippleView == null)
360363
return;
361364

362-
rippleView.Right = group.Width;
363-
rippleView.Bottom = group.Height;
365+
rippleView.Right = view.Width;
366+
rippleView.Bottom = view.Height;
364367
}
365368

366369
sealed class AccessibilityListener : Java.Lang.Object,

0 commit comments

Comments
 (0)