Compare commits
	
		
			3 Commits
		
	
	
		
			04309b1514
			...
			f83eeeb03b
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					f83eeeb03b | ||
| 
						 | 
					602c61568c | ||
| 
						 | 
					fa33cc5189 | 
@ -4,30 +4,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
<h1 style="text-align:center;">Component Sandbox</h1>
 | 
					<h1 style="text-align:center;">Component Sandbox</h1>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<FormWizard Id="Wizard1">
 | 
					<DatePicker @bind-SelectedDate=date>
 | 
				
			||||||
    <FormWizardStep Name="Step1">
 | 
					 | 
				
			||||||
        Step1
 | 
					 | 
				
			||||||
    </FormWizardStep>
 | 
					 | 
				
			||||||
    <FormWizardStep Name="Step2">
 | 
					 | 
				
			||||||
        Step2
 | 
					 | 
				
			||||||
    </FormWizardStep>
 | 
					 | 
				
			||||||
    <FormWizardStep Name="Step3">
 | 
					 | 
				
			||||||
        Step3
 | 
					 | 
				
			||||||
    </FormWizardStep>
 | 
					 | 
				
			||||||
    <FormWizardStep Name="Step4">
 | 
					 | 
				
			||||||
        Step4
 | 
					 | 
				
			||||||
    </FormWizardStep>
 | 
					 | 
				
			||||||
</FormWizard>
 | 
					 | 
				
			||||||
<DatePicker 
 | 
					 | 
				
			||||||
CloseOnDateSelect=true
 | 
					 | 
				
			||||||
@bind-SelectedDate=@date>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
</DatePicker>
 | 
					</DatePicker>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<TextInput @bind-Value="@value"></TextInput>
 | 
					<p>Izbran datum je: @date</p>
 | 
				
			||||||
