Skip to content

Commit

Permalink
feat(iOS): Add TimePicker Feature Flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpinedam authored and jeromelaban committed Nov 27, 2020
1 parent 9171f2e commit c332a25
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 35 deletions.
9 changes: 8 additions & 1 deletion src/Uno.UI/FeatureConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;
using Windows.UI.Xaml;
Expand Down Expand Up @@ -450,5 +450,12 @@ public static class Xaml
[EditorBrowsable(EditorBrowsableState.Never)]
public static int MaxRecursiveResolvingDepth { get; set; } = 12;
}

public static class TimePicker
{
#if __IOS__
public static bool UseLegacyStyle { get; set; } = false;
#endif
}
}
}
42 changes: 10 additions & 32 deletions src/Uno.UI/UI/Xaml/Controls/TimePicker/TimePickerSelector.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,10 @@ namespace Windows.UI.Xaml.Controls
{
public partial class TimePickerSelector
{
private readonly UIDatePickerStyle _iOSDefaultStyle = UIDatePickerStyle.Wheels;

private UIDatePicker _picker;
private NSDate _initialTime;
private NSDate _newDate;

partial void InitPartial()
{
ResourceResolver.ApplyResource(this, UsePlatformDefaultStyleProperty, "TimePickerSelectorUsePlatformDefaultStyle", isThemeResourceExtension: false);
}

private protected override void OnLoaded()
{
base.OnLoaded();
Expand Down Expand Up @@ -155,38 +148,23 @@ private protected override void OnUnloaded()
base.OnUnloaded();
}

/// <summary>
/// Used to set whether or not we want to use the default <see cref="PreferredDatePickerStyle" /> specified for the os Version
/// Default value is False
/// </summary>
public bool UsePlatformDefaultStyle
{
get => (bool)GetValue(UsePlatformDefaultStyleProperty);
set => SetValue(UsePlatformDefaultStyleProperty, value);
}

public static DependencyProperty UsePlatformDefaultStyleProperty { get; } =
DependencyProperty.Register(
nameof(UsePlatformDefaultStyle),
typeof(bool),
typeof(TimePickerSelector),
new FrameworkPropertyMetadata(
defaultValue: false,
propertyChangedCallback: (s, e) => ((TimePickerSelector)s)?.OnUseDefaultStyleChanged()
));

private void OnUseDefaultStyleChanged() => UpdatePickerStyle();

private void UpdatePickerStyle()
{
if (_picker == null)
{
return;
}

_picker.PreferredDatePickerStyle = UIDevice.CurrentDevice.CheckSystemVersion(14, 0) && UsePlatformDefaultStyle
? UIDatePickerStyle.Inline
: _iOSDefaultStyle;
if (UIDevice.CurrentDevice.CheckSystemVersion(14, 0))
{
_picker.PreferredDatePickerStyle = FeatureConfiguration.TimePicker.UseLegacyStyle
? UIDatePickerStyle.Wheels
: UIDatePickerStyle.Inline;
}
else
{
_picker.PreferredDatePickerStyle = UIDatePickerStyle.Wheels;
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/Uno.UI/UI/Xaml/Style/Generic/Generic.Native.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@

<!--iOS14 feature flag-->
<x:Boolean x:Key="DatePickerUsePlatformDefaultStyle">False</x:Boolean>
<x:Boolean x:Key="TimePickerUsePlatformDefaultStyle">False</x:Boolean>

<ios:StaticResource x:Key="DatePickerSelectorUsePlatformDefaultStyle" ResourceKey="DatePickerUsePlatformDefaultStyle" />
<ios:StaticResource x:Key="TimePickerSelectorUsePlatformDefaultStyle" ResourceKey="TimePickerUsePlatformDefaultStyle" />
<!--iOS14 feature flag-->

<!-- Default native Button styles -->
Expand Down

0 comments on commit c332a25

Please sign in to comment.