Skip to content

Commit

Permalink
Merge pull request #835 from enisn/date-time-picker
Browse files Browse the repository at this point in the history
Better selection handler for Date & Time Picker
  • Loading branch information
enisn authored Dec 12, 2024
2 parents 553345e + 9706d1a commit cbf33a6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 57 deletions.
19 changes: 16 additions & 3 deletions src/UraniumUI.Material/Controls/DatePickerField.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Plainer.Maui.Controls;
using Microsoft.Maui.Platform;
using Plainer.Maui.Controls;
using System.ComponentModel;
using UraniumUI.Controls;
using UraniumUI.Pages;
Expand All @@ -11,8 +12,8 @@ namespace UraniumUI.Material.Controls;
[ContentProperty(nameof(Validations))]
public class DatePickerField : InputField
{
public DatePickerWrappedView DatePickerView => Content as DatePickerWrappedView;
public override View Content { get; set; } = new DatePickerWrappedView
public DatePickerView DatePickerView => Content as DatePickerView;
public override View Content { get; set; } = new DatePickerView
{
VerticalOptions = LayoutOptions.Center,
#if ANDROID
Expand Down Expand Up @@ -79,7 +80,19 @@ protected virtual void OnClearTapped(object parameter)
{
if (IsEnabled)
{
// Workaround for the selecting the same date again:
#if WINDOWS
if (DatePickerView.Handler.PlatformView is Microsoft.UI.Xaml.Controls.CalendarDatePicker dp)
{
dp.Date = null;
}
#elif ANDROID
DatePickerView.Date = DatePickerView.Date.AddMonths(-1);
#endif
// End of workaround

Date = null;

#if MACCATALYST
DatePickerView.Unfocus();
#endif
Expand Down
8 changes: 6 additions & 2 deletions src/UraniumUI.Material/Controls/TimePickerField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace UraniumUI.Material.Controls;
[ContentProperty(nameof(Validations))]
public class TimePickerField : InputField
{
public TimePickerWrappedView TimePickerView => Content as TimePickerWrappedView;
public override View Content { get; set; } = new TimePickerWrappedView
public TimePickerView TimePickerView => Content as TimePickerView;
public override View Content { get; set; } = new TimePickerView
{
VerticalOptions = LayoutOptions.Center,
#if WINDOWS
Expand Down Expand Up @@ -79,6 +79,10 @@ protected virtual void OnClearTapped(object parameter)
{
if (IsEnabled)
{
// Workaround for the selecting the same time again:
TimePickerView.Time += TimeSpan.FromSeconds(1);
// End of workaround

Time = null;
}
}
Expand Down
27 changes: 0 additions & 27 deletions src/UraniumUI/Controls/DatePickerWrappedView.cs

This file was deleted.

25 changes: 0 additions & 25 deletions src/UraniumUI/Controls/TimePickerWrappedView.cs

This file was deleted.

0 comments on commit cbf33a6

Please sign in to comment.