diff --git a/src/Connected.Components/Components/TimePicker.razor b/src/Connected.Components/Components/TimePicker.razor new file mode 100644 index 0000000..df7b51c --- /dev/null +++ b/src/Connected.Components/Components/TimePicker.razor @@ -0,0 +1,10 @@ +
+ + + + + + + + +
\ No newline at end of file diff --git a/src/Connected.Components/Components/TimePicker.razor.cs b/src/Connected.Components/Components/TimePicker.razor.cs new file mode 100644 index 0000000..19b602e --- /dev/null +++ b/src/Connected.Components/Components/TimePicker.razor.cs @@ -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(); + } +} diff --git a/src/Connected.Components/Enums/TouchGesture.cs b/src/Connected.Components/Enums/TouchGesture.cs new file mode 100644 index 0000000..1982833 --- /dev/null +++ b/src/Connected.Components/Enums/TouchGesture.cs @@ -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, +} diff --git a/src/Connected.Components/Utilities/TouchGestures.cs b/src/Connected.Components/Utilities/TouchGestures.cs new file mode 100644 index 0000000..e3d03ab --- /dev/null +++ b/src/Connected.Components/Utilities/TouchGestures.cs @@ -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; + } + + } +}