From 9c1aed5838704a5b0184130c2bf4691f7c163f56 Mon Sep 17 00:00:00 2001 From: Vlad Shcherban Date: Fri, 6 Jul 2018 09:31:25 -0400 Subject: [PATCH] Sync to 2018.7.4 --- widgetLibrary/widget.lua | 15 ++++++++------ widgetLibrary/widget_momentumScrolling.lua | 3 +-- widgetLibrary/widget_pickerWheel.lua | 6 ++++++ widgetLibrary/widget_scrollview.lua | 23 ++++++---------------- widgetLibrary/widget_tabbar.lua | 20 +++++++++++++------ widgetLibrary/widget_tableview.lua | 11 +++++++++++ 6 files changed, 47 insertions(+), 31 deletions(-) diff --git a/widgetLibrary/widget.lua b/widgetLibrary/widget.lua index c2c9021..c357470 100755 --- a/widgetLibrary/widget.lua +++ b/widgetLibrary/widget.lua @@ -24,12 +24,15 @@ function display.newGroup() local function removeWidgets( group ) if group.numChildren then for i = group.numChildren, 1, -1 do - if group[i]._isWidget then - group[i]:removeSelf() - - elseif not group[i]._isWidget and group[i].numChildren then - -- Nested group (that is not a widget) - removeWidgets( group[i] ) + local toRemove = group[i] + if toRemove then + if toRemove._isWidget then + toRemove:removeSelf() + + elseif not toRemove._isWidget and toRemove.numChildren then + -- Nested group (that is not a widget) + removeWidgets( toRemove ) + end end end end diff --git a/widgetLibrary/widget_momentumScrolling.lua b/widgetLibrary/widget_momentumScrolling.lua index 377fb4e..91c5cb7 100644 --- a/widgetLibrary/widget_momentumScrolling.lua +++ b/widgetLibrary/widget_momentumScrolling.lua @@ -673,7 +673,6 @@ function lib.createScrollBar( view, options ) -- Setup the scrollBar's width/height --local parentGroup = view.parent.parent - local scrollBarWidth = options.width or 5 local viewHeight = view._height -- The height of the windows visible area local viewContentHeight = view._scrollHeight -- The height of the total content height local minimumScrollBarHeight = 24 -- The minimum height the scrollbar can be @@ -819,7 +818,7 @@ function lib.createScrollBar( view, options ) -- Insert the scrollBar into the fixed group and position it view._fixedGroup:insert( lib.scrollBar ) - view._fixedGroup.x = view._width * 0.5 - scrollBarWidth * 0.5 + view._fixedGroup.x = view._width * 0.5 - opt.width * 0.5 --local viewFixedGroupY = view.parent.y - view._top - view._height * 0.5 -- this has to be positioned at the yCoord - half the height, no matter what. diff --git a/widgetLibrary/widget_pickerWheel.lua b/widgetLibrary/widget_pickerWheel.lua index 1ecc43f..7b5b69f 100644 --- a/widgetLibrary/widget_pickerWheel.lua +++ b/widgetLibrary/widget_pickerWheel.lua @@ -549,6 +549,12 @@ local function createPickerWheel( pickerWheel, options ) -- EnterFrame listener for our pickerWheel function view:enterFrame( event ) + + if not self.parent then + Runtime:removeEventListener( "enterFrame", self ) + return true + end + local _pickerWheel = self.parent -- Update the y position -- this has to be calculated in content coordinates to abstract the widget being in a group diff --git a/widgetLibrary/widget_scrollview.lua b/widgetLibrary/widget_scrollview.lua index 9ea2ce3..a52bb0f 100644 --- a/widgetLibrary/widget_scrollview.lua +++ b/widgetLibrary/widget_scrollview.lua @@ -582,23 +582,6 @@ local function createScrollView( scrollView, options ) if "began" == phase then self._timeHeld = event.time end - - -- Android fix for objects inserted into scrollView's - if self._isPlatformAndroid then - -- Distance moved - local dy = mAbs( event.y - event.yStart ) - local dx = mAbs( event.x - event.xStart ) - local moveThresh = 20 - - -- If the finger has moved less than the desired range, set the phase back to began (Android only fix, iOS doesn't exhibit this touch behavior..) - if dy < moveThresh then - if dx < moveThresh then - if phase ~= "ended" and phase ~= "cancelled" then - event.phase = "began" - end - end - end - end -- Handle momentum scrolling (and the view isn't locked) if not self._isLocked then @@ -639,6 +622,12 @@ local function createScrollView( scrollView, options ) -- EnterFrame listener for our scrollView function view:enterFrame( event ) + + if not self.parent then + Runtime:removeEventListener( "enterFrame", self ) + return true + end + local _scrollView = self.parent -- Handle momentum @ runtime diff --git a/widgetLibrary/widget_tabbar.lua b/widgetLibrary/widget_tabbar.lua index 46515dc..c5acf74 100644 --- a/widgetLibrary/widget_tabbar.lua +++ b/widgetLibrary/widget_tabbar.lua @@ -205,8 +205,8 @@ local function initWithImageFiles( tabBar, options ) viewSelected.x = viewButtons[view._defaultTab].x - ( viewSelected.contentWidth * 0.5 ) - tabBar.x -- Throw error if tabBar width is too small to hold all passed in tab items - if ( view._totalTabWidth + 4 ) > opt.width then - error( "ERROR: " .. M._widgetName .. ": width passed is too small to fit the tab items inside, you need a width of at least " .. ( view._totalTabWidth + 4 ) .. " to fit your tab items inside", 3 ) + if view._totalTabWidth > opt.width then + error( "ERROR: " .. M._widgetName .. ": width passed is too small to fit the tab items inside, you need a width of at least " .. view._totalTabWidth .. " to fit your tab items inside", 3 ) end ------------------------------------------------------- @@ -438,14 +438,22 @@ local function initWithImageSheet( tabBar, options ) viewButtons[i] = display.newImageRect( tabBar, imageSheet, 7, 15, 15 ) --error( "ERROR: " .. M._widgetName .. ": tab button default file expected, got nil" ) else - viewButtons[i] = display.newImageRect( tabBar, opt.tabButtons[i].defaultFile, opt.tabButtons[i].width, opt.tabButtons[i].height ) + if opt.tabButtons[i].width ~= nil and opt.tabButtons[i].height ~= nil then + viewButtons[i] = display.newImageRect( tabBar, opt.tabButtons[i].defaultFile, opt.tabButtons[i].width, opt.tabButtons[i].height ) + else + viewButtons[i] = display.newImage( tabBar, opt.tabButtons[i].defaultFile ) + end end if not opt.tabButtons[i].overFile then viewButtons[i].over = display.newImageRect( tabBar, imageSheet, 10, 15, 15 ) --error( "ERROR: " .. M._widgetName .. ": tab button default file expected, got nil" ) else - viewButtons[i].over = display.newImageRect( tabBar, opt.tabButtons[i].overFile, opt.tabButtons[i].width, opt.tabButtons[i].height ) + if opt.tabButtons[i].width ~= nil and opt.tabButtons[i].height ~= nil then + viewButtons[i].over = display.newImageRect( tabBar, opt.tabButtons[i].overFile, opt.tabButtons[i].width, opt.tabButtons[i].height ) + else + viewButtons[i].over = display.newImage( tabBar, opt.tabButtons[i].overFile ) + end end viewButtons[i].over.isVisible = false end @@ -557,8 +565,8 @@ local function initWithImageSheet( tabBar, options ) --viewSelected.y = tabBar.y - viewSelected.contentHeight * 0.5 -- Throw error if tabBar width is too small to hold all passed in tab items - if ( view._totalTabWidth + 4 ) > view.width then - error( "ERROR: " .. M._widgetName .. ": width passed is too small to fit the tab items inside, you need a width of at least " .. ( view._totalTabWidth + 4 ) .. " to fit your tab items inside", 3 ) + if view._totalTabWidth > view.width then + error( "ERROR: " .. M._widgetName .. ": width passed is too small to fit the tab items inside, you need a width of at least " .. view._totalTabWidth .. " to fit your tab items inside", 3 ) end ------------------------------------------------------- diff --git a/widgetLibrary/widget_tableview.lua b/widgetLibrary/widget_tableview.lua index 359c581..3b4b5c7 100755 --- a/widgetLibrary/widget_tableview.lua +++ b/widgetLibrary/widget_tableview.lua @@ -565,6 +565,12 @@ local function createTableView( tableView, options ) -- EnterFrame listener for our tableView function view:enterFrame( event ) + + if not self.parent then + Runtime:removeEventListener( "enterFrame", self ) + return true + end + local _tableView = self.parent -- If we have finished rendering all rows @@ -1199,6 +1205,11 @@ local function createTableView( tableView, options ) -- Function to insert a row into a tableView function view:_insertRow( options, reRender ) + if not self.parent then + print("WARNING: trying to insert a row into a non-existant tableView") + return false + end + -- Create the row self._rows[table.maxn(self._rows) + 1] = {}