Skip to content

Commit

Permalink
feat(datepicker): Use LoopingSelector instead of ListView for non-nat…
Browse files Browse the repository at this point in the history
…ive DatePicker.
  • Loading branch information
carldebilly committed Feb 25, 2021
1 parent 2bc77af commit 0a5203b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define FAKE_LOOPINGSELECTOR // LoopingSelector not implemented yet in Uno

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand All @@ -10,10 +8,6 @@
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Input;

#if FAKE_LOOPINGSELECTOR
using LoopingSelector = Windows.UI.Xaml.Controls.ListView;
#endif

using DateTime = System.DateTimeOffset;

namespace Windows.UI.Xaml.Controls
Expand Down Expand Up @@ -299,14 +293,14 @@ protected override void OnApplyTemplate()
LoopingSelector spMonthPicker;

//wrl.MakeAndInitialize<xaml_primitives.LoopingSelector>(spMonthPicker);
spMonthPicker = new LoopingSelector();
spMonthPicker = new LoopingSelector() {ShouldLoop = false};
_tpMonthPicker = spMonthPicker;
//spMonthPicker.As(spLSAsUI);
//spMonthPicker.As(spLSAsFE);
//spMonthPicker.As(spLSAsControl);
spLSAsControl = spMonthPicker;
//Don't set ItemWidth. We want the item to size to the width of its parent.
/* spMonthPicker.ItemHeight = itemHeight; NOT SUPPORTED BY LISTVIEW */
spMonthPicker.ItemHeight = itemHeight;
spLSAsControl.HorizontalContentAlignment = HorizontalAlignment.Left;
spLSAsControl.Padding = monthPadding;
spMonthPicker.Name = "MonthLoopingSelector";
Expand All @@ -330,14 +324,14 @@ protected override void OnApplyTemplate()
LoopingSelector spDayPicker;

//wrl.MakeAndInitialize<xaml_primitives.LoopingSelector>(spDayPicker);
spDayPicker = new LoopingSelector();
spDayPicker = new LoopingSelector() { ShouldLoop = false };
_tpDayPicker = spDayPicker;
//spDayPicker.As(spLSAsUI);
//spDayPicker.As(spLSAsFE);
//spDayPicker.As(spLSAsControl);
spLSAsControl = spDayPicker;
//Don't set ItemWidth. We want the item to size to the width of its parent.
/* spMonthPicker.ItemHeight = itemHeight; NOT SUPPORTED BY LISTVIEW */
spDayPicker.ItemHeight = itemHeight;
spLSAsControl.HorizontalContentAlignment = HorizontalAlignment.Center;
spLSAsControl.Padding = itemPadding;
spLSAsControl.Name = "DayLoopingSelector";
Expand All @@ -361,15 +355,15 @@ protected override void OnApplyTemplate()
LoopingSelector spYearPicker;

//wrl.MakeAndInitialize<xaml_primitives.LoopingSelector>(spYearPicker);
spYearPicker = new LoopingSelector();
spYearPicker = new LoopingSelector() { ShouldLoop = false };
_tpYearPicker = spYearPicker;
//spYearPicker.As(spLSAsUI);
//spYearPicker.As(spLSAsFE);
//spYearPicker.As(spLSAsControl);
spLSAsControl = spYearPicker;
/* spYearPicker.ShouldLoop = false; NOT SUPPORTED BY LISTVIEW */
//Don't set ItemWidth. We want the item to size to the width of its parent.
/* spMonthPicker.ItemHeight = itemHeight; NOT SUPPORTED BY LISTVIEW */
spYearPicker.ItemHeight = itemHeight;
spLSAsControl.HorizontalContentAlignment = HorizontalAlignment.Center;
spLSAsControl.Padding = itemPadding;
spLSAsControl.Name = "YearLoopingSelector";
Expand Down Expand Up @@ -464,16 +458,16 @@ protected override void OnApplyTemplate()
//IList<object> spCollectionAsInterface;

