Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Implemented colored refresh indicator for ListView pull-to-refresh (#…
Browse files Browse the repository at this point in the history
…2961)

* Implemented colored spinner for ListView pull-to-refresh

* Added back default spinner color

* Renamed away from "spinner" and did some default value magic

Color.Default reinstated, but also added the default black color in the iOS `UpdateRefreshControlColor` method. Seeing this also happens for the seperator color this is something that is necessary. If not, the spinner is invisible.

* Implemented default color on iOS and right property name on Android

For iOS, when the new `RefreshControlColor` has the default color, the `TintColor` for iOS is set to null, causing the color to be the default one.

Forgot to refactor the new name in the Android renderer, whoops

* Reinstated coloring on listview gallry page

* Implemented colored spinner for ListView pull-to-refresh

* Added back default spinner color

* Renamed away from "spinner" and did some default value magic

Color.Default reinstated, but also added the default black color in the iOS `UpdateRefreshControlColor` method. Seeing this also happens for the seperator color this is something that is necessary. If not, the spinner is invisible.

* Implemented default color on iOS and right property name on Android

For iOS, when the new `RefreshControlColor` has the default color, the `TintColor` for iOS is set to null, causing the color to be the default one.

Forgot to refactor the new name in the Android renderer, whoops

* Reinstated coloring on listview gallry page

* Added documentation for new property

* Fixed merge boo-boos
  • Loading branch information
jfversluis authored and rmarinho committed Nov 29, 2018
1 parent 43eb6b3 commit 0d08fd8
Show file tree
Hide file tree
Showing 6 changed files with 1,217 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using System.Threading;
using Xamarin.Forms.Internals;

using Xamarin.Forms.PlatformConfiguration;
Expand Down Expand Up @@ -267,6 +267,16 @@ protected override void Build(StackLayout stackLayout)
fastScrollItemContainer.View.On<Android>().SetIsFastScrollEnabled(true);
fastScrollItemContainer.View.ItemsSource = viewModel.CategorizedEmployees;

var refreshControlColorContainer = new ViewContainer<ListView>(Test.ListView.RefreshControlColor, new ListView());
InitializeElement(refreshControlColorContainer.View);
refreshControlColorContainer.View.RefreshControlColor = Color.Red;
refreshControlColorContainer.View.IsPullToRefreshEnabled = true;
refreshControlColorContainer.View.Refreshing += async (object sender, EventArgs e) => {
await Task.Delay(2000);
refreshControlColorContainer.View.IsRefreshing = false;
};
refreshControlColorContainer.View.ItemsSource = viewModel.Employees;

var scrollbarVisibilityContainer = new ViewContainer<ListView>(Test.ListView.ScrollBarVisibility, new ListView());
InitializeElement(scrollbarVisibilityContainer.View);
scrollbarVisibilityContainer.View.HorizontalScrollBarVisibility = ScrollBarVisibility.Never;
Expand All @@ -287,6 +297,7 @@ protected override void Build(StackLayout stackLayout)
Add(rowHeightContainer);
Add(selectedItemContainer);
Add(fastScrollItemContainer);
Add(refreshControlColorContainer);
Add(scrollbarVisibilityContainer);
}
}
Expand Down
8 changes: 8 additions & 0 deletions Xamarin.Forms.Core/ListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class ListView : ItemsView<Cell>, IListViewController, IElementConfigurat

public static readonly BindableProperty SeparatorColorProperty = BindableProperty.Create("SeparatorColor", typeof(Color), typeof(ListView), Color.Default);

public static readonly BindableProperty RefreshControlColorProperty = BindableProperty.Create(nameof(RefreshControlColor), typeof(Color), typeof(ListView), Color.Default);

public static readonly BindableProperty HorizontalScrollBarVisibilityProperty = BindableProperty.Create(nameof(HorizontalScrollBarVisibility), typeof(ScrollBarVisibility), typeof(ListView), ScrollBarVisibility.Default);

