コード例 #1
0
        public _ActiveItem _removeActiveItemAt(List <_ActiveItem> items, int itemIndex)
        {
            int         i    = AnimatedListUtils.binarySearch(items, new _ActiveItem(itemIndex));
            _ActiveItem item = null;

            if (i != -1)
            {
                item = items[i];
                items.RemoveAt(i);
            }
            return(i == -1 ? null : item);
        }
コード例 #2
0
        public Widget _itemBuilder(BuildContext context, int itemIndex)
        {
            _ActiveItem outgoingItem = _activeItemAt(_outgoingItems, itemIndex);

            if (outgoingItem != null)
            {
                return(outgoingItem.removedItemBuilder(
                           context,
                           outgoingItem.controller.view
                           ));
            }
            _ActiveItem       incomingItem = _activeItemAt(_incomingItems, itemIndex);
            Animation <float> animation    = incomingItem?.controller?.view ?? Animations.kAlwaysCompleteAnimation;

            return(widget.itemBuilder(
                       context,
                       _itemIndexToIndex(itemIndex),
                       animation
                       ));
        }
コード例 #3
0
        public void insertItem(int index, TimeSpan?duration = null)
        {
            duration = duration ?? _kDuration;
            D.assert(index != null && index >= 0);
            D.assert(duration != null);
            int itemIndex = _indexToItemIndex(index);

            D.assert(itemIndex >= 0 && itemIndex <= _itemsCount);

            foreach (_ActiveItem item in _incomingItems)
            {
                if (item.itemIndex >= itemIndex)
                {
                    item.itemIndex += 1;
                }
            }
            foreach (_ActiveItem item in _outgoingItems)
            {
                if (item.itemIndex >= itemIndex)
                {
                    item.itemIndex += 1;
                }
            }
            AnimationController controller = new AnimationController(
                duration: duration,
                vsync: this
                );
            _ActiveItem incomingItem = new _ActiveItem(
                controller,
                itemIndex
                );

            setState(() => {
                _incomingItems.Add(incomingItem);
                _incomingItems.Sort();
                _itemsCount += 1;
            });
            controller.forward().then((_) => {
                _removeActiveItemAt(_incomingItems, incomingItem.itemIndex).controller.dispose();
            });
        }
コード例 #4
0
        public void removeItem(int index, AnimatedListRemovedItemBuilder builder, TimeSpan?duration = null)
        {
            duration = duration ?? _kDuration;
            D.assert(index >= 0);
            D.assert(builder != null);
            D.assert(duration != null);
            int itemIndex = _indexToItemIndex(index);

            D.assert(itemIndex >= 0 && itemIndex < _itemsCount);
            D.assert(_activeItemAt(_outgoingItems, itemIndex) == null);
            _ActiveItem         incomingItem = _removeActiveItemAt(_incomingItems, itemIndex);
            AnimationController controller   = incomingItem?.controller
                                               ?? new AnimationController(duration: duration, value: 1.0f, vsync: this);
            _ActiveItem outgoingItem = new _ActiveItem(controller, itemIndex, builder);

            setState(() => {
                _outgoingItems.Add(outgoingItem);
                _outgoingItems.Sort();
            });

            controller.reverse().then((_) => {
                _removeActiveItemAt(_outgoingItems, outgoingItem.itemIndex).controller.dispose();
                foreach (_ActiveItem item in _incomingItems)
                {
                    if (item.itemIndex > outgoingItem.itemIndex)
                    {
                        item.itemIndex -= 1;
                    }
                }
                foreach (_ActiveItem item in _outgoingItems)
                {
                    if (item.itemIndex > outgoingItem.itemIndex)
                    {
                        item.itemIndex -= 1;
                    }
                }

                setState(() => _itemsCount -= 1);
            });
        }