Skip to content

Commit b609d15

Browse files
Separate GestureExtension Classes to allow for [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
1 parent 629db45 commit b609d15

3 files changed

Lines changed: 46 additions & 38 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace CommunityToolkit.Maui.Markup.Services;
2+
3+
static class GestureExtensions
4+
{
5+
public static TGestureElement ConfigureSwipeGesture<TGestureElement>(this TGestureElement gestureElement,
6+
SwipeGestureRecognizer swipeGesture,
7+
SwipeDirection? direction = null,
8+
uint? threshold = null) where TGestureElement : IGestureRecognizers
9+
{
10+
if (direction is not null)
11+
{
12+
swipeGesture.Direction = direction.Value;
13+
}
14+
15+
if (threshold is not null)
16+
{
17+
swipeGesture.Threshold = threshold.Value;
18+
}
19+
20+
return gestureElement;
21+
}
22+
23+
public static TGestureElement ConfigureTapGesture<TGestureElement>(this TGestureElement gestureElement,
24+
TapGestureRecognizer tapGesture,
25+
int? numberOfTapsRequired = null) where TGestureElement : IGestureRecognizers
26+
{
27+
if (numberOfTapsRequired is not null)
28+
{
29+
tapGesture.NumberOfTapsRequired = numberOfTapsRequired.Value;
30+
}
31+
32+
return gestureElement;
33+
}
34+
}

src/CommunityToolkit.Maui.Markup/GesturesExtensions.cs renamed to src/CommunityToolkit.Maui.Markup/StringGesturesExtensions.cs

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using System.Diagnostics.CodeAnalysis;
22
using System.Windows.Input;
3+
using CommunityToolkit.Maui.Markup.Services;
34

45
namespace CommunityToolkit.Maui.Markup;
56

67
/// <summary>
78
/// Extension Methods for Element Gestures
89
/// </summary>
9-
public static partial class GesturesExtensions
10+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
11+
public static class StringGesturesExtensions
1012
{
1113
/// <summary>Add a <see cref="SwipeGestureRecognizer"/> and bind to its Command and (optionally) CommandParameter properties</summary>
1214
/// <param name="gestureElement">An <see cref="Element"/> implementing <see cref="IGestureRecognizers"/></param>
@@ -17,7 +19,6 @@ public static partial class GesturesExtensions
1719
/// <param name="direction">Swipe gesture direction</param>
1820
/// <param name="threshold">Minimum swipe distance that will cause the gesture to be recognized</param>
1921
/// <returns><paramref name="gestureElement"/></returns>
20-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
2122
[RequiresUnreferencedCode("Using bindings with string paths is not trim safe. Use expression-based binding instead.")]
2223
public static TGestureElement BindSwipeGesture<TGestureElement>(this TGestureElement gestureElement,
2324
string commandPath,
@@ -40,7 +41,6 @@ public static TGestureElement BindSwipeGesture<TGestureElement>(this TGestureEle
4041
/// <param name="parameterSource">Binding source for Command Binding</param>
4142
/// <param name="numberOfTapsRequired">Number of taps required to trigger the <see cref="ICommand"/></param>
4243
/// <returns><paramref name="gestureElement"/></returns>
43-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
4444
[RequiresUnreferencedCode("Using bindings with string paths is not trim safe. Use expression-based binding instead.")]
4545
public static TGestureElement BindTapGesture<TGestureElement>(this TGestureElement gestureElement,
4646
string commandPath,
@@ -163,45 +163,15 @@ public static TGestureElement TapGesture<TGestureElement>(this TGestureElement g
163163

164164
return gestureElement;
165165
}
166-
167-
static TGestureElement ConfigureSwipeGesture<TGestureElement>(this TGestureElement gestureElement,
168-
SwipeGestureRecognizer swipeGesture,
169-
SwipeDirection? direction = null,
170-
uint? threshold = null) where TGestureElement : IGestureRecognizers
171-
{
172-
if (direction is not null)
173-
{
174-
swipeGesture.Direction = direction.Value;
175-
}
176-
177-
if (threshold is not null)
178-
{
179-
swipeGesture.Threshold = threshold.Value;
180-
}
181-
182-
return gestureElement;
183-
}
184-
185-
static TGestureElement ConfigureTapGesture<TGestureElement>(this TGestureElement gestureElement,
186-
TapGestureRecognizer tapGesture,
187-
int? numberOfTapsRequired = null) where TGestureElement : IGestureRecognizers
188-
{
189-
if (numberOfTapsRequired is not null)
190-
{
191-
tapGesture.NumberOfTapsRequired = numberOfTapsRequired.Value;
192-
}
193-
194-
return gestureElement;
195-
}
196-
166+
197167
[RequiresUnreferencedCode("Using bindings with string paths is not trim safe. Use expression-based binding instead.")]
198-
static TGestureRecognizer BindGesture<TGestureElement, TGestureRecognizer>(
168+
static TGestureRecognizer BindGesture<TGestureElement, TGestureRecognizer>(
199169
this TGestureElement gestureElement,
200170
string commandPath,
201171
object? commandSource = null,
202172
string? parameterPath = null,
203173
object? parameterSource = null) where TGestureElement : IGestureRecognizers
204-
where TGestureRecognizer : BindableObject, IGestureRecognizer, new()
174+
where TGestureRecognizer : BindableObject, IGestureRecognizer, new()
205175
{
206176
var gestureRecognizer = new TGestureRecognizer().BindCommand(commandPath, commandSource, parameterPath, parameterSource);
207177
gestureElement.GestureRecognizers.Add(gestureRecognizer);

src/CommunityToolkit.Maui.Markup/GesturesExtensions.TypedBindings.cs renamed to src/CommunityToolkit.Maui.Markup/TypedGesturesExtensions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
using System.Linq.Expressions;
1+
using System.Diagnostics.CodeAnalysis;
2+
using System.Linq.Expressions;
23
using System.Windows.Input;
4+
using CommunityToolkit.Maui.Markup.Services;
5+
36
namespace CommunityToolkit.Maui.Markup;
47

58
/// <summary>
69
/// Extension Methods for Element Gestures
710
/// </summary>
8-
public static partial class GesturesExtensions
11+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
12+
public static class TypedGesturesExtensions
913
{
1014
/// <summary>Add a <see cref="SwipeGestureRecognizer"/> and bind to its Command </summary>
1115
public static TGestureElement BindSwipeGesture<TGestureElement, TCommandBindingContext>(

0 commit comments

Comments
 (0)