//wfci_.Vector<DependencyObject>.Make(spCollection);
spCollection = new ObservableCollection<object>();
spCollection = new List<object>();
//spCollection.As(spCollectionAsInterface);
//spCollectionAsInterface = spCollection;
_tpDaySource = spCollection;
//wfci_.Vector<DependencyObject>.Make(spCollection);
spCollection = new ObservableCollection<object>();
spCollection = new List<object>();
//spCollection.As(spCollectionAsInterface);
_tpMonthSource = spCollection;
//wfci_.Vector<DependencyObject>.Make(spCollection);
spCollection = new ObservableCollection<object>();
spCollection = new List<object>();
//spCollection.As(spCollectionAsInterface);
_tpYearSource = spCollection;
}
Expand Down Expand Up @@ -712,20 +706,17 @@ void ClearSelectors(
{
if (_tpDayPicker != null && clearDay)
{
//_tpDayPicker.Items = null;
_tpDayPicker.ItemsSource = null;
_tpDayPicker.Items = null;
}

if (_tpMonthPicker != null && clearMonth)
{
//_tpMonthPicker.Items = null;
_tpMonthPicker.ItemsSource = null;
_tpMonthPicker.Items = null;
}

if (_tpYearPicker != null && clearYear)
{
//_tpYearPicker.Items = null;
_tpYearPicker.ItemsSource = null;
_tpYearPicker.Items = null;
}
}

Expand Down Expand Up @@ -821,14 +812,13 @@ void RefreshSourcesAndSetSelectedIndices(
{
GenerateYears();
//_tpYearPicker.Items = _tpYearSource;
if (_tpYearPicker.ItemsSource != _tpYearSource)
if (_tpYearPicker.Items != _tpYearSource)
{
_tpYearPicker.ItemsSource = _tpYearSource;
_tpYearPicker.Items = _tpYearSource;
}
}

_tpYearPicker.SelectedIndex = yearIndex;
_tpYearPicker.ScrollIntoView(_tpYearPicker.SelectedItem);
}

if (_tpMonthPicker != null)
Expand All @@ -837,14 +827,13 @@ void RefreshSourcesAndSetSelectedIndices(
{
GenerateMonths(yearIndex);
//_tpMonthPicker.Items = _tpMonthSource;
if (_tpMonthPicker.ItemsSource != _tpMonthSource)
if (_tpMonthPicker.Items != _tpMonthSource)
{
_tpMonthPicker.ItemsSource = _tpMonthSource;
_tpMonthPicker.Items = _tpMonthSource;
}
}

_tpMonthPicker.SelectedIndex = monthIndex;
_tpMonthPicker.ScrollIntoView(_tpMonthPicker.SelectedItem);
}

if (_tpDayPicker != null)
Expand All @@ -853,14 +842,13 @@ void RefreshSourcesAndSetSelectedIndices(
{
GenerateDays(yearIndex, monthIndex);
//_tpDayPicker.Items = _tpDaySource;
if (_tpDayPicker.ItemsSource != _tpDaySource)
if (_tpDayPicker.Items != _tpDaySource)
{
_tpDayPicker.ItemsSource = _tpDaySource;
_tpDayPicker.Items = _tpDaySource;
}
}

_tpDayPicker.SelectedIndex = dayIndex;
_tpDayPicker.ScrollIntoView(_tpDayPicker.SelectedItem);
}

AllowReactionToSelectionChange();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Globalization;
using Windows.Globalization.DateTimeFormatting;
using Windows.UI.Xaml.Controls.Primitives;

using LoopingSelector = Windows.UI.Xaml.Controls.ListView;
using DateTime = System.DateTimeOffset;

namespace Windows.UI.Xaml.Controls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,11 @@ void IsTemplateAndItemsAttached(out bool result)

result = false;

if(ItemHeight == 0)
{
throw new InvalidOperationException("ItemHeight not set.");
}

if (_tpScrollViewer is { } &&
_tpPanel is { })
{
Expand Down

0 comments on commit 0a5203b

Please sign in to comment.