summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/Renderers
diff options
context:
space:
mode:
authorRui Marinho <me@ruimarinho.net>2017-03-08 11:30:08 +0000
committerGitHub <noreply@github.com>2017-03-08 11:30:08 +0000
commit1ad18e33eb6b6ac02551d14d39f267968d044068 (patch)
tree5e63cca1a054ff2a3224cfeabf25eff1e4faaa5b /Xamarin.Forms.Platform.Android/Renderers
parent1b39d02dfa11ac53efb3a8f7668640e03a10194c (diff)
downloadxamarin-forms-1ad18e33eb6b6ac02551d14d39f267968d044068.tar.gz
xamarin-forms-1ad18e33eb6b6ac02551d14d39f267968d044068.tar.bz2
xamarin-forms-1ad18e33eb6b6ac02551d14d39f267968d044068.zip
[Android] Small performance fixes to ListViewRenderer, PlatformSpecific IsFastScrollEnabled (#797)
* [Android] Enable fast scroll by default * [Android] Cache count for Listview * [Android] Add IsFastScrollEnabled AndroidSpecific and sample * [Android] Use count cache on GetCellsFromPosition * [Android] Fix default for platform specific IsFastScrollEnabled * [Docs]Fix docs * [Android] Don't used cached listCount when getting cell
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Renderers')
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs35
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/ListViewRenderer.cs11
2 files changed, 35 insertions, 11 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs b/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs
index 1ff11f4a..5c23fd2e 100644
--- a/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs
+++ b/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs
@@ -26,6 +26,7 @@ namespace Xamarin.Forms.Platform.Android
readonly AListView _realListView;
readonly Dictionary<DataTemplate, int> _templateToId = new Dictionary<DataTemplate, int>();
int _dataTemplateIncrementer = 2; // lets start at not 0 because
+ int _listCount = -1; // -1 we need to get count from the list
Cell _enabledCheckCell;
bool _fromNative;
@@ -57,22 +58,27 @@ namespace Xamarin.Forms.Platform.Android
MessagingCenter.Subscribe<AppCompat.Platform>(this, AppCompat.Platform.CloseContextActionsSignalName, p => CloseContextActions());
else
MessagingCenter.Subscribe<Platform>(this, Platform.CloseContextActionsSignalName, p => CloseContextActions());
+ InvalidateCount();
}
public override int Count
{
get
{
- var templatedItems = TemplatedItemsView.TemplatedItems;
- int count = templatedItems.Count;
-
- if (_listView.IsGroupingEnabled)
+ if (_listCount == -1)
{
- for (var i = 0; i < templatedItems.Count; i++)
- count += templatedItems.GetGroup(i).Count;
- }
+ var templatedItems = TemplatedItemsView.TemplatedItems;
+ int count = templatedItems.Count;
- return count;
+ if (_listView.IsGroupingEnabled)
+ {
+ for (var i = 0; i < templatedItems.Count; i++)
+ count += templatedItems.GetGroup(i).Count;
+ }
+
+ _listCount = count;
+ }
+ return _listCount;
}
}
@@ -371,7 +377,7 @@ namespace Xamarin.Forms.Platform.Android
if (position < 0 || position >= Count)
return;
- if(_lastSelected != view)
+ if (_lastSelected != view)
_fromNative = true;
Select(position, view);
Controller.NotifyRowTapped(position, cell);
@@ -386,11 +392,12 @@ namespace Xamarin.Forms.Platform.Android
return cells;
var templatedItems = TemplatedItemsView.TemplatedItems;
+ var templatedItemsCount = templatedItems.Count;
if (!_listView.IsGroupingEnabled)
{
for (var x = 0; x < take; x++)
{
- if (position + x >= templatedItems.Count)
+ if (position + x >= templatedItemsCount)
return cells;
cells.Add(templatedItems[x + position]);
@@ -401,7 +408,7 @@ namespace Xamarin.Forms.Platform.Android
var i = 0;
var global = 0;
- for (; i < templatedItems.Count; i++)
+ for (; i < templatedItemsCount; i++)
{
var group = templatedItems.GetGroup(i);
@@ -446,6 +453,7 @@ namespace Xamarin.Forms.Platform.Android
void OnDataChanged()
{
+ InvalidateCount();
if (ActionModeContext != null && !TemplatedItemsView.TemplatedItems.Contains(ActionModeContext))
CloseContextActions();
@@ -586,5 +594,10 @@ namespace Xamarin.Forms.Platform.Android
Row,
Header
}
+
+ void InvalidateCount()
+ {
+ _listCount = -1;
+ }
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Android/Renderers/ListViewRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/ListViewRenderer.cs
index fa83b25b..a0906915 100644
--- a/Xamarin.Forms.Platform.Android/Renderers/ListViewRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/Renderers/ListViewRenderer.cs
@@ -6,6 +6,8 @@ using Android.Views;
using AListView = Android.Widget.ListView;
using AView = Android.Views.View;
using Xamarin.Forms.Internals;
+using System;
+using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
namespace Xamarin.Forms.Platform.Android
{
@@ -147,6 +149,7 @@ namespace Xamarin.Forms.Platform.Android
UpdateHeader();
UpdateFooter();
UpdateIsSwipeToRefreshEnabled();
+ UpdateFastScrollEnabled();
}
}
@@ -166,6 +169,8 @@ namespace Xamarin.Forms.Platform.Android
UpdateIsRefreshing();
else if (e.PropertyName == ListView.SeparatorColorProperty.PropertyName || e.PropertyName == ListView.SeparatorVisibilityProperty.PropertyName)
_adapter.NotifyDataSetChanged();
+ else if (e.PropertyName == PlatformConfiguration.AndroidSpecific.ListView.IsFastScrollEnabledProperty.PropertyName)
+ UpdateFastScrollEnabled();
}
protected override void OnLayout(bool changed, int l, int t, int r, int b)
@@ -328,6 +333,12 @@ namespace Xamarin.Forms.Platform.Android
_refresh.Enabled = Element.IsPullToRefreshEnabled && (Element as IListViewController).RefreshAllowed;
}
+ void UpdateFastScrollEnabled()
+ {
+ if (Control != null)
+ Control.FastScrollEnabled = Element.OnThisPlatform().IsFastScrollEnabled();
+ }
+
internal class Container : ViewGroup
{
IVisualElementRenderer _child;