Skip to content

Commit

Permalink
feat(iOS): Add DatePicker FeatureFlag
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpinedam authored and jeromelaban committed Nov 27, 2020
1 parent c332a25 commit 4966060
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 39 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 @@ -451,6 +451,13 @@ public static class Xaml
public static int MaxRecursiveResolvingDepth { get; set; } = 12;
}

public static class DatePicker
{
#if __IOS__
public static bool UseLegacyStyle { get; set; } = false;
#endif
}

public static class TimePicker
{
#if __IOS__
Expand Down
42 changes: 10 additions & 32 deletions src/Uno.UI/UI/Xaml/Controls/DatePicker/DatePickerSelector.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ public partial class DatePickerSelector
private NSDate _initialValue;
private NSDate _newValue;

private readonly UIDatePickerStyle _iOSDefaultStyle = UIDatePickerStyle.Wheels;

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

private protected override void OnLoaded()
{
base.OnLoaded();
Expand Down Expand Up @@ -169,38 +162,23 @@ private DateTimeOffset ConvertFromNative(NSDate value)
return date;
}

/// <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(DatePickerSelector),
new FrameworkPropertyMetadata(
defaultValue: false,
propertyChangedCallback: (s, e) => ((DatePickerSelector)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.DatePicker.UseLegacyStyle
? UIDatePickerStyle.Wheels
: UIDatePickerStyle.Inline;
}
else
{
_picker.PreferredDatePickerStyle = UIDatePickerStyle.Wheels;
}
}
}
}
6 changes: 0 additions & 6 deletions src/Uno.UI/UI/Xaml/Style/Generic/Generic.Native.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
xmlns:not_wasm="http://uno.ui/not_wasm"
mc:Ignorable="d xamarin ios android skia wasm not_wasm net461 macos">

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

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

<!-- Default native Button styles -->
<android:Style x:Key="NativeDefaultButton"
TargetType="Button">
Expand Down

0 comments on commit 4966060

Please sign in to comment.