Ejemplo n.º 1
0
        public void Refresh()
        {
            m_Pool.Clear();
            m_ScrollView.Clear();
            m_VisibleItemCount = 0;

            if (!HasValidDataAndBindings())
            {
                return;
            }

            m_LastHeight = m_ScrollView.layout.height;

            if (float.IsNaN(m_LastHeight))
            {
                return;
            }

            ResizeHeight(m_LastHeight);
        }
Ejemplo n.º 2
0
        public void Refresh()
        {
            m_Pool.Clear();
            m_ScrollView.Clear();

            m_ScrollView.contentContainer.style.width = m_ScrollView.contentViewport.layout.width;
            m_ScrollView.contentContainer.style.flex  = 0;

            if (!HasValidDataAndBindings())
            {
                return;
            }

            // Resize ScrollView in case the collection has changed.
            m_ScrollView.contentContainer.style.height = itemsSource.Count * itemHeight;

            // Restore scroll offset and pre-emptively update the highValue
            // in case this is the initial restore from persistent data and
            // the ScrollView's OnGeometryChanged() didn't update the low
            // and highValues.
            m_ScrollView.verticalScroller.highValue = Mathf.Max(m_ScrollOffset, m_ScrollView.verticalScroller.highValue);
            m_ScrollView.verticalScroller.value     = m_ScrollOffset;

            if (m_LastSize != m_ScrollView.layout)
            {
                m_LastSize = m_ScrollView.layout;
            }

            if (float.IsNaN(m_LastSize.height))
            {
                return;
            }

            m_ScrollView.contentContainer.style.height = itemsSource.Count * itemHeight;

            m_VisibleItemCount = (int)(m_LastSize.height / itemHeight) + m_ExtraVisibleItems;
            for (var i = m_FirstVisibleIndex; i < m_VisibleItemCount + m_FirstVisibleIndex; i++)
            {
                var item         = makeItem();
                var recycledItem = new RecycledItem(item);
                m_Pool.Add(recycledItem);

                item.style.marginTop     = 0;
                item.style.marginBottom  = 0;
                item.style.positionType  = PositionType.Absolute;
                item.style.positionLeft  = 0;
                item.style.positionRight = 0;
                item.style.height        = itemHeight;
                if (i < itemsSource.Count)
                {
                    item.style.visibility = Visibility.Visible;
                    Setup(recycledItem, i);
                }
                else
                {
                    item.style.visibility = Visibility.Hidden;
                }

                m_ScrollView.Add(item);
            }

            schedule.Execute(() => { Dirty(ChangeType.Layout); });
        }