diff --git a/src/UraniumUI.Material/Controls/DatePickerField.cs b/src/UraniumUI.Material/Controls/DatePickerField.cs index c22440f9..a2763bfd 100644 --- a/src/UraniumUI.Material/Controls/DatePickerField.cs +++ b/src/UraniumUI.Material/Controls/DatePickerField.cs @@ -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; @@ -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 @@ -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 diff --git a/src/UraniumUI.Material/Controls/TimePickerField.cs b/src/UraniumUI.Material/Controls/TimePickerField.cs index 308888df..0a17cf2d 100644 --- a/src/UraniumUI.Material/Controls/TimePickerField.cs +++ b/src/UraniumUI.Material/Controls/TimePickerField.cs @@ -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 @@ -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; } } diff --git a/src/UraniumUI/Controls/AutoFormView.cs b/src/UraniumUI/Controls/AutoFormView.cs index 1358b1b6..d7b8200d 100644 --- a/src/UraniumUI/Controls/AutoFormView.cs +++ b/src/UraniumUI/Controls/AutoFormView.cs @@ -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; diff --git a/src/UraniumUI/Controls/DatePickerWrappedView.cs b/src/UraniumUI/Controls/DatePickerWrappedView.cs deleted file mode 100644 index b5d95030..00000000 --- a/src/UraniumUI/Controls/DatePickerWrappedView.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Plainer.Maui.Controls; - -namespace UraniumUI.Controls; - -/// -/// TODO Revisit when the underlying dotnet/maui issue is fixed: https://github.com/dotnet/maui/issues/13156 -/// A workaround for abovementioned issue where the DateSelected event is not raised when the date is the same as the current date. -/// This "manually" raises the PropertyChanged event when the date is the same as the current date by briefly setting it to a different time before applying the actual value. -/// Alternatively, this workaround could be implemented in Plainer.Maui.Controls.DatePickerView directly. -/// -public class DatePickerWrappedView : DatePickerView, IDatePicker -{ - DateTime IDatePicker.Date - { - get => Date; - set - { - if (value == Date) - { - Date += TimeSpan.FromDays(1); - } - - Date = value; - OnPropertyChanged(nameof(Date)); - } - } -} diff --git a/src/UraniumUI/Controls/TimePickerWrappedView.cs b/src/UraniumUI/Controls/TimePickerWrappedView.cs deleted file mode 100644 index 90154cec..00000000 --- a/src/UraniumUI/Controls/TimePickerWrappedView.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Plainer.Maui.Controls; - -namespace UraniumUI.Controls; - - -/// -/// See explanation in -/// -public class TimePickerWrappedView : TimePickerView, ITimePicker -{ - TimeSpan ITimePicker.Time - { - get => Time; - set - { - if (value == Time) - { - Time += TimeSpan.FromSeconds(1); - } - - Time = value; - OnPropertyChanged(nameof(Time)); - } - } -}