Ejemplo n.º 1
0
        void ScrollUpdate()
        {
            var oldTopHiddenItems = topHiddenItems;

            topHiddenItems    = GetFirstVisibleIndex();
            bottomHiddenItems = Mathf.Max(0, DataSource.Count - visibleItems - topHiddenItems);

            if (oldTopHiddenItems == topHiddenItems)
            {
                //do nothing
            }
            // optimization on +-1 item scroll
            else if (oldTopHiddenItems == (topHiddenItems + 1))
            {
                var bottomComponent = ComponentTopToBottom();

                bottomComponent.Index     = topHiddenItems;
                bottomComponent.Text.text = DataSource[topHiddenItems];
                Coloring(bottomComponent);
            }
            else if (oldTopHiddenItems == (topHiddenItems - 1))
            {
                var topComponent = ComponentBottomToTop();

                var new_index = topHiddenItems + visibleItems - 1;
                topComponent.Index     = new_index;
                topComponent.Text.text = DataSource[new_index];
                Coloring(topComponent);
            }
            // all other cases
            else
            {
                //!
                var new_indicies = Enumerable.Range(topHiddenItems, visibleItems).ToArray();
                components.ForEach((x, i) => {
                    x.Index     = new_indicies[i];
                    x.Text.text = DataSource[new_indicies[i]];
                    Coloring(x);
                });
            }

            if (LayoutBridge != null)
            {
                LayoutBridge.SetFiller(CalculateTopFillerSize(), CalculateBottomFillerSize());
                LayoutBridge.UpdateLayout();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// On ScrollUpdate.
        /// </summary>
        protected virtual void ScrollUpdate()
        {
            var oldTopHiddenItems = topHiddenItems;

            topHiddenItems    = GetFirstVisibleIndex();
            bottomHiddenItems = Mathf.Max(0, DataSource.Count - visibleItems - topHiddenItems);

            if (oldTopHiddenItems == topHiddenItems)
            {
                //do nothing
            }
            // optimization on +-1 item scroll
            else if (oldTopHiddenItems == (topHiddenItems + 1))
            {
                var bottomComponent = components[components.Count - 1];
                components.RemoveAt(components.Count - 1);
                components.Insert(0, bottomComponent);
                bottomComponent.transform.SetAsFirstSibling();

                bottomComponent.Index = topHiddenItems;
                SetData(bottomComponent, DataSource[topHiddenItems]);
                Coloring(bottomComponent as ListViewItem);
            }
            else if (oldTopHiddenItems == (topHiddenItems - 1))
            {
                var topComponent = components[0];
                components.RemoveAt(0);
                components.Add(topComponent);
                topComponent.transform.SetAsLastSibling();

                topComponent.Index = topHiddenItems + visibleItems - 1;
                SetData(topComponent, DataSource[topHiddenItems + visibleItems - 1]);
                Coloring(topComponent as ListViewItem);
            }
            // all other cases
            else
            {
                var current_visible_range = components.Convert <TComponent, int>(GetComponentIndex);
                var new_visible_range     = Enumerable.Range(topHiddenItems, visibleItems).ToArray();

                var new_indicies_to_change = new_visible_range.Except(current_visible_range).ToList();
                var components_to_change   = new Stack <TComponent>(components.Where(x => !new_visible_range.Contains(x.Index)));

                new_indicies_to_change.ForEach(index => {
                    var component = components_to_change.Pop();

                    component.Index = index;
                    SetData(component, DataSource[index]);
                    Coloring(component as ListViewItem);
                });

                components.Sort(ComponentsComparer);
                components.ForEach(SetComponentAsLastSibling);
            }

            if (LayoutBridge != null)
            {
                LayoutBridge.SetFiller(CalculateTopFillerSize(), CalculateBottomFillerSize());
                LayoutBridge.UpdateLayout();
            }
        }