Merge pull request #14964 from zilongshanren/fix14909

fix pageview page turning event issue
This commit is contained in:
zilongshanren 2016-01-27 20:53:48 +08:00
commit b0d0a7a064
11 changed files with 225 additions and 89 deletions

View File

@ -1,3 +1,5 @@
/*global ccui */
/* /*
* Copyright (c) 2013-2014 Chukong Technologies Inc. * Copyright (c) 2013-2014 Chukong Technologies Inc.
* *
@ -25,15 +27,69 @@
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");
this.setString(text); this.setString(text);
}; };
ccui.Text.prototype.getStringValue = function(){ ccui.Text.prototype.getStringValue = function() {
logW("ccui.Text.getStringValue", "ccui.Text.getString"); logW("ccui.Text.getStringValue", "ccui.Text.getString");
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();
};
})(); })();

View File

@ -62,16 +62,16 @@ static int lua_cocos2dx_Widget_addTouchEventListener(lua_State* L)
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_Error tolua_err; tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.Widget",0,&tolua_err)) goto tolua_lerror; if (!tolua_isusertype(L,1,"ccui.Widget",0,&tolua_err)) goto tolua_lerror;
#endif #endif
self = static_cast<Widget*>(tolua_tousertype(L,1,0)); self = static_cast<Widget*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (nullptr == self) { if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Widget_addTouchEventListener'\n", NULL); tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Widget_addTouchEventListener'\n", NULL);
return 0; return 0;
} }
#endif #endif
argc = lua_gettop(L) - 1; argc = lua_gettop(L) - 1;
@ -183,16 +183,16 @@ static int lua_cocos2dx_CheckBox_addEventListener(lua_State* L)
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_Error tolua_err; tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.CheckBox",0,&tolua_err)) goto tolua_lerror; if (!tolua_isusertype(L,1,"ccui.CheckBox",0,&tolua_err)) goto tolua_lerror;
#endif #endif
self = static_cast<CheckBox*>(tolua_tousertype(L,1,0)); self = static_cast<CheckBox*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (nullptr == self) { if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_CheckBox_addEventListener'\n", NULL); tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_CheckBox_addEventListener'\n", NULL);
return 0; return 0;
} }
#endif #endif
argc = lua_gettop(L) - 1; argc = lua_gettop(L) - 1;
if (1 == argc) if (1 == argc)
@ -379,16 +379,16 @@ static int lua_cocos2dx_Slider_addEventListener(lua_State* L)
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_Error tolua_err; tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.Slider",0,&tolua_err)) goto tolua_lerror; if (!tolua_isusertype(L,1,"ccui.Slider",0,&tolua_err)) goto tolua_lerror;
#endif #endif
self = static_cast<Slider*>(tolua_tousertype(L,1,0)); self = static_cast<Slider*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (nullptr == self) { if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Slider_addEventListener'\n", NULL); tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Slider_addEventListener'\n", NULL);
return 0; return 0;
} }
#endif #endif
argc = lua_gettop(L) - 1; argc = lua_gettop(L) - 1;
if (1 == argc) if (1 == argc)
@ -441,16 +441,16 @@ static int lua_cocos2dx_TextField_addEventListener(lua_State* L)
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_Error tolua_err; tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.TextField",0,&tolua_err)) goto tolua_lerror; if (!tolua_isusertype(L,1,"ccui.TextField",0,&tolua_err)) goto tolua_lerror;
#endif #endif
self = static_cast<TextField*>(tolua_tousertype(L,1,0)); self = static_cast<TextField*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (nullptr == self) { if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_TextField_addEventListener'\n", NULL); tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_TextField_addEventListener'\n", NULL);
return 0; return 0;
} }
#endif #endif
argc = lua_gettop(L) - 1; argc = lua_gettop(L) - 1;
if (1 == argc) if (1 == argc)
@ -503,16 +503,16 @@ static int lua_cocos2dx_PageView_addEventListener(lua_State* L)
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_Error tolua_err; tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.PageView",0,&tolua_err)) goto tolua_lerror; if (!tolua_isusertype(L,1,"ccui.PageView",0,&tolua_err)) goto tolua_lerror;
#endif #endif
self = static_cast<PageView*>(tolua_tousertype(L,1,0)); self = static_cast<PageView*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (nullptr == self) { if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_PageView_addEventListener'\n", NULL); tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_PageView_addEventListener'\n", NULL);
return 0; return 0;
} }
#endif #endif
argc = lua_gettop(L) - 1; argc = lua_gettop(L) - 1;
if (1 == argc) if (1 == argc)
@ -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;
@ -565,16 +565,16 @@ static int lua_cocos2dx_ScrollView_addEventListener(lua_State* L)
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_Error tolua_err; tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; if (!tolua_isusertype(L,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror;
#endif #endif
self = static_cast<ScrollView*>(tolua_tousertype(L,1,0)); self = static_cast<ScrollView*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (nullptr == self) { if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_ScrollView_addEventListener'\n", NULL); tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_ScrollView_addEventListener'\n", NULL);
return 0; return 0;
} }
#endif #endif
argc = lua_gettop(L) - 1; argc = lua_gettop(L) - 1;
if (1 == argc) if (1 == argc)
@ -627,16 +627,16 @@ static int lua_cocos2dx_ListView_addEventListener(lua_State* L)
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_Error tolua_err; tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.ListView",0,&tolua_err)) goto tolua_lerror; if (!tolua_isusertype(L,1,"ccui.ListView",0,&tolua_err)) goto tolua_lerror;
#endif #endif
self = static_cast<ListView*>(tolua_tousertype(L,1,0)); self = static_cast<ListView*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (nullptr == self) { if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_ListView_addEventListener'\n", NULL); tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_ListView_addEventListener'\n", NULL);
return 0; return 0;
} }
#endif #endif
argc = lua_gettop(L) - 1; argc = lua_gettop(L) - 1;
if (1 == argc) if (1 == argc)
@ -679,16 +679,16 @@ static int lua_cocos2dx_ListView_addScrollViewEventListener(lua_State* L)
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_Error tolua_err; tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.ListView",0,&tolua_err)) goto tolua_lerror; if (!tolua_isusertype(L,1,"ccui.ListView",0,&tolua_err)) goto tolua_lerror;
#endif #endif
self = static_cast<ListView*>(tolua_tousertype(L,1,0)); self = static_cast<ListView*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (nullptr == self) { if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_ListView_addScrollViewEventListener'\n", NULL); tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_ListView_addScrollViewEventListener'\n", NULL);
return 0; return 0;
} }
#endif #endif
argc = lua_gettop(L) - 1; argc = lua_gettop(L) - 1;
if (1 == argc) if (1 == argc)
@ -743,16 +743,16 @@ static int lua_cocos2dx_LayoutParameter_setMargin(lua_State* L)
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_Error tolua_err; tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.LayoutParameter",0,&tolua_err)) goto tolua_lerror; if (!tolua_isusertype(L,1,"ccui.LayoutParameter",0,&tolua_err)) goto tolua_lerror;
#endif #endif
self = static_cast<LayoutParameter*>(tolua_tousertype(L,1,0)); self = static_cast<LayoutParameter*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (nullptr == self) { if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_LayoutParameter_setMargin'\n", NULL); tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_LayoutParameter_setMargin'\n", NULL);
return 0; return 0;
} }
#endif #endif
argc = lua_gettop(L) - 1; argc = lua_gettop(L) - 1;
@ -811,16 +811,16 @@ static int lua_cocos2dx_LayoutParameter_getMargin(lua_State* L)
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_Error tolua_err; tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.LayoutParameter",0,&tolua_err)) goto tolua_lerror; if (!tolua_isusertype(L,1,"ccui.LayoutParameter",0,&tolua_err)) goto tolua_lerror;
#endif #endif
self = static_cast<LayoutParameter*>(tolua_tousertype(L,1,0)); self = static_cast<LayoutParameter*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (nullptr == self) { if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_LayoutParameter_getMargin'\n", NULL); tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_LayoutParameter_getMargin'\n", NULL);
return 0; return 0;
} }
#endif #endif
argc = lua_gettop(L) - 1; argc = lua_gettop(L) - 1;
@ -883,16 +883,16 @@ static int tolua_cocos2d_EditBox_registerScriptEditBoxHandler(lua_State* L)
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_Error tolua_err; tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.EditBox",0,&tolua_err)) goto tolua_lerror; if (!tolua_isusertype(L,1,"ccui.EditBox",0,&tolua_err)) goto tolua_lerror;
#endif #endif
self = static_cast<EditBox*>(tolua_tousertype(L,1,0)); self = static_cast<EditBox*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (nullptr == self) { if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'tolua_cocos2d_EditBox_registerScriptEditBoxHandler'\n", NULL); tolua_error(L,"invalid 'self' in function 'tolua_cocos2d_EditBox_registerScriptEditBoxHandler'\n", NULL);
return 0; return 0;
} }
#endif #endif
argc = lua_gettop(L) - 1; argc = lua_gettop(L) - 1;
@ -932,16 +932,16 @@ static int tolua_cocos2d_EditBox_unregisterScriptEditBoxHandler(lua_State* L)
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_Error tolua_err; tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.EditBox",0,&tolua_err)) goto tolua_lerror; if (!tolua_isusertype(L,1,"ccui.EditBox",0,&tolua_err)) goto tolua_lerror;
#endif #endif
self = static_cast<EditBox*>(tolua_tousertype(L,1,0)); self = static_cast<EditBox*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (nullptr == self) { if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'tolua_cocos2d_EditBox_unregisterScriptEditBoxHandler'\n", NULL); tolua_error(L,"invalid 'self' in function 'tolua_cocos2d_EditBox_unregisterScriptEditBoxHandler'\n", NULL);
return 0; return 0;
} }
#endif #endif
argc = lua_gettop(L) - 1; argc = lua_gettop(L) - 1;
@ -1072,9 +1072,9 @@ static int tolua_cocos2dx_EventListenerFocus_clone(lua_State* L)
self = static_cast<EventListenerFocus*>(tolua_tousertype(L,1,0)); self = static_cast<EventListenerFocus*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (nullptr == self) { if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'tolua_cocos2dx_EventListenerFocus_clone'\n", nullptr); tolua_error(L,"invalid 'self' in function 'tolua_cocos2dx_EventListenerFocus_clone'\n", nullptr);
return 0; return 0;
} }
#endif #endif
argc = lua_gettop(L) - 1; argc = lua_gettop(L) - 1;
@ -1120,9 +1120,9 @@ static int tolua_cocos2dx_EventListenerFocus_registerScriptHandler(lua_State* L)
self = static_cast<EventListenerFocus*>(tolua_tousertype(L,1,0)); self = static_cast<EventListenerFocus*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (nullptr == self) { if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'tolua_cocos2dx_EventListenerFocus_registerScriptHandler'\n", nullptr); tolua_error(L,"invalid 'self' in function 'tolua_cocos2dx_EventListenerFocus_registerScriptHandler'\n", nullptr);
return 0; return 0;
} }
#endif #endif
argc = lua_gettop(L) - 1; argc = lua_gettop(L) - 1;
@ -1183,8 +1183,8 @@ int register_ui_moudle(lua_State* L)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_TARGET_OS_TVOS) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_TARGET_OS_TVOS)
register_all_cocos2dx_experimental_video(L); register_all_cocos2dx_experimental_video(L);
register_all_cocos2dx_experimental_video_manual(L); register_all_cocos2dx_experimental_video_manual(L);
register_all_cocos2dx_experimental_webview(L); register_all_cocos2dx_experimental_webview(L);
register_all_cocos2dx_experimental_webview_manual(L); register_all_cocos2dx_experimental_webview_manual(L);
#endif #endif
extendEventListenerFocusEvent(L); extendEventListenerFocusEvent(L);
} }

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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
}; };
/** /**

View File

@ -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);

View File

@ -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;
} }
@ -334,4 +335,4 @@ var UIListViewTest_TouchIntercept = UIMainLayer.extend({
} }
return false; return false;
} }
}); });

View File

@ -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;
@ -580,4 +585,4 @@ var UIPageViewDisableTouchTest = UIMainLayer.extend({
} }
return false; return false;
} }
}); });

View File

@ -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