示例#1
0
        private void InitializeTween(int dataIndex, int cellViewIndex)
        {
            _data[dataIndex].isExpanded = !_data[dataIndex].isExpanded;

            for (var i = 0; i < _data.Count; i++)
            {
                if (i != dataIndex)
                {
                    if (((dataIndex + 2) % 3 == 0) || ((i + 2) % 3 == 0))
                    {
                        _data[i].isExpanded = false;
                    }
                }
            }

            var cellPosition = scroller.GetScrollPositionForCellViewIndex(cellViewIndex, EnhancedScroller.CellViewPositionEnum.Before);

            var tweenCellOffset = cellPosition - scroller.ScrollPosition;

            scroller.IgnoreLoopJump(true);

            scroller.ReloadData();

            cellPosition = scroller.GetScrollPositionForCellViewIndex(cellViewIndex, EnhancedScroller.CellViewPositionEnum.Before);

            scroller.SetScrollPositionImmediately(cellPosition - tweenCellOffset);

            scroller.IgnoreLoopJump(false);

            if (_data[dataIndex].tweenType == Tween.TweenType.immediate)
            {
                return;
            }

            _lastPadderActive = scroller.LastPadder.IsActive();
            _lastPadderSize   = scroller.LastPadder.minHeight;

            if (_data[dataIndex].isExpanded)
            {
                scroller.LastPadder.minHeight += _data[dataIndex].SizeDifference;
            }
            else
            {
                scroller.LastPadder.minHeight -= _data[dataIndex].SizeDifference;
            }

            scroller.LastPadder.gameObject.SetActive(true);

            var cellViewTween = scroller.GetCellViewAtDataIndex(dataIndex) as CellView;

            cellViewTween.BeginTween();
        }
示例#2
0
        /// <summary>
        /// This method is called by the cell view when the cell is clicked.
        /// It will set all the expansion properties of the cells, reload the scroller,
        /// set the position correctly, and kick off the tweening of the cell size
        /// </summary>
        /// <param name="dataIndex">The data index of the cell</param>
        /// <param name="cellViewIndex">The cell view index of the cell</param>
        private void InitializeTween(int dataIndex, int cellViewIndex)
        {
            // toggle the cell's expansion
            _data[dataIndex].isExpanded = !_data[dataIndex].isExpanded;

            // set all the other cells' expansion properties
            for (var i = 0; i < _data.Count; i++)
            {
                // if not this cell
                if (i != dataIndex)
                {
                    // if the clicked cell is a single cell or if this iteration is a single cell
                    // collapse other cells
                    if (((dataIndex + 2) % 3 == 0) || ((i + 2) % 3 == 0))
                    {
                        _data[i].isExpanded = false;
                    }
                }
            }

            // get the cell's position (using the cell view index in case of looping)
            var cellPosition = scroller.GetScrollPositionForCellViewIndex(cellViewIndex, EnhancedScroller.CellViewPositionEnum.Before);

            // get the offset of the cell from the top of the scroll rect
            var tweenCellOffset = cellPosition - scroller.ScrollPosition;

            // turn off loop jumping so that the scroller will not try to jump to a new location as the cell is expanding / collapsing
            scroller.IgnoreLoopJump(true);

            // reload the scroller to accommodate the new cell sizes
            scroller.ReloadData();

            // get the new position of the cell (using the cell view index in case of looping)
            cellPosition = scroller.GetScrollPositionForCellViewIndex(cellViewIndex, EnhancedScroller.CellViewPositionEnum.Before);

            // set the scroller's position to focus on the cell, using the offset calculated above
            scroller.SetScrollPositionImmediately(cellPosition - tweenCellOffset);

            // turn loop jumping back on
            scroller.IgnoreLoopJump(false);

            // if this cell has an immediate tween type, then we can just exit the
            // method and not worry about adjusting padder sizes or calling
            // the tweening on the cell
            if (_data[dataIndex].tweenType == Tween.TweenType.immediate)
            {
                return;
            }

            // cache the last padder's active state and size for after the tween
            _lastPadderActive = scroller.LastPadder.IsActive();
            _lastPadderSize   = scroller.LastPadder.minHeight;

            // manually set the last padder's size so that we can tween the cell
            // size without distorting all the cells' sizes
            if (_data[dataIndex].isExpanded)
            {
                scroller.LastPadder.minHeight += _data[dataIndex].SizeDifference;
            }
            else
            {
                scroller.LastPadder.minHeight -= _data[dataIndex].SizeDifference;
            }

            // make sure the last padder is active so that we can tween its size
            scroller.LastPadder.gameObject.SetActive(true);

            // grab the cell that was clicked so that we can start tweening.
            // note that we cannot just pass in the cell to this method since we
            // are calling ReloadData, which destroys that cell. Grabbing it
            // here is the only way to get an active cell after the reload.
            var cellViewTween = scroller.GetCellViewAtDataIndex(dataIndex) as CellView;

            // start the cell's tweening process
            cellViewTween.BeginTween();
        }