Skip to content

Commit

Permalink
feat: Add ability to style DatePickerFlyoutPresenter
Browse files Browse the repository at this point in the history
  • Loading branch information
kazo0 committed Mar 12, 2021
1 parent 610085f commit 1f96c0b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,8 @@ public async Task ValidateCalendarIdentifierProperty(string cid)

await RunOnUIThread.ExecuteAsync(() =>
{
datePicker.SelectedDate = (calendar.GetDateTime());
datePicker.CalendarIdentifier = cid;
datePicker.SelectedDate = (calendar.GetDateTime());
});
TestServices.WindowHelper.WaitForIdle();

Expand Down
38 changes: 31 additions & 7 deletions src/Uno.UI/UI/Xaml/Controls/DatePicker/DatePicker.Flyout.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Uno;
using Uno.UI;

namespace Windows.UI.Xaml.Controls
Expand Down Expand Up @@ -27,16 +28,31 @@ public bool UseNativeStyle
set => SetValue(UseNativeStyleProperty, value);
}

#if __IOS__ || __ANDROID__

/// <summary>
/// FlyoutPresenterStyle is an Uno-only property to allow the styling of the DatePicker's FlyoutPresenter.
/// </summary>
[UnoOnly]
public Style FlyoutPresenterStyle
{
get => (Style)this.GetValue(FlyoutPresenterStyleProperty);
set => this.SetValue(FlyoutPresenterStyleProperty, value);
}

public static DependencyProperty FlyoutPresenterStyleProperty { get; } =
DependencyProperty.Register(
nameof(FlyoutPresenterStyle),
typeof(Style),
typeof(DatePicker),
new FrameworkPropertyMetadata(
default(Style),
FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext));


private Lazy<DatePickerFlyout> _lazyFlyout;

private DatePickerFlyout _flyout => _lazyFlyout.Value;

#else
private readonly DatePickerFlyout _flyout = new DatePickerFlyout();

#endif

private void InitPartial()
{
Expand All @@ -45,7 +61,7 @@ DatePickerFlyout CreateFlyout()
{
var f = UseNativeStyle
? new NativeDatePickerFlyout()
: new DatePickerFlyout();
: CreateManagedDatePickerFlyout();

f.DatePicked += OnPicked;

Expand All @@ -54,7 +70,7 @@ DatePickerFlyout CreateFlyout()

_lazyFlyout = new Lazy<DatePickerFlyout>(CreateFlyout);
#else
_flyout.DatePicked += OnPicked;
_lazyFlyout = new Lazy<DatePickerFlyout>(CreateManagedDatePickerFlyout);
#endif

void OnPicked(DatePickerFlyout snd, DatePickedEventArgs evt)
Expand All @@ -67,6 +83,14 @@ void OnPicked(DatePickerFlyout snd, DatePickedEventArgs evt)
DateChanged?.Invoke(this, new DatePickerValueChangedEventArgs(evt.NewDate, evt.OldDate));
}
}

DatePickerFlyout CreateManagedDatePickerFlyout()
{
var flyout = new DatePickerFlyout() { DatePickerFlyoutPresenterStyle = FlyoutPresenterStyle };
flyout.DatePicked += OnPicked;

return flyout;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,20 @@ public DateTimeOffset MaxYear
)
);

public Style DatePickerFlyoutPresenterStyle
{
get { return (Style)this.GetValue(DatePickerFlyoutPresenterStyleProperty); }
set { this.SetValue(DatePickerFlyoutPresenterStyleProperty, value); }
}

public static DependencyProperty DatePickerFlyoutPresenterStyleProperty { get; } =
DependencyProperty.Register(
nameof(DatePickerFlyoutPresenterStyle),
typeof(Style),
typeof(DatePickerFlyout),
new FrameworkPropertyMetadata(
default(Style),
FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,11 @@ protected override void OnApplyTemplate()
_tpYearSource = spCollection;
}

RefreshSetup();
if (_calendarIdentifier != null)
{
RefreshSetup();
}

((IDatePickerFlyoutPresenter)this).SetAcceptDismissButtonsVisibility(_acceptDismissButtonsVisible);
// Apply a shadow
bool isDefaultShadowEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ protected override void OnConfirmed()
protected override Control CreatePresenter()
{
DatePickerFlyoutPresenter spFlyoutPresenter;
spFlyoutPresenter = new DatePickerFlyoutPresenter();
spFlyoutPresenter = new DatePickerFlyoutPresenter()
{
Style = DatePickerFlyoutPresenterStyle
};
_tpPresenter = spFlyoutPresenter;
return _tpPresenter as Control;
}
Expand Down

0 comments on commit 1f96c0b

Please sign in to comment.