WIP TimePicker - initial commit (not working), Added class for TouchGestures detection (for future use)

features/rewrite/timepicker
markosteger 2 years ago
parent 602c61568c
commit f83eeeb03b

@ -0,0 +1,10 @@
<div>
<span>
<input id="hour" type="number" min="0" max="59" step="1" @bind-value="@Hour" />
<label for="hour">hrs</label>
<input id="minute" type="number" min="0" max="59" step="1" @bind-value="@Minute" />
<label for="minute">min</label>
<input id="minute" type="number" min="0" max="59" step="1" @bind-value="@Second" />
<label for="minute">sec</label>
</span>
</div>

@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Components;
namespace Connected.Components;
public partial class TimePicker: ComponentBase
{
[Parameter]
public TimeOnly Time { get; set; } = TimeOnly.FromDateTime(DateTime.Now);
private int Hour = 0;
private int Minute = 0;
private int Second = 0;
protected override async Task OnParametersSetAsync()
{
Hour = Time.Hour;
Minute = Time.Minute;
Second = Time.Second;
await base.OnInitializedAsync();
}
}

@ -0,0 +1,22 @@
using System.ComponentModel;
namespace Connected.Enums;
public enum TouchGesture
{
[Description("swipeleft")]
SwipeLeft,
[Description("swiperight")]
SwipeRight,
[Description("swipeup")]
SwipeUp,
[Description("swipedown")]
SwipeDown,
[Description("pinch")]
Pinch,
[Description("zoom")]
Zoom,
[Description("tap")]
Tap,
[Description("none")]
None,
}

@ -0,0 +1,76 @@
using Connected.Enums;
using Microsoft.AspNetCore.Components.Web;
using System.Reflection.Metadata.Ecma335;
namespace Connected.Utilities;
public static class TouchGestures
{
public static TouchGesture GetTouchGesture(TouchPoint[] TouchPoints, DateTime GestureStart)
{
try
{
if (TouchPoints is not null)
{
/* handling tap
* TouchPoints --> array with one point inside suggesting user tapped the screen
*/
if (TouchPoints.Length == 1)
{
var point = TouchPoints[0];
return TouchGesture.Tap;
}
/* handling swipe with one finger
* TouchPoints --> array of exactly two points start and end point, suggesting one finger was used and dragged across the screen
*/
if (TouchPoints.Length == 2)
{
var startPoint = TouchPoints[0];
var endPoint = TouchPoints[1];
const double swipeThreshold = 0.8;
var diffX = startPoint.ClientX - endPoint.ClientX;
var diffY = startPoint.ClientY - endPoint.ClientY;
var diffTime = DateTime.Now - GestureStart;
var velocityX = Math.Abs(diffX / diffTime.Milliseconds);
var velocityY = Math.Abs(diffY / diffTime.Milliseconds);
//dismiss touch gestures if user slowly touched the screen, preventing accidental or unwanted touches
if (velocityX < swipeThreshold && velocityY < swipeThreshold)
return TouchGesture.None;
//preventing false gesture detection if the swipe is too diagonal
if (Math.Abs(velocityX - velocityY) < 0.5)
return TouchGesture.None;
if (velocityX >= swipeThreshold)
{
if (diffX < 0)
return TouchGesture.SwipeRight;
else
return TouchGesture.SwipeLeft;
}
if (velocityY >= swipeThreshold)
{
if (diffX < 0)
return TouchGesture.SwipeUp;
else
return TouchGesture.SwipeDown;
}
}
/* handling zoom, pinch, mutifinger swipe
* TouchPoints --> array of more than 2 points, suggesting two or more fingers were used to make a gesture
*/
if (TouchPoints.Length > 2)
{
//TODO
}
}
return TouchGesture.None;
}
catch
{
return TouchGesture.None;
}
}
}
Loading…
Cancel
Save