Skip to content

Commit

Permalink
Better selection handler for Date & Time Picker
Browse files Browse the repository at this point in the history
  • Loading branch information
enisn committed Dec 12, 2024
1 parent 0650f5d commit 21b3fa1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 82 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
53 changes: 28 additions & 25 deletions src/UraniumUI/Controls/AutoFormView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,41 +132,44 @@ private void Render()
return;
}

foreach (var property in EditingProperties)
using (_itemsLayout.Batch())
{
var createEditor = EditorMapping.FirstOrDefault(x => x.Key.IsAssignableFrom(property.PropertyType.AsNonNullable())).Value;
if (createEditor != null)
foreach (var property in EditingProperties)
{
var editor = createEditor(property, Options.PropertyNameFactory, Source);

foreach (var action in Options.PostEditorActions)
var createEditor = EditorMapping.FirstOrDefault(x => x.Key.IsAssignableFrom(property.PropertyType.AsNonNullable())).Value;
if (createEditor != null)
{
action(editor, property);
}
var editor = createEditor(property, Options.PropertyNameFactory, Source);

foreach (var action in Options.PostEditorActions)
{
action(editor, property);
}

if (editor is IValidatable validatable && Options.ValidationFactory != null)
if (editor is IValidatable validatable && Options.ValidationFactory != null)
{
validatable.Validations.AddRange(Options.ValidationFactory(property));
}

_itemsLayout.Children.Add(editor);
}
else if (ShowMissingProperties)
{
validatable.Validations.AddRange(Options.ValidationFactory(property));
_itemsLayout.Children.Add(new Label
{
Text = $"No editor for {property.Name} ({property.PropertyType})",
FontAttributes = FontAttributes.Italic
});
}

_itemsLayout.Children.Add(editor);
}
else if (ShowMissingProperties)

if (!_itemsLayout.Children.Contains(_footerLayout))
{
_itemsLayout.Children.Add(new Label
{
Text = $"No editor for {property.Name} ({property.PropertyType})",
FontAttributes = FontAttributes.Italic
});
_itemsLayout.Children.Add(_footerLayout);
OnShowSubmitButtonChanged();
OnShowResetButtonChanged();
}
}

if (!_itemsLayout.Children.Contains(_footerLayout))
{
_itemsLayout.Children.Add(_footerLayout);
OnShowSubmitButtonChanged();
OnShowResetButtonChanged();
}
}

Button? submitButton;
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 21b3fa1

Please sign in to comment.