Skip to content

Commit 8a5808a

Browse files
authored
Wheel Multiple Value Change On Touch (#181)
1 parent fcf316f commit 8a5808a

3 files changed

Lines changed: 32 additions & 18 deletions

File tree

CodeBeam.MudBlazor.Extensions/Components/Wheel/MudWheel.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
<MudText Align="Align.Center" Color="@Color">@Label</MudText>
1111
}
12-
<MudSwipeArea Class="@InnerClassname" Style="@GetStylename()" Sensitivity="@Sensitivity" OnSwipe="@(async(d) => await HandleOnSwipe(d))" @onwheel="HandleOnWheel" PreventDefault="true">
12+
<MudSwipeArea Class="@InnerClassname" Style="@GetStylename()" Sensitivity="@Sensitivity" OnSwipeEnd="HandleOnSwipe" @onwheel="HandleOnWheel" PreventDefault="true">
1313

1414
@if (true)
1515
{

CodeBeam.MudBlazor.Extensions/Components/Wheel/MudWheel.razor.cs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ public partial class MudWheel<T> : MudBaseInput<T>
6060
public int WheelLevel { get; set; } = 2;
6161

6262
/// <summary>
63-
/// The minimum swipe delta to change wheel value on touch devices. Default is 30.
63+
/// The minimum swipe delta to change wheel value on touch devices. Default is 40.
6464
/// </summary>
6565
[Parameter]
66-
public int Sensitivity { get; set; } = 30;
66+
public int Sensitivity { get; set; } = 40;
6767

6868
[Parameter]
6969
public string InnerClass { get; set; }
@@ -143,18 +143,18 @@ protected async Task HandleOnWheel(WheelEventArgs args)
143143
await Task.Delay(300);
144144
}
145145

146-
protected async Task HandleOnSwipe(SwipeDirection direction)
146+
protected async Task HandleOnSwipe(SwipeEventArgs args)
147147
{
148148
if (Disabled || ReadOnly)
149149
{
150150
return;
151151
}
152152
int index = GetIndex();
153-
if ((direction == SwipeDirection.TopToBottom && index == 0) || (direction == SwipeDirection.BottomToTop && index == ItemCollection.Count - 1))
153+
if ((args.SwipeDirection == SwipeDirection.TopToBottom && index == 0) || (args.SwipeDirection == SwipeDirection.BottomToTop && index == ItemCollection.Count - 1))
154154
{
155155
return;
156156
}
157-
if (direction == SwipeDirection.BottomToTop)
157+
if (args.SwipeDirection == SwipeDirection.BottomToTop)
158158
{
159159
_animateValue = GetAnimateValue();
160160
}
@@ -163,19 +163,34 @@ protected async Task HandleOnSwipe(SwipeDirection direction)
163163
_animateValue = - GetAnimateValue();
164164
}
165165

166-
167-
await _animate.Refresh();
168-
if (direction == SwipeDirection.TopToBottom)
169-
{
170-
T val = ItemCollection[index - 1];
171-
await SetValueAsync(val);
172-
}
173-
else if (direction == SwipeDirection.BottomToTop)
166+
int changedCount = (Math.Abs((int)args.SwipeDelta) / (Sensitivity == 0 ? 1 : Sensitivity));
167+
for (int i = 0; i < changedCount; i++)
174168
{
175-
T val = ItemCollection[index + 1];
176-
await SetValueAsync(val);
169+
await _animate.Refresh();
170+
StateHasChanged();
171+
if (args.SwipeDirection == SwipeDirection.TopToBottom)
172+
{
173+
if (index - 1 < 0)
174+
{
175+
break;
176+
}
177+
T val = ItemCollection[index - 1];
178+
index--;
179+
await SetValueAsync(val);
180+
StateHasChanged();
181+
}
182+
else if (args.SwipeDirection == SwipeDirection.BottomToTop)
183+
{
184+
if (ItemCollection.Count <= index + 1)
185+
{
186+
break;
187+
}
188+
T val = ItemCollection[index + 1];
189+
index++;
190+
await SetValueAsync(val);
191+
StateHasChanged();
192+
}
177193
}
178-
179194
}
180195

181196
public async Task ChangeWheel(int changeCount)

ComponentViewer.Wasm/wwwroot/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
77
<title>ComponentViewer.Wasm</title>
88
<base href="/" />
9-
<link href="css/app.css" rel="stylesheet" />
109
<link href="app.css" rel="stylesheet" />
1110
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
1211
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@700;900&display=swap" rel="stylesheet">

0 commit comments

Comments
 (0)