Skip to content

Commit

Permalink
Merge pull request #1981 from southworkscom/feature/1946
Browse files Browse the repository at this point in the history
Deprecating PullToRefreshListView for controls available in next Windows release
  • Loading branch information
nmetulev authored Apr 30, 2018
2 parents b44a847 + 252eab9 commit 4fd0046
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 55 deletions.
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<IsUwpProject Condition="'$(IsDesignProject)' != 'true'">$(MSBuildProjectName.Contains('Uwp'))</IsUwpProject>
<IsSampleProject>$(MSBuildProjectName.Contains('Sample'))</IsSampleProject>


<UwpMetaPackageVersion>6.0.8</UwpMetaPackageVersion>
<DefaultTargetPlatformVersion>17134</DefaultTargetPlatformVersion>
<DefaultTargetPlatformMinVersion>14393</DefaultTargetPlatformMinVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
public sealed partial class PullToRefreshListViewPage : IXamlRenderListener
{
#pragma warning disable CS0618
private readonly ObservableCollection<Item> _items;

public PullToRefreshListViewPage()
Expand Down Expand Up @@ -50,5 +51,6 @@ private void ListView_RefreshCommand(object sender, EventArgs e)
{
AddItems();
}
#pragma warning restore CS0618
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
Background="White"
OverscrollLimit="@[OverscrollLimit:DoubleSlider:0.4:0-1]"
PullThreshold="@[PullThreshold:Slider:100:50-300]"
IsPullToRefreshWithMouseEnabled="@[IsPullToRefreshWithMouseEnabled:Bool:True]">
IsPullToRefreshWithMouseEnabled="@[IsPullToRefreshWithMouseEnabled:Bool:True]"
UseRefreshContainerWhenPossible="@[UseRefreshContainerWhenPossible:Bool:True]">
<controls:PullToRefreshListView.ItemTemplate>
<DataTemplate>
<TextBlock AutomationProperties.Name="{Binding Title}"
Expand Down
4 changes: 3 additions & 1 deletion Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@
{
"Name": "PullToRefreshListView",
"Type": "PullToRefreshListViewPage",
"About": "PullToRefreshListView is derived from the built in ListView in the Universal Windows Platform. It enables the popular Pull To Refresh pattern.",
"About": "The PullToRefreshListView will be removed in a future major release. Please use the RefreshContainer control available in the 1803 version of Windows.",
"CodeUrl": "https://github.com/Microsoft/UWPCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/PullToRefreshListView",
"CodeFile": "PullToRefreshListViewCode.bind",
"XamlCodeFile": "PullToRefreshListViewXaml.bind",
"Icon": "/SamplePages/PullToRefreshListView/PullToRefreshListView.png",
"BadgeUpdateVersionRequired": "DEPRECATED",
"DeprecatedWarning": "The PullToRefreshListView will be removed in a future major release. Please use the RefreshContainer control available in the 1803 version of Windows.",
"DocumentationUrl": "https://raw.githubusercontent.com/Microsoft/UWPCommunityToolkit/master/docs/controls/PullToRefreshListview.md"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Windows.Input;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using Windows.Foundation;
using Windows.Foundation.Metadata;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
Expand All @@ -33,6 +34,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
[TemplatePart(Name = PartIndicatorTransform, Type = typeof(CompositeTransform))]
[TemplatePart(Name = PartDefaultIndicatorContent, Type = typeof(TextBlock))]
[TemplatePart(Name = PullAndReleaseIndicatorContent, Type = typeof(ContentPresenter))]
[Obsolete("The PullToRefreshListView will be removed in a future major release. Please use the RefreshContainer control available in the 1803 version of Windows")]
public class PullToRefreshListView : ListView
{
/// <summary>
Expand Down Expand Up @@ -95,6 +97,17 @@ public class PullToRefreshListView : ListView
public static readonly DependencyProperty IsPullToRefreshWithMouseEnabledProperty =
DependencyProperty.Register(nameof(IsPullToRefreshWithMouseEnabled), typeof(bool), typeof(PullToRefreshListView), new PropertyMetadata(false));

/// <summary>
/// Identifies the <see cref="UseRefreshContainerWhenPossible"/> dependency property
/// </summary>
public static readonly DependencyProperty UseRefreshContainerWhenPossibleProperty =
DependencyProperty.Register(nameof(UseRefreshContainerWhenPossible), typeof(bool), typeof(PullToRefreshListView), new PropertyMetadata(false, OnUseRefreshContainerWhenPossibleChanged));

/// <summary>
/// Gets a value indicating whether <see cref="RefreshContainer"/> is supported
/// </summary>
public static bool IsRefreshContainerSupported { get; } = ApiInformation.IsTypePresent("Windows.UI.Xaml.Controls.RefreshContainer");

private const string PartRoot = "Root";
private const string PartScroller = "ScrollViewer";
private const string PartContentTransform = "ContentTransform";
Expand All @@ -103,6 +116,7 @@ public class PullToRefreshListView : ListView
private const string PartIndicatorTransform = "RefreshIndicatorTransform";
private const string PartDefaultIndicatorContent = "DefaultIndicatorContent";
private const string PullAndReleaseIndicatorContent = "PullAndReleaseIndicatorContent";
private const string PartRefreshContainer = "RefreshContainer";

private Border _root;
private Border _refreshIndicatorBorder;
Expand All @@ -123,6 +137,20 @@ public class PullToRefreshListView : ListView
private double _overscrollMultiplier;
private bool _isManipulatingWithMouse;
private double _startingVerticalOffset;
private ControlTemplate _previousTemplateUsed;
private RefreshContainer _refreshContainer;

private bool UsingRefreshContainer => IsRefreshContainerSupported && UseRefreshContainerWhenPossible;

/// <summary>
/// Gets or sets a value indicating whether the HamburgerMenu should use the NavigationView when possible (Fall Creators Update and above)
/// When set to true and the device supports NavigationView, the HamburgerMenu will use a template based on NavigationView
/// </summary>
public bool UseRefreshContainerWhenPossible
{
get { return (bool)GetValue(UseRefreshContainerWhenPossibleProperty); }
set { SetValue(UseRefreshContainerWhenPossibleProperty, value); }
}

/// <summary>
/// Occurs when the user has requested content to be refreshed
Expand Down Expand Up @@ -185,6 +213,23 @@ protected override void OnApplyTemplate()
_root.ManipulationCompleted -= Scroller_ManipulationCompleted;
}

_root = null;
_refreshIndicatorBorder = null;
_refreshIndicatorTransform = null;
_scroller = null;
_contentTransform = null;
_headerTransform = null;
_footerTransform = null;
_scrollerContent = null;
_defaultIndicatorContent = null;
_pullAndReleaseIndicatorContent = null;
_scrollerVerticalScrollBar = null;

if (UsingRefreshContainer)
{
OnApplyRefreshContainerTemplate();
}

_root = GetTemplateChild(PartRoot) as Border;
_scroller = GetTemplateChild(PartScroller) as ScrollViewer;
_scrollerContent = GetTemplateChild(PartScrollerContent) as ItemsPresenter;
Expand Down Expand Up @@ -225,6 +270,21 @@ protected override void OnApplyTemplate()
base.OnApplyTemplate();
}

private void OnApplyRefreshContainerTemplate()
{
if (_refreshContainer != null)
{
_refreshContainer.RefreshRequested -= RefreshContainer_RefreshRequested;
}

_refreshContainer = GetTemplateChild(PartRefreshContainer) as RefreshContainer;

if (_refreshContainer != null)
{
_refreshContainer.RefreshRequested += RefreshContainer_RefreshRequested;
}
}

private void Scroller_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
// Other input are already managed by the scroll viewer
Expand Down Expand Up @@ -629,6 +689,18 @@ private void ScrollerVerticalScrollBar_PointerExited(object sender, PointerRoute
}
}

