diff --git a/cocos/ui/UIListView.cpp b/cocos/ui/UIListView.cpp index a50804045c..b08ee6f751 100644 --- a/cocos/ui/UIListView.cpp +++ b/cocos/ui/UIListView.cpp @@ -100,6 +100,11 @@ void ListView::handleReleaseLogic(Touch *touch) } } +void ListView::onItemListChanged() +{ + _outOfBoundaryAmountDirty = true; +} + void ListView::updateInnerContainerSize() { switch (_direction) @@ -263,7 +268,7 @@ void ListView::addChild(cocos2d::Node *child, int zOrder, int tag) if (nullptr != widget) { _items.pushBack(widget); - _outOfBoundaryAmountDirty = true; + onItemListChanged(); } } @@ -285,7 +290,7 @@ void ListView::addChild(Node* child, int zOrder, const std::string &name) if (nullptr != widget) { _items.pushBack(widget); - _outOfBoundaryAmountDirty = true; + onItemListChanged(); } } @@ -307,7 +312,7 @@ void ListView::removeChild(cocos2d::Node *child, bool cleaup) } } _items.eraseObject(widget); - _outOfBoundaryAmountDirty = true; + onItemListChanged(); } ScrollView::removeChild(child, cleaup); @@ -321,9 +326,9 @@ void ListView::removeAllChildren() void ListView::removeAllChildrenWithCleanup(bool cleanup) { ScrollView::removeAllChildrenWithCleanup(cleanup); - _items.clear(); _curSelectedIndex = -1; - _outOfBoundaryAmountDirty = true; + _items.clear(); + onItemListChanged(); } void ListView::insertCustomItem(Widget* item, ssize_t index) @@ -336,8 +341,8 @@ void ListView::insertCustomItem(Widget* item, ssize_t index) } } _items.insert(index, item); - _outOfBoundaryAmountDirty = true; - + onItemListChanged(); + ScrollView::addChild(item); remedyLayoutParameter(item); diff --git a/cocos/ui/UIListView.h b/cocos/ui/UIListView.h index 25978f13e5..3acfd20da8 100644 --- a/cocos/ui/UIListView.h +++ b/cocos/ui/UIListView.h @@ -387,7 +387,9 @@ CC_CONSTRUCTOR_ACCESS: protected: virtual void handleReleaseLogic(Touch *touch) override; - + + virtual void onItemListChanged(); + void updateInnerContainerSize(); void remedyLayoutParameter(Widget* item); void remedyVerticalLayoutParameter(LinearLayoutParameter* layoutParameter, ssize_t itemIndex); diff --git a/cocos/ui/UIPageView.cpp b/cocos/ui/UIPageView.cpp index 17c9870eb7..fa241ee05c 100644 --- a/cocos/ui/UIPageView.cpp +++ b/cocos/ui/UIPageView.cpp @@ -137,6 +137,13 @@ bool PageView::isUsingCustomScrollThreshold()const return _usingCustomScrollThreshold; } +void PageView::onItemListChanged() +{ + ListView::onItemListChanged(); + ssize_t index = getIndex(getCenterItemInCurrentView()); + _indicator->reset(_items.size(), index); +} + void PageView::onSizeChanged() { ListView::onSizeChanged(); diff --git a/cocos/ui/UIPageView.h b/cocos/ui/UIPageView.h index 8c26ad7fe5..a7343a13aa 100644 --- a/cocos/ui/UIPageView.h +++ b/cocos/ui/UIPageView.h @@ -256,6 +256,7 @@ CC_CONSTRUCTOR_ACCESS: protected: void pageTurningEvent(); + virtual void onItemListChanged() override; virtual void onSizeChanged() override; virtual void handleReleaseLogic(Touch *touch) override;