1 /* Copyright (c) 2021 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
18 using System.Collections;
19 using System.Collections.Generic;
20 using System.Windows.Input;
21 using System.ComponentModel;
22 using Tizen.NUI.BaseComponents;
23 using Tizen.NUI.Binding;
25 namespace Tizen.NUI.Components
28 /// This class provides a View that can layouting items in list and grid with high performance.
30 [EditorBrowsable(EditorBrowsableState.Never)]
31 public class CollectionView : RecyclerView
34 /// Binding Property of selected item in single selection.
36 [EditorBrowsable(EditorBrowsableState.Never)]
37 public static readonly BindableProperty SelectedItemProperty =
38 BindableProperty.Create(nameof(SelectedItem), typeof(object), typeof(CollectionView), null,
39 propertyChanged: (bindable, oldValue, newValue) =>
41 var colView = (CollectionView)bindable;
42 oldValue = colView.selectedItem;
43 colView.selectedItem = newValue;
44 var args = new SelectionChangedEventArgs(oldValue, newValue);
46 foreach (RecyclerViewItem item in colView.ContentContainer.Children.Where((item) => item is RecyclerViewItem))
48 if (item.BindingContext == null) continue;
49 if (item.BindingContext == oldValue) item.IsSelected = false;
50 else if (item.BindingContext == newValue) item.IsSelected = true;
53 SelectionPropertyChanged(colView, args);
55 defaultValueCreator: (bindable) =>
57 var colView = (CollectionView)bindable;
58 return colView.selectedItem;
62 /// Binding Property of selected items list in multiple selection.
64 [EditorBrowsable(EditorBrowsableState.Never)]
65 public static readonly BindableProperty SelectedItemsProperty =
66 BindableProperty.Create(nameof(SelectedItems), typeof(IList<object>), typeof(CollectionView), null,
67 propertyChanged: (bindable, oldValue, newValue) =>
69 var colView = (CollectionView)bindable;
70 var oldSelection = colView.selectedItems ?? selectEmpty;
71 //FIXME : CoerceSelectedItems calls only isCreatedByXaml
72 var newSelection = (SelectionList)CoerceSelectedItems(colView, newValue);
73 colView.selectedItems = newSelection;
74 colView.SelectedItemsPropertyChanged(oldSelection, newSelection);
76 defaultValueCreator: (bindable) =>
78 var colView = (CollectionView)bindable;
79 colView.selectedItems = colView.selectedItems ?? new SelectionList(colView);
80 return colView.selectedItems;
84 /// Binding Property of selected items list in multiple selection.
86 [EditorBrowsable(EditorBrowsableState.Never)]
87 public static readonly BindableProperty SelectionModeProperty =
88 BindableProperty.Create(nameof(SelectionMode), typeof(ItemSelectionMode), typeof(CollectionView), ItemSelectionMode.None,
89 propertyChanged: (bindable, oldValue, newValue) =>
91 var colView = (CollectionView)bindable;
92 oldValue = colView.selectionMode;
93 colView.selectionMode = (ItemSelectionMode)newValue;
94 SelectionModePropertyChanged(colView, oldValue, newValue);
96 defaultValueCreator: (bindable) =>
98 var colView = (CollectionView)bindable;
99 return colView.selectionMode;
103 private static readonly IList<object> selectEmpty = new List<object>(0);
104 private DataTemplate itemTemplate = null;
105 private IEnumerable itemsSource = null;
106 private ItemsLayouter itemsLayouter = null;
107 private DataTemplate groupHeaderTemplate;
108 private DataTemplate groupFooterTemplate;
109 private bool isGrouped;
110 private bool wasRelayouted = false;
111 private bool needInitalizeLayouter = false;
112 private object selectedItem;
113 private SelectionList selectedItems;
114 private bool suppressSelectionChangeNotification;
115 private ItemSelectionMode selectionMode = ItemSelectionMode.None;
116 private RecyclerViewItem header;
117 private RecyclerViewItem footer;
118 private View focusedView;
119 private int prevFocusedDataIndex = 0;
120 private List<RecyclerViewItem> recycleGroupHeaderCache { get; } = new List<RecyclerViewItem>();
121 private List<RecyclerViewItem> recycleGroupFooterCache { get; } = new List<RecyclerViewItem>();
124 /// Base constructor.
126 [EditorBrowsable(EditorBrowsableState.Never)]
127 public CollectionView() : base()
130 SetKeyboardNavigationSupport(true);
134 /// Base constructor with ItemsSource
136 /// <param name="itemsSource">item's data source</param>
137 [EditorBrowsable(EditorBrowsableState.Never)]
138 public CollectionView(IEnumerable itemsSource) : this()
140 ItemsSource = itemsSource;
144 /// Base constructor with ItemsSource, ItemsLayouter and ItemTemplate
146 /// <param name="itemsSource">item's data source</param>
147 /// <param name="layouter">item's layout manager</param>
148 /// <param name="template">item's view template with data bindings</param>
149 [EditorBrowsable(EditorBrowsableState.Never)]
150 public CollectionView(IEnumerable itemsSource, ItemsLayouter layouter, DataTemplate template) : this()
152 ItemsSource = itemsSource;
153 ItemTemplate = template;
154 ItemsLayouter = layouter;
158 /// Event of Selection changed.
159 /// old selection list and new selection will be provided.
161 [EditorBrowsable(EditorBrowsableState.Never)]
162 public event EventHandler<SelectionChangedEventArgs> SelectionChanged;
165 /// Align item in the viewport when ScrollTo() calls.
167 [EditorBrowsable(EditorBrowsableState.Never)]
168 public enum ItemScrollTo
171 /// Scroll to show item in nearest viewport on scroll direction.
172 /// item is above the scroll viewport, item will be came into front,
173 /// item is under the scroll viewport, item will be came into end,
174 /// item is in the scroll viewport, no scroll.
178 /// Scroll to show item in start of the viewport.
182 /// Scroll to show item in center of the viewport.
186 /// Scroll to show item in end of the viewport.
192 /// Item's source data.
194 [EditorBrowsable(EditorBrowsableState.Never)]
195 public override IEnumerable ItemsSource
207 if (InternalItemSource != null) InternalItemSource.Dispose();
211 if (InternalItemSource != null) InternalItemSource.Dispose();
212 InternalItemSource = ItemsSourceFactory.Create(this);
214 if (itemsLayouter == null) return;
216 needInitalizeLayouter = true;
222 /// DataTemplate for items.
224 [EditorBrowsable(EditorBrowsableState.Never)]
225 public override DataTemplate ItemTemplate
233 itemTemplate = value;
240 needInitalizeLayouter = true;
248 [EditorBrowsable(EditorBrowsableState.Never)]
249 public virtual ItemsLayouter ItemsLayouter
253 return itemsLayouter;
257 itemsLayouter = value;
258 base.InternalItemsLayouter = ItemsLayouter;
261 needInitalizeLayouter = false;
265 needInitalizeLayouter = true;
271 /// Scrolling direction to display items layout.
273 [EditorBrowsable(EditorBrowsableState.Never)]
274 public new Direction ScrollingDirection
278 return base.ScrollingDirection;
282 base.ScrollingDirection = value;
284 if (ScrollingDirection == Direction.Horizontal)
286 ContentContainer.SizeWidth = ItemsLayouter.CalculateLayoutOrientationSize();
290 ContentContainer.SizeHeight = ItemsLayouter.CalculateLayoutOrientationSize();
296 /// Selected item in single selection.
298 [EditorBrowsable(EditorBrowsableState.Never)]
299 public object SelectedItem
301 get => GetValue(SelectedItemProperty);
302 set => SetValue(SelectedItemProperty, value);
306 /// Selected items list in multiple selection.
308 [EditorBrowsable(EditorBrowsableState.Never)]
309 public IList<object> SelectedItems
311 get => (IList<object>)GetValue(SelectedItemsProperty);
312 // set => SetValue(SelectedItemsProperty, new SelectionList(this, value));
316 /// Selection mode to handle items selection. See ItemSelectionMode for details.
318 [EditorBrowsable(EditorBrowsableState.Never)]
319 public ItemSelectionMode SelectionMode
321 get => (ItemSelectionMode)GetValue(SelectionModeProperty);
322 set => SetValue(SelectionModeProperty, value);
326 /// Command of selection changed.
328 [EditorBrowsable(EditorBrowsableState.Never)]
329 public ICommand SelectionChangedCommand { set; get; }
332 /// Command parameter of selection changed.
334 [EditorBrowsable(EditorBrowsableState.Never)]
335 public object SelectionChangedCommandParameter { set; get; }
338 /// Size strategy of measuring scroll content. see details in ItemSizingStrategy.
340 [EditorBrowsable(EditorBrowsableState.Never)]
341 public ItemSizingStrategy SizingStrategy { get; set; }
344 /// Header item which placed in top-most position.
345 /// note : internal index and count will be increased.
347 [EditorBrowsable(EditorBrowsableState.Never)]
348 public RecyclerViewItem Header
355 //ContentContainer.Remove(header);
356 Utility.Dispose(header);
361 value.ParentItemsView = this;
362 value.IsHeader = true;
363 ContentContainer.Add(value);
366 needInitalizeLayouter = true;
372 /// Footer item which placed in bottom-most position.
373 /// note : internal count will be increased.
375 [EditorBrowsable(EditorBrowsableState.Never)]
376 public RecyclerViewItem Footer
383 //ContentContainer.Remove(footer);
384 Utility.Dispose(footer);
388 value.Index = InternalItemSource?.Count ?? 0;
389 value.ParentItemsView = this;
390 value.IsFooter = true;
391 ContentContainer.Add(value);
394 needInitalizeLayouter = true;
400 /// Boolean flag of group feature existence.
402 [EditorBrowsable(EditorBrowsableState.Never)]
403 public bool IsGrouped
409 needInitalizeLayouter = true;
410 //Need to re-intialize Internal Item Source.
411 if (InternalItemSource != null)
413 InternalItemSource.Dispose();
414 InternalItemSource = null;
416 if (ItemsSource != null)
417 InternalItemSource = ItemsSourceFactory.Create(this);
423 /// DataTemplate of group header. Group feature is not supported yet.
425 [EditorBrowsable(EditorBrowsableState.Never)]
426 public DataTemplate GroupHeaderTemplate
430 return groupHeaderTemplate;
434 groupHeaderTemplate = value;
435 needInitalizeLayouter = true;
441 /// DataTemplate of group footer. Group feature is not supported yet.
443 [EditorBrowsable(EditorBrowsableState.Never)]
444 public DataTemplate GroupFooterTemplate
448 return groupFooterTemplate;
452 groupFooterTemplate = value;
453 needInitalizeLayouter = true;
460 /// Internal encapsulated items data source.
462 internal new IGroupableItemSource InternalItemSource
466 return (base.InternalItemSource as IGroupableItemSource);
470 base.InternalItemSource = value;
474 [EditorBrowsable(EditorBrowsableState.Never)]
475 public override void OnRelayout(Vector2 size, RelayoutContainer container)
477 base.OnRelayout(size, container);
479 wasRelayouted = true;
480 if (needInitalizeLayouter) Init();
484 [EditorBrowsable(EditorBrowsableState.Never)]
485 public override View GetNextFocusableView(View currentFocusedView, View.FocusDirection direction, bool loopEnabled)
487 View nextFocusedView = null;
489 if (focusedView == null)
491 // If focusedView is null, find child which has previous data index
492 if (ContentContainer.Children.Count > 0 && InternalItemSource.Count > 0)
494 for (int i = 0; i < ContentContainer.Children.Count; i++)
496 RecyclerViewItem item = Children[i] as RecyclerViewItem;
497 if (item?.Index == prevFocusedDataIndex)
499 nextFocusedView = item;
507 // If this is not first focus, request next focus to Layouter
508 nextFocusedView = ItemsLayouter.RequestNextFocusableView(currentFocusedView, direction, loopEnabled);
511 if (nextFocusedView != null)
513 // Check next focused view is inside of visible area.
514 // If it is not, move scroll position to make it visible.
515 Position scrollPosition = ContentContainer.CurrentPosition;
516 float targetPosition = -(ScrollingDirection == Direction.Horizontal ? scrollPosition.X : scrollPosition.Y);
518 float left = nextFocusedView.Position.X;
519 float right = nextFocusedView.Position.X + nextFocusedView.Size.Width;
520 float top = nextFocusedView.Position.Y;
521 float bottom = nextFocusedView.Position.Y + nextFocusedView.Size.Height;
523 float visibleRectangleLeft = -scrollPosition.X;
524 float visibleRectangleRight = -scrollPosition.X + Size.Width;
525 float visibleRectangleTop = -scrollPosition.Y;
526 float visibleRectangleBottom = -scrollPosition.Y + Size.Height;
528 if (ScrollingDirection == Direction.Horizontal)
530 if ((direction == View.FocusDirection.Left || direction == View.FocusDirection.Up) && left < visibleRectangleLeft)
532 targetPosition = left;
534 else if ((direction == View.FocusDirection.Right || direction == View.FocusDirection.Down) && right > visibleRectangleRight)
536 targetPosition = right - Size.Width;
541 if ((direction == View.FocusDirection.Up || direction == View.FocusDirection.Left) && top < visibleRectangleTop)
543 targetPosition = top;
545 else if ((direction == View.FocusDirection.Down || direction == View.FocusDirection.Right) && bottom > visibleRectangleBottom)
547 targetPosition = bottom - Size.Height;
551 focusedView = nextFocusedView;
552 prevFocusedDataIndex = (nextFocusedView as RecyclerViewItem)?.Index ?? -1;
554 ScrollTo(targetPosition, true);
558 // If nextView is null, it means that we should move focus to outside of Control.
559 // Return FocusableView depending on direction.
562 case View.FocusDirection.Left:
564 nextFocusedView = LeftFocusableView;
567 case View.FocusDirection.Right:
569 nextFocusedView = RightFocusableView;
572 case View.FocusDirection.Up:
574 nextFocusedView = UpFocusableView;
577 case View.FocusDirection.Down:
579 nextFocusedView = DownFocusableView;
584 if (nextFocusedView != null)
590 //If FocusableView doesn't exist, not move focus.
591 nextFocusedView = focusedView;
595 return nextFocusedView;
599 /// Update selected items list in multiple selection.
601 /// <param name="newSelection">updated selection list by user</param>
602 [EditorBrowsable(EditorBrowsableState.Never)]
603 public void UpdateSelectedItems(IList<object> newSelection)
605 var oldSelection = new List<object>(SelectedItems);
607 suppressSelectionChangeNotification = true;
609 SelectedItems.Clear();
611 if (newSelection?.Count > 0)
613 for (int n = 0; n < newSelection.Count; n++)
615 SelectedItems.Add(newSelection[n]);
619 suppressSelectionChangeNotification = false;
621 SelectedItemsPropertyChanged(oldSelection, newSelection);
625 /// Scroll to specific position with or without animation.
627 /// <param name="position">Destination.</param>
628 /// <param name="animate">Scroll with or without animation</param>
629 [EditorBrowsable(EditorBrowsableState.Never)]
630 public new void ScrollTo(float position, bool animate) => base.ScrollTo(position, animate);
633 /// Scroll to specific item's aligned position with or without animation.
635 /// <param name="item">Target item of dataset.</param>
636 /// <param name="animate">Boolean flag of animation.</param>
637 /// <param name="align">Align state of item. see details in ItemScrollTo.</param>
638 [EditorBrowsable(EditorBrowsableState.Never)]
639 public virtual void ScrollTo(object item, bool animate = false, ItemScrollTo align = ItemScrollTo.Nearest)
641 if (item == null) throw new ArgumentNullException(nameof(item));
642 if (ItemsLayouter == null) throw new Exception("Item Layouter must exist.");
644 if (InternalItemSource.GetPosition(item) == -1)
646 throw new Exception("ScrollTo parameter item is not a member of ItemsSource");
649 float scrollPos, curPos, curSize, curItemSize;
650 (float x, float y) = ItemsLayouter.GetItemPosition(item);
651 (float width, float height) = ItemsLayouter.GetItemSize(item);
652 if (ScrollingDirection == Direction.Horizontal)
655 curPos = ScrollPosition.X;
656 curSize = Size.Width;
662 curPos = ScrollPosition.Y;
663 curSize = Size.Height;
664 curItemSize = height;
667 //Console.WriteLine("[NUI] ScrollTo [{0}:{1}], curPos{2}, itemPos{3}, curSize{4}, itemSize{5}", InternalItemSource.GetPosition(item), align, curPos, scrollPos, curSize, curItemSize);
670 case ItemScrollTo.Start:
673 case ItemScrollTo.Center:
674 scrollPos = scrollPos - (curSize / 2) + (curItemSize / 2);
676 case ItemScrollTo.End:
677 scrollPos = scrollPos - curSize + curItemSize;
679 case ItemScrollTo.Nearest:
680 if (scrollPos < curPos - curItemSize)
682 // item is placed before the current screen. scrollTo.Top
684 else if (scrollPos >= curPos + curSize + curItemSize)
686 // item is placed after the current screen. scrollTo.End
687 scrollPos = scrollPos - curSize + curItemSize;
691 // item is in the scroller. ScrollTo() is ignored.
697 //Console.WriteLine("[NUI] ScrollTo [{0}]-------------------", scrollPos);
698 base.ScrollTo(scrollPos, animate);
701 // Realize and Decorate the item.
702 internal override RecyclerViewItem RealizeItem(int index)
704 if (index == 0 && Header != null)
710 if (index == InternalItemSource.Count - 1 && Footer != null)
718 var context = InternalItemSource.GetItem(index);
719 if (InternalItemSource.IsGroupHeader(index))
721 DataTemplate templ = (groupHeaderTemplate as DataTemplateSelector)?.SelectDataTemplate(context, this) ?? groupHeaderTemplate;
723 RecyclerViewItem groupHeader = PopRecycleGroupCache(templ, true);
724 if (groupHeader == null)
726 groupHeader = (RecyclerViewItem)DataTemplateExtensions.CreateContent(groupHeaderTemplate, context, this);
728 groupHeader.ParentItemsView = this;
729 groupHeader.Template = templ;
730 groupHeader.isGroupHeader = true;
731 groupHeader.isGroupFooter = false;
732 ContentContainer.Add(groupHeader);
734 groupHeader.Index = index;
735 groupHeader.ParentGroup = context;
736 groupHeader.BindingContext = context;
740 else if (InternalItemSource.IsGroupFooter(index))
742 DataTemplate templ = (groupFooterTemplate as DataTemplateSelector)?.SelectDataTemplate(context, this) ?? groupFooterTemplate;
744 RecyclerViewItem groupFooter = PopRecycleGroupCache(templ, false);
745 if (groupFooter == null)
747 groupFooter = (RecyclerViewItem)DataTemplateExtensions.CreateContent(groupFooterTemplate, context, this);
749 groupFooter.ParentItemsView = this;
750 groupFooter.Template = templ;
751 groupFooter.isGroupHeader = false;
752 groupFooter.isGroupFooter = true;
753 ContentContainer.Add(groupFooter);
755 groupFooter.Index = index;
756 groupFooter.ParentGroup = context;
757 groupFooter.BindingContext = context;
764 RecyclerViewItem item = base.RealizeItem(index);
769 item.ParentGroup = InternalItemSource.GetGroupParent(index);
772 switch (SelectionMode)
774 case ItemSelectionMode.SingleSelection:
775 if (item.BindingContext != null && item.BindingContext == SelectedItem)
777 item.IsSelected = true;
781 case ItemSelectionMode.MultipleSelections:
782 if ((item.BindingContext != null) && (SelectedItems?.Contains(item.BindingContext) ?? false))
784 item.IsSelected = true;
787 case ItemSelectionMode.None:
788 item.IsSelectable = false;
795 // Unrealize and caching the item.
796 internal override void UnrealizeItem(RecyclerViewItem item, bool recycle = true)
808 if (item.isGroupHeader || item.isGroupFooter)
810 if (!recycle || !PushRecycleGroupCache(item))
811 Utility.Dispose(item);
815 item.IsSelected = false;
816 base.UnrealizeItem(item, recycle);
819 internal void SelectedItemsPropertyChanged(IList<object> oldSelection, IList<object> newSelection)
821 if (suppressSelectionChangeNotification)
826 foreach (RecyclerViewItem item in ContentContainer.Children.Where((item) => item is RecyclerViewItem))
828 if (item.BindingContext == null) continue;
829 if (newSelection.Contains(item.BindingContext))
831 if (!item.IsSelected) item.IsSelected = true;
835 if (item.IsSelected) item.IsSelected = false;
838 SelectionPropertyChanged(this, new SelectionChangedEventArgs(oldSelection, newSelection));
840 OnPropertyChanged(SelectedItemsProperty.PropertyName);
844 /// Internal selection callback.
846 [EditorBrowsable(EditorBrowsableState.Never)]
847 protected virtual void OnSelectionChanged(SelectionChangedEventArgs args)
853 /// Adjust scrolling position by own scrolling rules.
854 /// Override this function when developer wants to change destination of flicking.(e.g. always snap to center of item)
856 /// <param name="position">Scroll position which is calculated by ScrollableBase</param>
857 /// <returns>Adjusted scroll destination</returns>
858 [EditorBrowsable(EditorBrowsableState.Never)]
859 protected override float AdjustTargetPositionOfScrollAnimation(float position)
861 // Destination is depending on implementation of layout manager.
862 // Get destination from layout manager.
863 return ItemsLayouter.CalculateCandidateScrollPosition(position);
867 /// OnScroll event callback.
869 /// <param name="source">Scroll source object</param>
870 /// <param name="args">Scroll event argument</param>
871 [EditorBrowsable(EditorBrowsableState.Never)]
872 protected override void OnScrolling(object source, ScrollEventArgs args)
874 if (disposed) return;
876 if (needInitalizeLayouter)
878 ItemsLayouter.Initialize(this);
879 needInitalizeLayouter = false;
881 base.OnScrolling(source, args);
885 /// Dispose ItemsView and all children on it.
887 /// <param name="type">Dispose type.</param>
888 protected override void Dispose(DisposeTypes type)
895 if (type == DisposeTypes.Explicit)
898 if (InternalItemSource != null)
900 InternalItemSource.Dispose();
901 InternalItemSource = null;
905 Utility.Dispose(Header);
910 Utility.Dispose(Footer);
913 groupHeaderTemplate = null;
914 groupFooterTemplate = null;
921 private static void SelectionPropertyChanged(CollectionView colView, SelectionChangedEventArgs args)
923 var command = colView.SelectionChangedCommand;
927 var commandParameter = colView.SelectionChangedCommandParameter;
929 if (command.CanExecute(commandParameter))
931 command.Execute(commandParameter);
934 colView.SelectionChanged?.Invoke(colView, args);
935 colView.OnSelectionChanged(args);
938 private static object CoerceSelectedItems(BindableObject bindable, object value)
942 return new SelectionList((CollectionView)bindable);
945 if (value is SelectionList)
950 return new SelectionList((CollectionView)bindable, value as IList<object>);
953 private static void SelectionModePropertyChanged(BindableObject bindable, object oldValue, object newValue)
955 var colView = (CollectionView)bindable;
957 var oldMode = (ItemSelectionMode)oldValue;
958 var newMode = (ItemSelectionMode)newValue;
960 IList<object> previousSelection = new List<object>();
961 IList<object> newSelection = new List<object>();
965 case ItemSelectionMode.None:
967 case ItemSelectionMode.SingleSelection:
968 if (colView.SelectedItem != null)
970 previousSelection.Add(colView.SelectedItem);
973 case ItemSelectionMode.MultipleSelections:
974 previousSelection = colView.SelectedItems;
980 case ItemSelectionMode.None:
982 case ItemSelectionMode.SingleSelection:
983 if (colView.SelectedItem != null)
985 newSelection.Add(colView.SelectedItem);
988 case ItemSelectionMode.MultipleSelections:
989 newSelection = colView.SelectedItems;
993 if (previousSelection.Count == newSelection.Count)
995 if (previousSelection.Count == 0 || (previousSelection[0] == newSelection[0]))
997 // Both selections are empty or have the same single item; no reason to signal a change
1002 var args = new SelectionChangedEventArgs(previousSelection, newSelection);
1003 SelectionPropertyChanged(colView, args);
1008 if (ItemsSource == null) return;
1009 if (ItemsLayouter == null) return;
1010 if (ItemTemplate == null) return;
1012 if (disposed) return;
1013 if (needInitalizeLayouter)
1015 if (InternalItemSource == null) return;
1017 InternalItemSource.HasHeader = (header != null);
1018 InternalItemSource.HasFooter = (footer != null);
1021 if (!wasRelayouted) return;
1023 if (needInitalizeLayouter)
1025 ItemsLayouter.Initialize(this);
1026 needInitalizeLayouter = false;
1028 ItemsLayouter.RequestLayout(0.0f, true);
1030 if (ScrollingDirection == Direction.Horizontal)
1032 ContentContainer.SizeWidth = ItemsLayouter.CalculateLayoutOrientationSize();
1036 ContentContainer.SizeHeight = ItemsLayouter.CalculateLayoutOrientationSize();
1040 private bool PushRecycleGroupCache(RecyclerViewItem item)
1042 if (item == null) throw new ArgumentNullException(nameof(item));
1043 if (RecycleCache.Count >= 20) return false;
1044 if (item.Template == null) return false;
1045 if (item.isGroupHeader)
1047 recycleGroupHeaderCache.Add(item);
1049 else if (item.isGroupFooter)
1051 recycleGroupFooterCache.Add(item);
1059 private RecyclerViewItem PopRecycleGroupCache(DataTemplate Template, bool isHeader)
1061 RecyclerViewItem viewItem = null;
1063 var Cache = (isHeader ? recycleGroupHeaderCache : recycleGroupFooterCache);
1064 for (int i = 0; i < Cache.Count; i++)
1066 viewItem = Cache[i];
1067 if (Template == viewItem.Template) break;
1070 if (viewItem != null)
1072 Cache.Remove(viewItem);