<p>Selected date is @date.ToString()</p>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@value
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
@code {
 | 
					@code {
 | 
				
			||||||
    DateTime date = DateTime.Today;
 | 
					    DateTime date = DateTime.Today;
 | 
				
			||||||
 | 
				
			|||||||
@ -21,16 +21,21 @@
 | 
				
			|||||||
                {
 | 
					                {
 | 
				
			||||||
                    case Selecting.Years:
 | 
					                    case Selecting.Years:
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            <div class="@NavBarClass">
 | 
					                            <div class="@NavBarClass" style="@NavBarStyle">
 | 
				
			||||||
                                <div class="d-inline-block p-2" style="width:10%;text-align:left"><i class='bx bx-chevron-left'></i></div>
 | 
					                                <div class="chip-group-content d-inline-flex">
 | 
				
			||||||
                                <div class="d-inline-block" style="width:70%;text-align:center" @onclick=@(()=>Selecting = Selecting.Months)>@SelectedDate.ToString("yyyy")</div>
 | 
					                                    <div class="chip-leading-icon" @onclick="(async ()=>await NavBarClick(false))"><i class='bx bx-chevron-left'></i></div>
 | 
				
			||||||
                                <div class="d-inline-block p-2" style="width:10%;text-align:right"><i class='bx bx-chevron-right'></i></div>
 | 
					                                </div>
 | 
				
			||||||
 | 
					                                <div class="d-inline-block" style="width:70%;text-align:center" @onclick=@(()=>Selecting = Selecting.Months)>@SelectedDate.ToString("MMMM yyyy")</div>
 | 
				
			||||||
 | 
					                                <!--<div class="d-inline-block p-2" style="width:10%;text-align:right"><i class='bx bx-chevron-right'></i></div>-->
 | 
				
			||||||
 | 
					                                <div class="chip-group-content d-inline-flex">
 | 
				
			||||||
 | 
					                                    <div class="chip-leading-icon" @onclick="(async ()=>await NavBarClick())"><i class='bx bx-chevron-right'></i></div>
 | 
				
			||||||
 | 
					                                </div>
 | 
				
			||||||
                            </div>
 | 
					                            </div>
 | 
				
			||||||
                            @for (int i = SelectedDate.Year - 7; i < SelectedDate.Year + 8; i++)
 | 
					                            @for (int i = SelectedDate.Year - 7; i < SelectedDate.Year + 8; i++)
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                int y = i;
 | 
					                                int y = i;
 | 
				
			||||||
                                <a href="#" @onclick="@(()=>SetYear(y))">
 | 
					                                <a href="#" @onclick="@(()=>SetYear(y))">
 | 
				
			||||||
                                    <div class="chip-group-content d-inline-flex bg-core m-1 b-1 b-r-3 text-light" style="width:30%;">
 | 
					                                    <div class="chip-group-content d-inline-flex bg-core @YearChipClass(y) m-1 b-1 b-r-3 text-light" style="width:30%;">
 | 
				
			||||||
                                        <div class="chip-leading-icon"></div>
 | 
					                                        <div class="chip-leading-icon"></div>
 | 
				
			||||||
                                        <div class="chip-label">@i.ToString()</div>
 | 
					                                        <div class="chip-label">@i.ToString()</div>
 | 
				
			||||||
                                        <div class="chip-cta-icon"></div>
 | 
					                                        <div class="chip-cta-icon"></div>
 | 
				
			||||||
@ -46,15 +51,22 @@
 | 
				
			|||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    case Selecting.Months:
 | 
					                    case Selecting.Months:
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            <div class="@NavBarClass">
 | 
					                            <div class="@NavBarClass" style="@NavBarStyle">
 | 
				
			||||||
                                <div class="d-inline-block p-2" style="width:10%;text-align:left"><i class='bx bx-chevron-left'></i></div>
 | 
					                                <div class="chip-group-content d-inline-flex">
 | 
				
			||||||
 | 
					                                    <div class="chip-leading-icon" @onclick="(async ()=>await NavBarClick(false))"><i class='bx bx-chevron-left'></i></div>
 | 
				
			||||||
 | 
					                                </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                <div class="d-inline-block" style="width:70%;text-align:center" @onclick=@(()=>Selecting = Selecting.Years)>@SelectedDate.ToString("MMMM yyyy")</div>
 | 
					                                <div class="d-inline-block" style="width:70%;text-align:center" @onclick=@(()=>Selecting = Selecting.Years)>@SelectedDate.ToString("MMMM yyyy")</div>
 | 
				
			||||||
                                <div class="d-inline-block p-2" style="width:10%;text-align:right"><i class='bx bx-chevron-right'></i></div>
 | 
					
 | 
				
			||||||
 | 
					                                <!--<div class="d-inline-block p-2" style="width:10%;text-align:right"><i class='bx bx-chevron-right'></i></div>-->
 | 
				
			||||||
 | 
					                                <div class="chip-group-content d-inline-flex">
 | 
				
			||||||
 | 
					                                    <div class="chip-leading-icon" @onclick="(async ()=>await NavBarClick())"><i class='bx bx-chevron-right'></i></div>
 | 
				
			||||||
 | 
					                                </div>
 | 
				
			||||||
                            </div>
 | 
					                            </div>
 | 
				
			||||||
                            @for (int i = 1; i <= @DateTimeFormatInfo.CurrentInfo.MonthNames.Length - 1; i++)
 | 
					                            @for (int i = 1; i <= @DateTimeFormatInfo.CurrentInfo.MonthNames.Length - 1; i++)
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                int m = i;
 | 
					                                int m = i;
 | 
				
			||||||
                                <a href="#" @onclick="@(()=>SetMonth(m))">
 | 
					                                <a href="#" @onclick="@(()=>SetMonth(m))" @ont>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                    <div class="chip-group-content d-inline-flex bg-core @MonthChipClass(m) m-1 b-1 b-r-3 text-light" style="width:30%;">
 | 
					                                    <div class="chip-group-content d-inline-flex bg-core @MonthChipClass(m) m-1 b-1 b-r-3 text-light" style="width:30%;">
 | 
				
			||||||
                                        <div class="chip-leading-icon"></div>
 | 
					                                        <div class="chip-leading-icon"></div>
 | 
				
			||||||
@ -72,10 +84,17 @@
 | 
				
			|||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    case (Selecting.Days):
 | 
					                    case (Selecting.Days):
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            <div class="@NavBarClass">
 | 
					                            <div class="@NavBarClass" style="@NavBarStyle">
 | 
				
			||||||
                                <div class="d-inline-block p-2" style="width:10%;text-align:left"><i class='bx bx-chevron-left'></i></div>
 | 
					                                <div class="chip-group-content d-inline-flex">
 | 
				
			||||||
 | 
					                                    <div class="chip-leading-icon" @onclick="(async ()=>await NavBarClick(false))"><i class='bx bx-chevron-left'></i></div>
 | 
				
			||||||
 | 
					                                </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                <div class="d-inline-block" style="width:70%;text-align:center" @onclick=@(()=>Selecting = Selecting.Months)>@SelectedDate.ToString("MMMM yyyy")</div>
 | 
					                                <div class="d-inline-block" style="width:70%;text-align:center" @onclick=@(()=>Selecting = Selecting.Months)>@SelectedDate.ToString("MMMM yyyy")</div>
 | 
				
			||||||
                                <div class="d-inline-block p-2" style="width:10%;text-align:right"><i class='bx bx-chevron-right'></i></div>
 | 
					
 | 
				
			||||||
 | 
					                                <!--<div class="d-inline-block p-2" style="width:10%;text-align:right"><i class='bx bx-chevron-right'></i></div>-->
 | 
				
			||||||
 | 
					                                <div class="chip-group-content d-inline-flex">
 | 
				
			||||||
 | 
					                                    <div class="chip-leading-icon" @onclick="(async ()=>await NavBarClick())"><i class='bx bx-chevron-right'></i></div>
 | 
				
			||||||
 | 
					                                </div>
 | 
				
			||||||
                            </div>
 | 
					                            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            @for (int i = 0; i < 7; i++)
 | 
					                            @for (int i = 0; i < 7; i++)
 | 
				
			||||||
@ -93,16 +112,19 @@
 | 
				
			|||||||
                                {
 | 
					                                {
 | 
				
			||||||
                                    <br />
 | 
					                                    <br />
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
 | 
					 | 
				
			||||||
                                CalendarStart = CalendarStart.AddDays(1);
 | 
					                                CalendarStart = CalendarStart.AddDays(1);
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                            break;
 | 
					                            break;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            </div>
 | 
					                @if (ShowBottomBar)
 | 
				
			||||||
            <!-- Bottom bar -->
 | 
					                {
 | 
				
			||||||
            <div>
 | 
					                    <!-- Bottom bar -->
 | 
				
			||||||
                
 | 
					                    <div class="p-2" style="@NavBarStyle">
 | 
				
			||||||
 | 
					                        <Button Class="btn-sm" OnClick="(()=>Shown=!Shown)">X</Button>
 | 
				
			||||||
 | 
					                        <Button Class="btn-sm" OnClick="(async () => await SetDate(SelectedDate, true))">OK</Button>
 | 
				
			||||||
 | 
					                    </div>
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
				
			|||||||
@ -32,6 +32,9 @@ public partial class DatePicker
 | 
				
			|||||||
	[Parameter]
 | 
						[Parameter]
 | 
				
			||||||
	public bool UseDateRange { get; set; } = false;
 | 
						public bool UseDateRange { get; set; } = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						[Parameter]
 | 
				
			||||||
 | 
						public bool ShowBottomBar { get; set; } = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	[Parameter]
 | 
						[Parameter]
 | 
				
			||||||
	public string Format { get; set; } = "dd.MM.yyyy";
 | 
						public string Format { get; set; } = "dd.MM.yyyy";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -50,13 +53,14 @@ public partial class DatePicker
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	private bool Shown { get; set; } = false;
 | 
						private bool Shown { get; set; } = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public async Task SetDate(DateTime Date)
 | 
						public async Task SetDate(DateTime Date, bool HideOnSet=false)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		SelectedDate = Date;
 | 
							SelectedDate = Date;
 | 
				
			||||||
		SetStartStop();
 | 
							SetStartStop();
 | 
				
			||||||
		if (CloseOnDateSelect)
 | 
							if (CloseOnDateSelect)
 | 
				
			||||||
			Shown = false;
 | 
								Shown = false;
 | 
				
			||||||
		await SelectedDateChanged.InvokeAsync(SelectedDate);
 | 
							await SelectedDateChanged.InvokeAsync(SelectedDate);
 | 
				
			||||||
 | 
							if (HideOnSet) Shown = false;
 | 
				
			||||||
		StateHasChanged();
 | 
							StateHasChanged();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -168,17 +172,17 @@ public partial class DatePicker
 | 
				
			|||||||
	public string MonthChipClass(int month)
 | 
						public string MonthChipClass(int month)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (month.CompareTo(SelectedDate.Month) == 0)
 | 
							if (month.CompareTo(SelectedDate.Month) == 0)
 | 
				
			||||||
			return "bg-info text-light";
 | 
								return "bg-info text-white";
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			return "bg-core text-dark";
 | 
								return "bg-core text-light";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public string YearChipClass(int year)
 | 
						public string YearChipClass(int year)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (year.CompareTo(SelectedDate.Year) == 0)
 | 
							if (year.CompareTo(SelectedDate.Year) == 0)
 | 
				
			||||||
			return "bg-info text-light";
 | 
								return "bg-info text-white";
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			return "bg-core text-dark";
 | 
								return "bg-core text-light";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	protected override async Task OnInitializedAsync()
 | 
						protected override async Task OnInitializedAsync()
 | 
				
			||||||
@ -196,12 +200,51 @@ public partial class DatePicker
 | 
				
			|||||||
			return new CssBuilder("text-justify")
 | 
								return new CssBuilder("text-justify")
 | 
				
			||||||
				.AddClass("text-md-justify")
 | 
									.AddClass("text-md-justify")
 | 
				
			||||||
				//.AddClass("bg-warning")
 | 
									//.AddClass("bg-warning")
 | 
				
			||||||
 | 
									.AddClass("p-2")
 | 
				
			||||||
				.AddClass("text-small")
 | 
									.AddClass("text-small")
 | 
				
			||||||
				.AddClass("text-dark")
 | 
									.AddClass("text-dark")
 | 
				
			||||||
				.Build();
 | 
									.Build();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private string NavBarStyle
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							get
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								return new StyleBuilder("display","flex")
 | 
				
			||||||
 | 
									.AddStyle("flex-direction","row")
 | 
				
			||||||
 | 
									.AddStyle("flex-wrap","nowrap")
 | 
				
			||||||
 | 
									.AddStyle("justify-content","space-between")
 | 
				
			||||||
 | 
									.Build();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private async Task NavBarClick(bool forward = true)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							int multiplier = 1;
 | 
				
			||||||
 | 
							if (!forward) multiplier = -1;
 | 
				
			||||||
 | 
							switch (Selecting)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								case Selecting.Years:
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										SelectedDate=SelectedDate.AddYears(8 * multiplier);
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								case Selecting.Months:
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										SelectedDate = SelectedDate.AddYears(1 * multiplier);
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								case Selecting.Days: 
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										SelectedDate = SelectedDate.AddMonths(1*multiplier);
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							SetStartStop();
 | 
				
			||||||
 | 
							await InvokeAsync(StateHasChanged);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public enum Selecting
 | 
					public enum Selecting
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								src/Connected.Components/Components/TimePicker.razor
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/Connected.Components/Components/TimePicker.razor
									
									
									
									
									
										Normal file
									
								
							@ -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>
 | 
				
			||||||
							
								
								
									
										20
									
								
								src/Connected.Components/Components/TimePicker.razor.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/Connected.Components/Components/TimePicker.razor.cs
									
									
									
									
									
										Normal file
									
								
							@ -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();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										22
									
								
								src/Connected.Components/Enums/TouchGesture.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/Connected.Components/Enums/TouchGesture.cs
									
									
									
									
									
										Normal file
									
								
							@ -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,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										76
									
								
								src/Connected.Components/Utilities/TouchGestures.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								src/Connected.Components/Utilities/TouchGestures.cs
									
									
									
									
									
										Normal file
									
								
							@ -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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user