From 2b65e7727dba3d14953e573effc5d466453eb858 Mon Sep 17 00:00:00 2001 From: Gerald Versluis Date: Thu, 20 Feb 2025 14:37:00 +0100 Subject: [PATCH 1/5] Nullable TimePicker.Time --- .../Android/Renderers/TimePickerRenderer.cs | 8 +- .../Core/src/Windows/TimePickerRenderer.cs | 2 +- .../src/iOS/Renderers/TimePickerRenderer.cs | 6 +- .../Pages/Controls/TimePickerPage.xaml | 10 +- .../Pages/Controls/TimePickerPage.xaml.cs | 14 +- .../net-android/PublicAPI.Shipped.txt | 1 - .../net-android/PublicAPI.Unshipped.txt | 4 +- .../PublicAPI/net-ios/PublicAPI.Shipped.txt | 1 - .../PublicAPI/net-ios/PublicAPI.Unshipped.txt | 2 + .../net-maccatalyst/PublicAPI.Shipped.txt | 1 - .../net-maccatalyst/PublicAPI.Unshipped.txt | 4 +- .../PublicAPI/net-tizen/PublicAPI.Shipped.txt | 1 - .../net-tizen/PublicAPI.Unshipped.txt | 4 +- .../net-windows/PublicAPI.Shipped.txt | 1 - .../net-windows/PublicAPI.Unshipped.txt | 4 +- .../Core/PublicAPI/net/PublicAPI.Shipped.txt | 1 - .../PublicAPI/net/PublicAPI.Unshipped.txt | 4 +- .../netstandard/PublicAPI.Shipped.txt | 1 - .../netstandard/PublicAPI.Unshipped.txt | 4 +- .../src/Core/TimePicker/TimePicker.Mapper.cs | 3 +- .../src/Core/TimePicker/TimePicker.cs | 12 +- .../Core.UnitTests/TimePickerUnitTest.cs | 16 +- src/Core/src/Core/ITimePicker.cs | 25 ++- .../DatePicker/DatePickerHandler.iOS.cs | 2 +- .../TimePicker/TimePickerHandler.Android.cs | 14 +- .../TimePicker/TimePickerHandler.Windows.cs | 3 +- .../Platform/Android/TimePickerExtensions.cs | 31 ++- .../Platform/Windows/TimePickerExtensions.cs | 127 ++++++------ .../src/Platform/iOS/DatePickerExtensions.cs | 193 +++++++++--------- src/Core/src/Platform/iOS/MauiTimePicker.cs | 5 +- .../src/Platform/iOS/TimePickerExtensions.cs | 111 +++++----- .../net-android/PublicAPI.Shipped.txt | 1 - .../net-android/PublicAPI.Unshipped.txt | 2 + .../PublicAPI/net-ios/PublicAPI.Shipped.txt | 1 - .../PublicAPI/net-ios/PublicAPI.Unshipped.txt | 2 + .../net-maccatalyst/PublicAPI.Shipped.txt | 1 - .../net-maccatalyst/PublicAPI.Unshipped.txt | 2 + .../PublicAPI/net-tizen/PublicAPI.Shipped.txt | 1 - .../net-tizen/PublicAPI.Unshipped.txt | 4 +- .../net-windows/PublicAPI.Shipped.txt | 1 - .../net-windows/PublicAPI.Unshipped.txt | 4 +- .../src/PublicAPI/net/PublicAPI.Shipped.txt | 1 - .../src/PublicAPI/net/PublicAPI.Unshipped.txt | 2 + .../netstandard/PublicAPI.Shipped.txt | 1 - .../netstandard/PublicAPI.Unshipped.txt | 2 + .../netstandard2.0/PublicAPI.Shipped.txt | 1 - .../netstandard2.0/PublicAPI.Unshipped.txt | 2 + .../tests/DeviceTests/Stubs/TimePickerStub.cs | 5 +- 48 files changed, 350 insertions(+), 298 deletions(-) diff --git a/src/Compatibility/Core/src/Android/Renderers/TimePickerRenderer.cs b/src/Compatibility/Core/src/Android/Renderers/TimePickerRenderer.cs index 83203a21169d..8e4b05ea7ba6 100644 --- a/src/Compatibility/Core/src/Android/Renderers/TimePickerRenderer.cs +++ b/src/Compatibility/Core/src/Android/Renderers/TimePickerRenderer.cs @@ -140,7 +140,7 @@ void IPickerRenderer.OnClick() TimePicker view = Element; ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, true); - _dialog = CreateTimePickerDialog(view.Time.Hours, view.Time.Minutes); + _dialog = CreateTimePickerDialog(view.Time?.Hours ?? 0, view.Time?.Minutes ?? 0); _dialog.Show(); } @@ -159,17 +159,17 @@ void OnCancelButtonClicked(object sender, EventArgs e) } [PortHandler] - void SetTime(TimeSpan time) + void SetTime(TimeSpan? time) { if (String.IsNullOrEmpty(Element.Format)) { var timeFormat = "t"; - EditText.Text = DateTime.Today.Add(time).ToString(timeFormat); + EditText.Text = DateTime.Today.Add(time ?? TimeSpan.Zero).ToString(timeFormat); } else { var timeFormat = Element.Format; - EditText.Text = DateTime.Today.Add(time).ToString(timeFormat); + EditText.Text = DateTime.Today.Add(time ?? TimeSpan.Zero).ToString(timeFormat); } Element.InvalidateMeasureNonVirtual(Internals.InvalidationTrigger.MeasureChanged); diff --git a/src/Compatibility/Core/src/Windows/TimePickerRenderer.cs b/src/Compatibility/Core/src/Windows/TimePickerRenderer.cs index ded027021259..4d9139a7e415 100644 --- a/src/Compatibility/Core/src/Windows/TimePickerRenderer.cs +++ b/src/Compatibility/Core/src/Windows/TimePickerRenderer.cs @@ -173,7 +173,7 @@ void UpdateFont() [PortHandler] void UpdateTime() { - Control.Time = Element.Time; + Control.Time = Element.Time ?? TimeSpan.Zero; if (Element.Format?.Contains('H', StringComparison.Ordinal) == true) { Control.ClockIdentifier = "24HourClock"; diff --git a/src/Compatibility/Core/src/iOS/Renderers/TimePickerRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/TimePickerRenderer.cs index fe997dc64d2c..d6ac8915442e 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/TimePickerRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/TimePickerRenderer.cs @@ -217,7 +217,7 @@ void UpdateCharacterSpacing() [PortHandler] void UpdateTime() { - _picker.Date = new DateTime(1, 1, 1).Add(Element.Time).ToNSDate(); + _picker.Date = new DateTime(1, 1, 1).Add(Element.Time ?? TimeSpan.Zero).ToNSDate(); string iOSLocale = NSLocale.CurrentLocale.CountryCode; var cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures) .Where(c => c.Name.EndsWith("-" + iOSLocale)).FirstOrDefault(); @@ -228,12 +228,12 @@ void UpdateTime() { string timeformat = cultureInfos.DateTimeFormat.ShortTimePattern; NSLocale locale = new NSLocale(cultureInfos.TwoLetterISOLanguageName); - Control.Text = DateTime.Today.Add(Element.Time).ToString(timeformat, cultureInfos); + Control.Text = DateTime.Today.Add(Element.Time ?? TimeSpan.Zero).ToString(timeformat, cultureInfos); _picker.Locale = locale; } else { - Control.Text = DateTime.Today.Add(Element.Time).ToString(Element.Format, cultureInfos); + Control.Text = DateTime.Today.Add(Element.Time ?? TimeSpan.Zero).ToString(Element.Format, cultureInfos); } if (Element.Format?.Contains('H', StringComparison.Ordinal) == true) diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/TimePickerPage.xaml b/src/Controls/samples/Controls.Sample/Pages/Controls/TimePickerPage.xaml index 13f7d25fc708..63d6956c74f5 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Controls/TimePickerPage.xaml +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/TimePickerPage.xaml @@ -87,6 +87,14 @@ Margin="6, 0" Style="{StaticResource IsFocusedTextStyle}"/> - +