public static readonly BindableProperty VerticalScrollBarVisibilityProperty = BindableProperty.Create(nameof(VerticalScrollBarVisibility), typeof(ScrollBarVisibility), typeof(ListView), ScrollBarVisibility.Default);
Expand Down Expand Up @@ -223,6 +225,12 @@ public Color SeparatorColor
set { SetValue(SeparatorColorProperty, value); }
}

public Color RefreshControlColor
{
get { return (Color)GetValue(RefreshControlColorProperty); }
set { SetValue(RefreshControlColorProperty, value); }
}

public SeparatorVisibility SeparatorVisibility
{
get { return (SeparatorVisibility)GetValue(SeparatorVisibilityProperty); }
Expand Down
1 change: 1 addition & 0 deletions Xamarin.Forms.CustomAttributes/TestAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ public enum ListView
GroupShortNameBinding,
ScrollTo,
FastScroll,
RefreshControlColor,
ScrollBarVisibility
}

Expand Down
9 changes: 9 additions & 0 deletions Xamarin.Forms.Platform.Android/Renderers/ListViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
UpdateIsSwipeToRefreshEnabled();
UpdateFastScrollEnabled();
UpdateSelectionMode();
UpdateSpinnerColor();
UpdateHorizontalScrollBarVisibility();
UpdateVerticalScrollBarVisibility();
}
Expand Down Expand Up @@ -217,6 +218,8 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
UpdateFastScrollEnabled();
else if (e.PropertyName == ListView.SelectionModeProperty.PropertyName)
UpdateSelectionMode();
else if (e.PropertyName == ListView.RefreshControlColorProperty.PropertyName)
UpdateSpinnerColor();
else if (e.PropertyName == ScrollView.HorizontalScrollBarVisibilityProperty.PropertyName)
UpdateHorizontalScrollBarVisibility();
else if (e.PropertyName == ScrollView.VerticalScrollBarVisibilityProperty.PropertyName)
Expand Down Expand Up @@ -419,6 +422,12 @@ void UpdateSelectionMode()
}
}

void UpdateSpinnerColor()
{
if (_refresh != null)
_refresh.SetColorSchemeColors(Element.RefreshControlColor.ToAndroid());
}

void UpdateHorizontalScrollBarVisibility()
{
if (_defaultHorizontalScrollVisibility == 0)
Expand Down
17 changes: 17 additions & 0 deletions Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
UpdateSeparatorColor();
UpdateSeparatorVisibility();
UpdateSelectionMode();
UpdateSpinnerColor();
UpdateVerticalScrollBarVisibility();
UpdateHorizontalScrollBarVisibility();

Expand Down Expand Up @@ -289,6 +290,8 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
UpdatePullToRefreshEnabled();
else if (e.PropertyName == Xamarin.Forms.ListView.SelectionModeProperty.PropertyName)
UpdateSelectionMode();
else if (e.PropertyName == Xamarin.Forms.ListView.RefreshControlColorProperty.PropertyName)
UpdateSpinnerColor();
else if (e.PropertyName == ScrollView.VerticalScrollBarVisibilityProperty.PropertyName)
UpdateVerticalScrollBarVisibility();
else if (e.PropertyName == ScrollView.HorizontalScrollBarVisibilityProperty.PropertyName)
Expand Down Expand Up @@ -682,6 +685,14 @@ void UpdateSelectionMode()
}
}

void UpdateSpinnerColor()
{
var color = Element.RefreshControlColor;

if (_tableViewController != null)
_tableViewController.UpdateRefreshControlColor(color == Color.Default ? null : color.ToUIColor());
}

void UpdateVerticalScrollBarVisibility()
{
if (_defaultVerticalScrollVisibility == null)
Expand Down Expand Up @@ -1463,6 +1474,12 @@ public override void ViewWillAppear(bool animated)
UpdateIsRefreshing(true);
}

public void UpdateRefreshControlColor(UIColor color)
{
if (RefreshControl != null)
RefreshControl.TintColor = color;
}

protected override void Dispose(bool disposing)
{
if (_disposed)
Expand Down
Loading

0 comments on commit 0d08fd8

Please sign in to comment.