Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Compatibility/Core/src/Windows/TimePickerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
Margin="6, 0"
Style="{StaticResource IsFocusedTextStyle}"/>
</HorizontalStackLayout>
</VerticalStackLayout>
<Label
Text="Set to null"
Style="{StaticResource Headline}"/>
<TimePicker
x:Name="NullTimePicker"
Time="{x:Null}"/>
<Button Text="Set to null" Clicked="SetTimePickerToNull" />
<Button Text="Set to now" Clicked="SetTimePickerToNow" />
</VerticalStackLayout>
</views:BasePage.Content>
</views:BasePage>
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public TimePickerPage()
UpdateTimePickerBackground();
}

void OnUpdateBackgroundButtonClicked(object sender, System.EventArgs e)
void OnUpdateBackgroundButtonClicked(object sender, EventArgs e)
{
UpdateTimePickerBackground();
}

void OnClearBackgroundButtonClicked(object sender, System.EventArgs e)
void OnClearBackgroundButtonClicked(object sender, EventArgs e)
{
BackgroundTimePicker.Background = null;
}
Expand All @@ -39,5 +39,15 @@ void UpdateTimePickerBackground()
}
};
}

void SetTimePickerToNull(object sender, EventArgs e)
{
NullTimePicker.Time = null;
}

void SetTimePickerToNow(object sender, EventArgs e)
{
NullTimePicker.Time = DateTime.Now.TimeOfDay;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,6 @@ Microsoft.Maui.Controls.SearchBar.ReturnType.set -> void
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
*REMOVED*Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan
Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan?
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,5 @@ override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertFrom(System.Comp
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.ToNSAttributedString(this Microsoft.Maui.Controls.FormattedString! formattedString, Microsoft.Maui.IFontManager! fontManager, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> Foundation.NSAttributedString!
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.ToNSAttributedString(this Microsoft.Maui.Controls.Span! span, Microsoft.Maui.IFontManager! fontManager, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> Foundation.NSAttributedString!
*REMOVED*Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan
Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan?
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,6 @@ override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertTo(System.Com
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.ToNSAttributedString(this Microsoft.Maui.Controls.FormattedString! formattedString, Microsoft.Maui.IFontManager! fontManager, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> Foundation.NSAttributedString!
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.ToNSAttributedString(this Microsoft.Maui.Controls.Span! span, Microsoft.Maui.IFontManager! fontManager, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> Foundation.NSAttributedString!
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.ToNSAttributedString(this Microsoft.Maui.Controls.Span! span, Microsoft.Maui.IFontManager! fontManager, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> Foundation.NSAttributedString!
*REMOVED*Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan
Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan?
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,6 @@ Microsoft.Maui.Controls.SearchBar.ReturnType.set -> void
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
*REMOVED*Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan
Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan?
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,6 @@ override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertTo(System.Com
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.ToRunAndColorsTuples(this Microsoft.Maui.Controls.FormattedString! formattedString, Microsoft.Maui.IFontManager! fontManager, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> System.Collections.Generic.IEnumerable<System.Tuple<Microsoft.UI.Xaml.Documents.Run!, Microsoft.Maui.Graphics.Color!, Microsoft.Maui.Graphics.Color!>!>!
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.UpdateInlines(this Microsoft.UI.Xaml.Controls.TextBlock! textBlock, Microsoft.Maui.IFontManager! fontManager, Microsoft.Maui.Controls.FormattedString! formattedString, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> void
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.UpdateInlines(this Microsoft.UI.Xaml.Controls.TextBlock! textBlock, Microsoft.Maui.IFontManager! fontManager, Microsoft.Maui.Controls.FormattedString! formattedString, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> void
*REMOVED*Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan
Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan?
4 changes: 3 additions & 1 deletion src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,6 @@ Microsoft.Maui.Controls.SearchBar.ReturnType.set -> void
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
*REMOVED*Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan
Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan?
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,6 @@ Microsoft.Maui.Controls.SearchBar.ReturnType.set -> void
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
*REMOVED*Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan
Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan?
3 changes: 1 addition & 2 deletions src/Controls/src/Core/TimePicker/TimePicker.Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
using System;
using System;
using Microsoft.Maui.Controls.Compatibility;

namespace Microsoft.Maui.Controls
Expand Down
12 changes: 6 additions & 6 deletions src/Controls/src/Core/TimePicker/TimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public partial class TimePicker : View, IFontElement, ITextElement, IElementConf
public static readonly BindableProperty CharacterSpacingProperty = TextElement.CharacterSpacingProperty;

/// <summary>Bindable property for <see cref="Time"/>.</summary>
public static readonly BindableProperty TimeProperty = BindableProperty.Create(nameof(Time), typeof(TimeSpan), typeof(TimePicker), new TimeSpan(0), BindingMode.TwoWay,
public static readonly BindableProperty TimeProperty = BindableProperty.Create(nameof(Time), typeof(TimeSpan?), typeof(TimePicker), new TimeSpan(0), BindingMode.TwoWay,
validateValue: (bindable, value) =>
{
var time = (TimeSpan)value;
return time.TotalHours < 24 && time.TotalMilliseconds >= 0;
var time = (TimeSpan?)value;
return time is null || (time?.TotalHours < 24 && time?.TotalMilliseconds >= 0);
},
propertyChanged: TimePropertyChanged);

Expand Down Expand Up @@ -70,9 +70,9 @@ public double CharacterSpacing
}

/// <include file="../../docs/Microsoft.Maui.Controls/TimePicker.xml" path="//Member[@MemberName='Time']/Docs/*" />
public TimeSpan Time
public TimeSpan? Time
{
get { return (TimeSpan)GetValue(TimeProperty); }
get { return (TimeSpan?)GetValue(TimeProperty); }
set { SetValue(TimeProperty, value); }
}

Expand Down Expand Up @@ -157,7 +157,7 @@ void ITextElement.OnTextTransformChanged(TextTransform oldValue, TextTransform n

Font ITextStyle.Font => this.ToFont();

TimeSpan ITimePicker.Time
TimeSpan? ITimePicker.Time
{
get => Time;
set => SetValue(TimeProperty, value, SetterSpecificity.FromHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public override string DebugName
new PropertyTestCase<TextCell, string> ("Detail", v => v.Detail, (v, o) => v.Detail = o, () => null, "Foo"),
new PropertyTestCase<TextCell, Color> ("TextColor", v => v.TextColor, (v, o) => v.TextColor = o, () => null, new Color (0, 1, 0)),
new PropertyTestCase<TextCell, Color> ("DetailColor", v => v.DetailColor, (v, o) => v.DetailColor = o, () => null, new Color (0, 1, 0)),
new PropertyTestCase<TimePicker, TimeSpan> ("Time", v => v.Time, (v, o) => v.Time = o, () => default(TimeSpan), new TimeSpan (8, 0, 0)),
new PropertyTestCase<TimePicker, TimeSpan?> ("Time", v => v.Time, (v, o) => v.Time = o, () => default(TimeSpan), new TimeSpan (8, 0, 0)),
new PropertyTestCase<TimePicker, string> ("Format", v => v.Format, (v, o) => v.Format = o, () => "t", "T"),
new PropertyTestCase<ViewCell, View> ("View", v => v.View, (v, o) => v.View = o, () => null, new View ()),
new PropertyTestCase<WebView, WebViewSource> ("Source", v => v.Source, (v, o) => v.Source = o, () => null, new UrlWebViewSource { Url = "Foo" }),
Expand Down
15 changes: 14 additions & 1 deletion src/Controls/tests/Core.UnitTests/TimePickerUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ public void ZeroTimeIsValid()
};
}

[Fact]
public void NullTimeIsValid()
{
var timePicker = new TimePicker
{
Time = null
};

Assert.Null(timePicker.Time);
}

[Fact]
public void TestTimeSelected()
{
Expand All @@ -57,7 +68,9 @@ public void TestTimeSelected()
public static object[] TimeSpans = {
new object[] { new TimeSpan (), new TimeSpan(9, 0, 0) },
new object[] { new TimeSpan(9, 0, 0), new TimeSpan(17, 30, 0) },
new object[] { new TimeSpan(23, 59, 59), new TimeSpan(0, 0, 0) }
new object[] { new TimeSpan(23, 59, 59), new TimeSpan(0, 0, 0) },
new object[] { new TimeSpan(23, 59, 59), null },
new object[] { null, new TimeSpan(23, 59, 59) },
};

public static IEnumerable<object[]> TimeSpansData()
Expand Down
25 changes: 12 additions & 13 deletions src/Core/src/Core/ITimePicker.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using System;

namespace Microsoft.Maui
namespace Microsoft.Maui;

/// <summary>
/// Represents a <see cref="IView"/> that allows the user to select a time.
/// </summary>
public interface ITimePicker : IView, ITextStyle
{
/// <summary>
/// Represents a View that allows the user to select a time.
/// The format of the time to display to the user.
/// </summary>
public interface ITimePicker : IView, ITextStyle
{
/// <summary>
/// The format of the time to display to the user.
/// </summary>
string Format { get; }
string Format { get; }

/// <summary>
/// Gets the displayed time.
/// </summary>
TimeSpan Time { get; set; }
}
/// <summary>
/// Gets or sets the selected time.
/// </summary>
TimeSpan? Time { get; set; }
}
Loading
Loading