mirror of https://github.com/axmolengine/axmol.git
Merge pull request #14964 from zilongshanren/fix14909
fix pageview page turning event issue
This commit is contained in:
commit
b0d0a7a064
|
@ -1,3 +1,5 @@
|
||||||
|
/*global ccui */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2014 Chukong Technologies Inc.
|
* Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||||
*
|
*
|
||||||
|
@ -25,6 +27,9 @@
|
||||||
var cc = cc || {};
|
var cc = cc || {};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
var logW = function(oldName, newName) {
|
||||||
|
cc.log("\n********** \n"+oldName +" was deprecated, please use "+ newName +" instead.\n**********");
|
||||||
|
};
|
||||||
|
|
||||||
ccui.Text.prototype.setText = function(text) {
|
ccui.Text.prototype.setText = function(text) {
|
||||||
logW("ccui.Text.setText", "ccui.Text.setString");
|
logW("ccui.Text.setText", "ccui.Text.setString");
|
||||||
|
@ -36,4 +41,55 @@ var cc = cc || {};
|
||||||
return this.getString();
|
return this.getString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ccui.PageView.prototype.getCurPageIndex = function() {
|
||||||
|
logW("ccui.PageView.getCurPageIndex", "ccui.PageView.getCurrentPageIndex");
|
||||||
|
return this.getCurrentPageIndex();
|
||||||
|
};
|
||||||
|
|
||||||
|
ccui.PageView.prototype.addWidgetToPage = function(widget, pageIndx) {
|
||||||
|
logW("ccui.PageView.addWidgetToPage", "ccui.PageView.insertPage");
|
||||||
|
return this.insertPage(widget, pageIndx);
|
||||||
|
};
|
||||||
|
|
||||||
|
ccui.PageView.prototype.setCurPageIndex = function(index) {
|
||||||
|
logW("ccui.PageView.setCurPageIndex", "ccui.PageView.setCurrentPageIndex");
|
||||||
|
return this.setCurrentPageIndex(index);
|
||||||
|
};
|
||||||
|
|
||||||
|
ccui.PageView.prototype.getPages = function() {
|
||||||
|
logW("ccui.PageView.getPages", "ccui.PageView.getItems");
|
||||||
|
return this.getItems();
|
||||||
|
};
|
||||||
|
|
||||||
|
ccui.PageView.prototype.getPage = function(index) {
|
||||||
|
logW("ccui.PageView.getPage", "ccui.PageView.getItem");
|
||||||
|
return this.getItem(index);
|
||||||
|
};
|
||||||
|
|
||||||
|
ccui.PageView.prototype.setCustomScrollThreshold = function() {
|
||||||
|
cc.log("Since v3.9, this method has no effect.");
|
||||||
|
};
|
||||||
|
|
||||||
|
ccui.PageView.prototype.getCustomScrollThreshold = function() {
|
||||||
|
cc.log("Since v3.9, this method has no effect.");
|
||||||
|
};
|
||||||
|
|
||||||
|
ccui.PageView.prototype.setUsingCustomScrollThreshold = function() {
|
||||||
|
cc.log("Since v3.9, this method has no effect.");
|
||||||
|
};
|
||||||
|
|
||||||
|
ccui.PageView.prototype.isUsingCustomScrollThreshold = function() {
|
||||||
|
cc.log("Since v3.9, this method has no effect.");
|
||||||
|
};
|
||||||
|
|
||||||
|
ccui.ListView.prototype.requestRefreshView = function() {
|
||||||
|
logW("ccui.ListView.requestRefreshView", "ccui.ListView.forceDoLayout");
|
||||||
|
this.forceDoLayout();
|
||||||
|
};
|
||||||
|
|
||||||
|
ccui.ListView.prototype.refreshView = function() {
|
||||||
|
logW("ccui.ListView.refreshView", "ccui.ListView.forceDoLayout");
|
||||||
|
this.forceDoLayout();
|
||||||
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -524,10 +524,10 @@ static int lua_cocos2dx_PageView_addEventListener(lua_State* L)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0));
|
LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0));
|
||||||
|
auto pageViewHandler = [=](cocos2d::Ref* ref,PageView::EventType eventType){
|
||||||
self->addEventListener([=](cocos2d::Ref* ref,PageView::EventType eventType){
|
|
||||||
handleUIEvent(handler, ref, (int)eventType);
|
handleUIEvent(handler, ref, (int)eventType);
|
||||||
});
|
};
|
||||||
|
self->addEventListener((PageView::ccPageViewCallback)pageViewHandler);
|
||||||
|
|
||||||
ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler);
|
ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -162,6 +162,56 @@ function UIPageViewDeprecated.addEventListenerPageView(self,handler)
|
||||||
return self:addEventListener(handler)
|
return self:addEventListener(handler)
|
||||||
end
|
end
|
||||||
ccui.PageView.addEventListenerPageView = UIPageViewDeprecated.addEventListenerPageView
|
ccui.PageView.addEventListenerPageView = UIPageViewDeprecated.addEventListenerPageView
|
||||||
|
|
||||||
|
function UIPageViewDeprecated.addWidgetToPage(self, widget, pageIdx)
|
||||||
|
deprecatedTip("ccui.PageView:addWidgetToPage","ccui.PageView:insertPage")
|
||||||
|
return self:insertPage(widget, pageIdx)
|
||||||
|
end
|
||||||
|
ccui.PageView.addWidgetToPage = UIPageViewDeprecated.addWidgetToPage
|
||||||
|
|
||||||
|
function UIPageViewDeprecated.getCurPageIndex(self)
|
||||||
|
deprecatedTip("ccui.PageView:getCurPageIndex","ccui.PageView:getCurrentPageIndex")
|
||||||
|
return self:getCurrentPageIndex()
|
||||||
|
end
|
||||||
|
ccui.PageView.getCurPageIndex = UIPageViewDeprecated.getCurPageIndex
|
||||||
|
|
||||||
|
function UIPageViewDeprecated.setCurPageIndex(self, index)
|
||||||
|
deprecatedTip("ccui.PageView:setCurPageIndex","ccui.PageView:setCurrentPageIndex")
|
||||||
|
return self:setCurrentPageIndex(index)
|
||||||
|
end
|
||||||
|
ccui.PageView.setCurPageIndex = UIPageViewDeprecated.setCurPageIndex
|
||||||
|
|
||||||
|
function UIPageViewDeprecated.getPages(self)
|
||||||
|
deprecatedTip("ccui.PageView:getPages","ccui.PageView:getItems")
|
||||||
|
return self:getItems()
|
||||||
|
end
|
||||||
|
ccui.PageView.getPages = UIPageViewDeprecated.getPages
|
||||||
|
|
||||||
|
function UIPageViewDeprecated.getPage(self, index)
|
||||||
|
deprecatedTip("ccui.PageView:getPage","ccui.PageView:getItem")
|
||||||
|
return self:getItem(index)
|
||||||
|
end
|
||||||
|
ccui.PageView.getPage = UIPageViewDeprecated.getPage
|
||||||
|
|
||||||
|
function UIPageViewDeprecated.setCustomScrollThreshold(self)
|
||||||
|
print("Since v3.9, this method has no effect.")
|
||||||
|
end
|
||||||
|
ccui.PageView.setCustomScrollThreshold = UIPageViewDeprecated.setCustomScrollThreshold
|
||||||
|
|
||||||
|
function UIPageViewDeprecated.getCustomScrollThreshold(self)
|
||||||
|
print("Since v3.9, this method has no effect.")
|
||||||
|
end
|
||||||
|
ccui.PageView.getCustomScrollThreshold = UIPageViewDeprecated.getCustomScrollThreshold
|
||||||
|
|
||||||
|
function UIPageViewDeprecated.isUsingCustomScrollThreshold(self)
|
||||||
|
print("Since v3.9, this method has no effect.")
|
||||||
|
end
|
||||||
|
ccui.PageView.isUsingCustomScrollThreshold = UIPageViewDeprecated.isUsingCustomScrollThreshold
|
||||||
|
|
||||||
|
function UIPageViewDeprecated.setUsingCustomScrollThreshold(self)
|
||||||
|
print("Since v3.9, this method has no effect.")
|
||||||
|
end
|
||||||
|
ccui.PageView.setUsingCustomScrollThreshold = UIPageViewDeprecated.setUsingCustomScrollThreshold
|
||||||
--functions of ccui.PageView will be deprecated end
|
--functions of ccui.PageView will be deprecated end
|
||||||
|
|
||||||
--functions of ccui.ScrollView will be deprecated begin
|
--functions of ccui.ScrollView will be deprecated begin
|
||||||
|
@ -180,4 +230,16 @@ function UIListViewDeprecated.addEventListenerListView(self,handler)
|
||||||
return self:addEventListener(handler)
|
return self:addEventListener(handler)
|
||||||
end
|
end
|
||||||
ccui.ListView.addEventListenerListView = UIListViewDeprecated.addEventListenerListView
|
ccui.ListView.addEventListenerListView = UIListViewDeprecated.addEventListenerListView
|
||||||
|
|
||||||
|
function UIListViewDeprecated.requestRefreshView(self)
|
||||||
|
deprecatedTip("ccui.ListView:requestRefreshView","ccui.ListView:forceDoLayout")
|
||||||
|
return self:forceDoLayout()
|
||||||
|
end
|
||||||
|
ccui.ListView.requestRefreshView = UIListViewDeprecated.requestRefreshView
|
||||||
|
|
||||||
|
function UIListViewDeprecated.refreshView(self)
|
||||||
|
deprecatedTip("ccui.ListView:refreshView","ccui.ListView:refreshView")
|
||||||
|
return self:forceDoLayout()
|
||||||
|
end
|
||||||
|
ccui.ListView.refreshView = UIListViewDeprecated.refreshView
|
||||||
--functions of ccui.ListView will be deprecated end
|
--functions of ccui.ListView will be deprecated end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ void PageView::handleReleaseLogic(Touch *touch)
|
||||||
{
|
{
|
||||||
--_currentPageIndex;
|
--_currentPageIndex;
|
||||||
}
|
}
|
||||||
_currentPageIndex = MIN(_currentPageIndex, _items.size());
|
_currentPageIndex = MIN(_currentPageIndex, _items.size() - 1);
|
||||||
_currentPageIndex = MAX(_currentPageIndex, 0);
|
_currentPageIndex = MAX(_currentPageIndex, 0);
|
||||||
scrollToItem(_currentPageIndex);
|
scrollToItem(_currentPageIndex);
|
||||||
}
|
}
|
||||||
|
@ -288,6 +288,12 @@ void PageView::addEventListenerPageView(Ref *target, SEL_PageViewEvent selector)
|
||||||
void PageView::addEventListener(const ccPageViewCallback& callback)
|
void PageView::addEventListener(const ccPageViewCallback& callback)
|
||||||
{
|
{
|
||||||
_eventCallback = callback;
|
_eventCallback = callback;
|
||||||
|
ccScrollViewCallback scrollViewCallback = [=](Ref* ref, ScrollView::EventType type) -> void{
|
||||||
|
if (type == ScrollView::EventType::AUTOSCROLL_ENDED) {
|
||||||
|
callback(ref, PageView::EventType::TURNING);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this->addEventListener(scrollViewCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t PageView::getCurPageIndex() const
|
ssize_t PageView::getCurPageIndex() const
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ public:
|
||||||
* @param callback A page turning callback.
|
* @param callback A page turning callback.
|
||||||
*/
|
*/
|
||||||
void addEventListener(const ccPageViewCallback& callback);
|
void addEventListener(const ccPageViewCallback& callback);
|
||||||
|
using ScrollView::addEventListener;
|
||||||
//override methods
|
//override methods
|
||||||
virtual std::string getDescription() const override;
|
virtual std::string getDescription() const override;
|
||||||
|
|
||||||
|
|
|
@ -535,6 +535,7 @@ void ScrollView::processAutoScrolling(float deltaTime)
|
||||||
if(reachedEnd)
|
if(reachedEnd)
|
||||||
{
|
{
|
||||||
_autoScrolling = false;
|
_autoScrolling = false;
|
||||||
|
dispatchEvent(SCROLLVIEW_EVENT_AUTOSCROLL_ENDED, EventType::AUTOSCROLL_ENDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
moveInnerContainer(newPosition - getInnerContainerPosition(), reachedEnd);
|
moveInnerContainer(newPosition - getInnerContainerPosition(), reachedEnd);
|
||||||
|
|
|
@ -55,7 +55,8 @@ typedef enum
|
||||||
SCROLLVIEW_EVENT_BOUNCE_TOP,
|
SCROLLVIEW_EVENT_BOUNCE_TOP,
|
||||||
SCROLLVIEW_EVENT_BOUNCE_BOTTOM,
|
SCROLLVIEW_EVENT_BOUNCE_BOTTOM,
|
||||||
SCROLLVIEW_EVENT_BOUNCE_LEFT,
|
SCROLLVIEW_EVENT_BOUNCE_LEFT,
|
||||||
SCROLLVIEW_EVENT_BOUNCE_RIGHT
|
SCROLLVIEW_EVENT_BOUNCE_RIGHT,
|
||||||
|
SCROLLVIEW_EVENT_AUTOSCROLL_ENDED
|
||||||
}ScrollviewEventType;
|
}ScrollviewEventType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,7 +101,8 @@ public:
|
||||||
BOUNCE_BOTTOM,
|
BOUNCE_BOTTOM,
|
||||||
BOUNCE_LEFT,
|
BOUNCE_LEFT,
|
||||||
BOUNCE_RIGHT,
|
BOUNCE_RIGHT,
|
||||||
CONTAINER_MOVED
|
CONTAINER_MOVED,
|
||||||
|
AUTOSCROLL_ENDED
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -83,7 +83,7 @@ bool UIPageViewTest::init()
|
||||||
|
|
||||||
pageView->removeItem(0);
|
pageView->removeItem(0);
|
||||||
pageView->scrollToItem(pageCount - 2);
|
pageView->scrollToItem(pageCount - 2);
|
||||||
pageView->addEventListener(CC_CALLBACK_2(UIPageViewTest::pageViewEvent, this));
|
pageView->addEventListener((PageView::ccPageViewCallback)CC_CALLBACK_2(UIPageViewTest::pageViewEvent, this));
|
||||||
|
|
||||||
_uiLayer->addChild(pageView);
|
_uiLayer->addChild(pageView);
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ bool UIPageViewButtonTest::init()
|
||||||
|
|
||||||
pageView->removeItem(0);
|
pageView->removeItem(0);
|
||||||
|
|
||||||
pageView->addEventListener(CC_CALLBACK_2(UIPageViewButtonTest::pageViewEvent, this));
|
pageView->addEventListener((PageView::ccPageViewCallback)CC_CALLBACK_2(UIPageViewButtonTest::pageViewEvent, this));
|
||||||
|
|
||||||
_uiLayer->addChild(pageView);
|
_uiLayer->addChild(pageView);
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ bool UIPageViewTouchPropagationTest::init()
|
||||||
pageView->insertCustomItem(outerBox, i);
|
pageView->insertCustomItem(outerBox, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
pageView->addEventListener(CC_CALLBACK_2(UIPageViewTouchPropagationTest::pageViewEvent, this));
|
pageView->addEventListener((PageView::ccPageViewCallback)CC_CALLBACK_2(UIPageViewTouchPropagationTest::pageViewEvent, this));
|
||||||
pageView->setName("pageView");
|
pageView->setName("pageView");
|
||||||
pageView->addTouchEventListener([](Ref* sender, Widget::TouchEventType type){
|
pageView->addTouchEventListener([](Ref* sender, Widget::TouchEventType type){
|
||||||
if (type == Widget::TouchEventType::BEGAN)
|
if (type == Widget::TouchEventType::BEGAN)
|
||||||
|
@ -493,7 +493,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init()
|
||||||
pageView->insertCustomItem(outerBox, i);
|
pageView->insertCustomItem(outerBox, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
pageView->addEventListener(CC_CALLBACK_2(UIPageViewDynamicAddAndRemoveTest::pageViewEvent, this));
|
pageView->addEventListener((PageView::ccPageViewCallback)CC_CALLBACK_2(UIPageViewDynamicAddAndRemoveTest::pageViewEvent, this));
|
||||||
pageView->setName("pageView");
|
pageView->setName("pageView");
|
||||||
_uiLayer->addChild(pageView);
|
_uiLayer->addChild(pageView);
|
||||||
|
|
||||||
|
@ -777,7 +777,7 @@ bool UIPageViewVerticalTest::init()
|
||||||
pageView->insertCustomItem(layout, i);
|
pageView->insertCustomItem(layout, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
pageView->addEventListener(CC_CALLBACK_2(UIPageViewVerticalTest::pageViewEvent, this));
|
pageView->addEventListener((PageView::ccPageViewCallback)CC_CALLBACK_2(UIPageViewVerticalTest::pageViewEvent, this));
|
||||||
|
|
||||||
_uiLayer->addChild(pageView);
|
_uiLayer->addChild(pageView);
|
||||||
|
|
||||||
|
@ -936,7 +936,7 @@ bool UIPageViewChildSizeTest::init()
|
||||||
pageView->insertCustomItem(imageView, i);
|
pageView->insertCustomItem(imageView, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
pageView->addEventListener(CC_CALLBACK_2(UIPageViewChildSizeTest::pageViewEvent, this));
|
pageView->addEventListener((PageView::ccPageViewCallback)CC_CALLBACK_2(UIPageViewChildSizeTest::pageViewEvent, this));
|
||||||
|
|
||||||
_uiLayer->addChild(pageView);
|
_uiLayer->addChild(pageView);
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,7 @@ var UIListViewTest_Vertical = UIMainLayer.extend({
|
||||||
|
|
||||||
// set all items layout gravity
|
// set all items layout gravity
|
||||||
listView.setGravity(ccui.ListView.GRAVITY_CENTER_VERTICAL);
|
listView.setGravity(ccui.ListView.GRAVITY_CENTER_VERTICAL);
|
||||||
|
listView.requestRefreshView();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,9 +66,14 @@ var UIPageViewTest = UIMainLayer.extend({
|
||||||
text.y = layoutRect.height / 2;
|
text.y = layoutRect.height / 2;
|
||||||
layout.addChild(text);
|
layout.addChild(text);
|
||||||
|
|
||||||
pageView.addPage(layout);
|
pageView.addWidgetToPage(layout, i);
|
||||||
}
|
}
|
||||||
|
pageView.setCurPageIndex(1);
|
||||||
pageView.addEventListener(this.pageViewEvent, this);
|
pageView.addEventListener(this.pageViewEvent, this);
|
||||||
|
|
||||||
|
//for test purpose only
|
||||||
|
cc.log(pageView.getPages());
|
||||||
|
cc.log(pageView.getPage(0));
|
||||||
this._mainNode.addChild(pageView);
|
this._mainNode.addChild(pageView);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1748,13 +1748,16 @@ add_new_testcase(function()
|
||||||
label:setPosition(cc.p(layout:getContentSize().width / 2, layout:getContentSize().height / 2))
|
label:setPosition(cc.p(layout:getContentSize().width / 2, layout:getContentSize().height / 2))
|
||||||
layout:addChild(label)
|
layout:addChild(label)
|
||||||
|
|
||||||
pageView:addPage(layout)
|
pageView:addWidgetToPage(layout, i-1)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
pageView:setCurPageIndex(1)
|
||||||
|
|
||||||
local function pageViewEvent(sender, eventType)
|
local function pageViewEvent(sender, eventType)
|
||||||
if eventType == ccui.PageViewEventType.turning then
|
if eventType == ccui.PageViewEventType.turning then
|
||||||
local pageInfo = string.format("page %d " , pageView:getCurPageIndex() + 1)
|
local pageInfo = string.format("page %d " , pageView:getCurPageIndex() + 1)
|
||||||
|
local pages = pageView:getPages()
|
||||||
|
print("total items " .. table.getn(pages))
|
||||||
self._displayValueLabel:setString(pageInfo)
|
self._displayValueLabel:setString(pageInfo)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue