Implemented colored refresh indicator for ListView pull-to-refresh (#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
This commit is contained in:
Gerald Versluis 2018-11-29 13:57:57 +01:00 коммит произвёл Rui Marinho
Родитель 43eb6b37db
Коммит 0d08fd8254
6 изменённых файлов: 1217 добавлений и 1 удалений

Просмотреть файл

@ -4,8 +4,8 @@ using System.Collections.ObjectModel;
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;
@ -267,6 +267,16 @@ namespace Xamarin.Forms.Controls
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;
@ -287,6 +297,7 @@ namespace Xamarin.Forms.Controls
Add(rowHeightContainer);
Add(selectedItemContainer);
Add(fastScrollItemContainer);
Add(refreshControlColorContainer);
Add(scrollbarVisibilityContainer);
}
}

Просмотреть файл

@ -46,6 +46,8 @@ namespace Xamarin.Forms
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);
@ -223,6 +225,12 @@ namespace Xamarin.Forms
set { SetValue(SeparatorColorProperty, value); }
}
public Color RefreshControlColor
{
get { return (Color)GetValue(RefreshControlColorProperty); }
set { SetValue(RefreshControlColorProperty, value); }
}
public SeparatorVisibility SeparatorVisibility
{
get { return (SeparatorVisibility)GetValue(SeparatorVisibilityProperty); }

Просмотреть файл

@ -431,6 +431,7 @@ namespace Xamarin.Forms.CustomAttributes
GroupShortNameBinding,
ScrollTo,
FastScroll,
RefreshControlColor,
ScrollBarVisibility
}

Просмотреть файл

@ -178,6 +178,7 @@ namespace Xamarin.Forms.Platform.Android
UpdateIsSwipeToRefreshEnabled();
UpdateFastScrollEnabled();
UpdateSelectionMode();
UpdateSpinnerColor();
UpdateHorizontalScrollBarVisibility();
UpdateVerticalScrollBarVisibility();
}
@ -217,6 +218,8 @@ namespace Xamarin.Forms.Platform.Android
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)
@ -419,6 +422,12 @@ namespace Xamarin.Forms.Platform.Android
}
}
void UpdateSpinnerColor()
{
if (_refresh != null)
_refresh.SetColorSchemeColors(Element.RefreshControlColor.ToAndroid());
}
void UpdateHorizontalScrollBarVisibility()
{
if (_defaultHorizontalScrollVisibility == 0)

Просмотреть файл

@ -249,6 +249,7 @@ namespace Xamarin.Forms.Platform.iOS
UpdateSeparatorColor();
UpdateSeparatorVisibility();
UpdateSelectionMode();
UpdateSpinnerColor();
UpdateVerticalScrollBarVisibility();
UpdateHorizontalScrollBarVisibility();
@ -289,6 +290,8 @@ namespace Xamarin.Forms.Platform.iOS
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)
@ -682,6 +685,14 @@ namespace Xamarin.Forms.Platform.iOS
}
}
void UpdateSpinnerColor()
{
var color = Element.RefreshControlColor;
if (_tableViewController != null)
_tableViewController.UpdateRefreshControlColor(color == Color.Default ? null : color.ToUIColor());
}
void UpdateVerticalScrollBarVisibility()
{
if (_defaultVerticalScrollVisibility == null)
@ -1463,6 +1474,12 @@ namespace Xamarin.Forms.Platform.iOS
UpdateIsRefreshing(true);
}
public void UpdateRefreshControlColor(UIColor color)
{
if (RefreshControl != null)
RefreshControl.TintColor = color;
}
protected override void Dispose(bool disposing)
{
if (_disposed)

Разница между файлами не показана из-за своего большого размера Загрузить разницу