private void RefreshContainer_RefreshRequested(object sender, RefreshRequestedEventArgs args)
{
using (var deferral = args.GetDeferral())
{
RefreshRequested?.Invoke(this, EventArgs.Empty);
if (RefreshCommand != null && RefreshCommand.CanExecute(null))
{
RefreshCommand.Execute(null);
}
}
}

/// <summary>
/// Gets or sets the Overscroll Limit. Value between 0 and 1 where 1 is the height of the control. Default is 0.3
/// </summary>
Expand Down Expand Up @@ -663,6 +735,30 @@ private static void OnReleaseToRefreshLabelChanged(DependencyObject d, Dependenc
d.SetValue(ReleaseToRefreshLabelProperty, e.NewValue);
}

private static void OnUseRefreshContainerWhenPossibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var list = d as PullToRefreshListView;
if (list == null)
{
return;
}

if (list.UseRefreshContainerWhenPossible && IsRefreshContainerSupported)
{
ResourceDictionary dict = new ResourceDictionary();
dict.Source = new System.Uri("ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/PullToRefreshListView/PullToRefreshListViewRefreshContainerTemplate.xaml");
list._previousTemplateUsed = list.Template;
list.Template = dict["PullToRefreshListViewRefreshContainerTemplate"] as ControlTemplate;
}
else if (!list.UseRefreshContainerWhenPossible &&
e.OldValue is bool oldValue &&
oldValue &&
list._previousTemplateUsed != null)
{
list.Template = list._previousTemplateUsed;
}
}

