I am experimenting with scrollView and a springboard file I got from the code exchange and after some changes the scrollView:getContentPosition() just doesn’t work anymore.
Here’s the code, but I honestly don’t think it’s going to help. I’m posting the whole thing because I have no idea where to start with this.
module(..., package.seeall) local widget = require( "widget" ) local math\_abs = math.abs local math\_floor = math.floor local system\_getTimer = system.getTimer local springboard = { } local springboard\_mt = { \_\_index = springboard } function springboard.new(group, pageWidth, pageHeight, pages, onScrollComplete, params) local touchTime, scrollView local obj = {pageWidth=pageWidth, pageHeight=pageHeight, pages=pages, page=1, onScrollComplete=onScrollComplete} obj.backgroundColor=(params and params.backgroundColor) or nil obj.time=(params and params.time) or nil local function scrollListener(event) local phase = event.phase if phase == "began" then touchTime = event.time elseif phase == "moved" and not touchTime then -- no began phase when focus is explicetly transferred to springboard with takeFocus touchTime = event.time elseif phase == "ended" or phase == "off" or phase == "cancelled" then touchTime = touchTime or system\_getTimer() local motionTime = system\_getTimer() - touchTime local dist = event.xStart - event.x local swipeDist = math\_abs(dist) local nextPage -- calculate next page index (negative or 0) if (motionTime \<= 300 and swipeDist \>= 30) then -- fast page flip nextPage = obj.page + dist/swipeDist else -- slow controlled drag local vx, vy = scrollView:getContentPosition() nextPage = math\_floor(-vx/pageWidth) + ((-vx%pageWidth \> 0.5\*pageWidth and 1) or 0) + 1 end -- move to page if nextPage \>= 1 and nextPage \<= pages then -- snap to next page scrollView:scrollToPosition({x=-(nextPage-1)\*pageWidth, onComplete=onScrollComplete, time=obj.time}) obj.page = nextPage else -- out of bounds snap quick because fuck out of bounds scrollView:scrollToPosition({x=-(obj.page-1)\*pageWidth, onComplete=onScrollComplete, time=50}) end end return true end scrollView = widget.newScrollView { top = 0, left = 0, width = pageWidth, height = pageHeight, scrollWidth = pageWidth \* pages, scrollHeight = pageHeight, listener = scrollListener, backgroundColor = obj.backgroundColor, hideBackground = not obj.backgroundColor, verticalScrollDisabled = true, hideScrollBar = true, } group:insert(scrollView) obj.view = scrollView return setmetatable(obj, springboard\_mt) end function springboard:goToPage(page, time) local options = {x = -(page-1)\*self.pageWidth, onComplete = self.onScrollComplete, time=(time or self.time)} self.view:scrollToPosition(options) self.page = page end return springboard
I don’t care about the y value, I just need x. It updates just fine from 0 to -443 but it just freezes at -444. The actual scrollView is still scrolling when it freezes at -444, it just doesn’t update the value.
I hope I explained this well, it really is a weird problem.