From 7f9c8acc2ab67d8b6e657327a208e17b43076f19 Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Sun, 13 Sep 2015 19:36:22 +0900 Subject: [PATCH] ScrollView - Add a guard statement in setContentSize() to avoid resetting inner container's position if not necessary. --- cocos/ui/UIScrollView.cpp | 10 ++++++++++ cocos/ui/UIScrollView.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index 9296afb087..b39780eb50 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -997,6 +997,16 @@ void ScrollView::update(float dt) } } +void ScrollView::setContentSize(const cocos2d::Size &contentSize) +{ + Size previousSize = Layout::getContentSize(); + if(previousSize.equals(contentSize)) + { + return; + } + Layout::setContentSize(contentSize); +} + void ScrollView::interceptTouchEvent(Widget::TouchEventType event, Widget *sender,Touch* touch) { if(!_touchEnabled) diff --git a/cocos/ui/UIScrollView.h b/cocos/ui/UIScrollView.h index 63a1cc4611..4c09b328fb 100644 --- a/cocos/ui/UIScrollView.h +++ b/cocos/ui/UIScrollView.h @@ -357,7 +357,7 @@ public: virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override; virtual void onTouchCancelled(Touch *touch, Event *unusedEvent) override; virtual void update(float dt) override; - + virtual void setContentSize(const Size &contentSize) override; /** * @brief Toggle bounce enabled when scroll to the edge.