/// <summary>
/// Gets or sets the PullThreshold in pixels for when Refresh should be Requested. Default is 100
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.Toolkit.Uwp.UI.Controls">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/PullToRefreshListView/PullToRefreshListViewTemplate.xaml" />
</ResourceDictionary.MergedDictionaries>

<Style TargetType="local:PullToRefreshListView">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="TabNavigation" Value="Once" />
Expand Down Expand Up @@ -33,54 +37,6 @@
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:PullToRefreshListView">
<Border x:Name="Root"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<Border x:Name="RefreshIndicator"
VerticalAlignment="Top">
<Grid>
<ContentPresenter x:Name="PullAndReleaseIndicatorContent"
HorizontalAlignment="Center"
FontSize="20" />
<ContentPresenter Content="{TemplateBinding RefreshIndicatorContent}" />
</Grid>
<Border.RenderTransform>
<CompositeTransform x:Name="RefreshIndicatorTransform" />
</Border.RenderTransform>
</Border>
<ScrollViewer x:Name="ScrollViewer"
AutomationProperties.AccessibilityView="Raw"
BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
IsHorizontalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsHorizontalScrollChainingEnabled}"
IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
IsVerticalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsVerticalScrollChainingEnabled}"
TabNavigation="{TemplateBinding TabNavigation}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}">
<ItemsPresenter x:Name="ItemsPresenter"
Padding="{TemplateBinding Padding}"
Footer="{TemplateBinding Footer}"
FooterTemplate="{TemplateBinding FooterTemplate}"
FooterTransitions="{TemplateBinding FooterTransitions}"
Header="{TemplateBinding Header}"
HeaderTemplate="{TemplateBinding HeaderTemplate}"
HeaderTransitions="{TemplateBinding HeaderTransitions}" />
</ScrollViewer>
</Grid>

</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template" Value="{StaticResource PullToRefreshListViewTemplate}" />
</Style>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.Toolkit.Uwp.UI.Controls">

<ControlTemplate x:Key="PullToRefreshListViewRefreshContainerTemplate" TargetType="local:PullToRefreshListView">
<Border x:Name="Root"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<RefreshContainer x:Name="RefreshContainer">
<ScrollViewer x:Name="ScrollViewer"
AutomationProperties.AccessibilityView="Raw"
BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
IsHorizontalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsHorizontalScrollChainingEnabled}"
IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
IsVerticalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsVerticalScrollChainingEnabled}"
TabNavigation="{TemplateBinding TabNavigation}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}">
<ItemsPresenter x:Name="ItemsPresenter"
Padding="{TemplateBinding Padding}"
Footer="{TemplateBinding Footer}"
FooterTemplate="{TemplateBinding FooterTemplate}"
FooterTransitions="{TemplateBinding FooterTransitions}"
Header="{TemplateBinding Header}"
HeaderTemplate="{TemplateBinding HeaderTemplate}"
HeaderTransitions="{TemplateBinding HeaderTransitions}" />
</ScrollViewer>
</RefreshContainer>
</Grid>

</Border>
</ControlTemplate>
</ResourceDictionary>
Loading

0 comments on commit 4fd0046

Please sign in to comment.