No X Value When Using object:getContentPosition() And An Object Is Included Into The Scrollview

Environment:

  • newest Public Build: Version 2015.2646 (2015.5.27)
  • newest Daily Build 2015.2693

My Code:

local widget = require( “widget” )

local scrollView

– ScrollView listener

local function scrollListener( event )

    local phase = event.phase

    if ( phase == “began” ) then print( “Scroll view was touched” )

    elseif ( phase == “moved” ) then print( “Scroll view was moved” )

    

    local x, y = event.target:getContentPosition()

    print ("X : " … x … "  " … " Y : " … y)

    

    

    

    elseif ( phase == “ended” ) then print( “Scroll view was released” )

    end

    – In the event a scroll limit is reached…

    if ( event.limitReached ) then

        if ( event.direction == “up” ) then print( “Reached top limit” )

        elseif ( event.direction == “down” ) then print( “Reached bottom limit” )

        elseif ( event.direction == “left” ) then print( “Reached left limit” )

        elseif ( event.direction == “right” ) then print( “Reached right limit” )

        end

    end

    return true

end

– Create the widget

scrollView = widget.newScrollView

{

    top = 100,

    left = 10,

    width = 300,

    height = 400,

    scrollWidth = 800,

    scrollHeight = 800,

    listener = scrollListener

}

local myRectangle = display.newRect( 200, 200, 150, 50 )

myRectangle:setFillColor( 0.5 )

scrollView:insert(myRectangle)

The Issue:

_ When I remove this code: _

local myRectangle = display.newRect( 200, 200, 150, 50 )

myRectangle:setFillColor( 0.5 )

scrollView:insert(myRectangle)

I get an X and Y from this line (although it is still weird; i.e. Y/X never go Negative):

local x, y = event.target:getContentPosition()

    print ("X : " … x … "  " … " Y : " … y)

_ When I keep this code: _

local myRectangle = display.newRect( 200, 200, 150, 50 )

myRectangle:setFillColor( 0.5 )

scrollView:insert(myRectangle)

_ I get the same Y value, but X prints out to 0 no matter what I do. _

local x, y = event.target:getContentPosition()

    print ("X : " … x … "  " … " Y : " … y)

This code is part of a larger project and larger code base. We pushed an app almost a year ago that is time sensitive and needs to be update. As of right now I was seeing the bug in my previous code and could not figure it out so I decided to make a more simple app to test (this code). I am seeing the same issue. Basically I see no reason why the X of this: local x, y = event.target:getContentPosition() should ever be 0.

This is pretty critical and I could use some advice ASAP or figure out that it is a known bug. 

Thanks,

Hi @beesh,

In my testing, this appears to be a regression bug. It works in older builds but not in the current official build.

I filed a bug report for this, so hopefully it will be fixed soon. Case is #42223 if you’d like to check up on it.

Thanks,

Brent

@Brent Sorrentino Can you point me in the direction of a build I can go live with and push to the app stores that works? This is a core feature of an app we pushed last year that is going to be used by about 30,000 people next week and as of right now I cannot find a way to update the product in the app store. Kind of screwed on this. I need to get this thing in ASAP. The event is in San Francisco.

Hi @beesh,

The bug may not be resolved by next week, so in the meantime, consider the following code which (should) do effectively the same thing. It simply stores the “starting X position” on the “began” phase and then calculates its “delta X” during the “moved” phase. I think this is what you’re looking for, and it should be simple to implement in your app in the meantime.

[lua]

local currentX = 0

local function scrollListener( event )

   if event.phase == “began” then

      currentX = event.x

      --print(currentX)

   elseif event.phase == “moved” then

      --local cx, cy = event.target:getContentPosition()

      --print( “X VALUES (event.x, content X)”, event.x, cx )

      --print( “Y VALUES (event.y, content Y)”, event.y, cy )

      print(event.x - currentX)

   end

end

[/lua]

Brent

Let me try it ASAP and get right back to you. Thanks

This worked. Thanks Brett!

Hi @beesh,

In my testing, this appears to be a regression bug. It works in older builds but not in the current official build.

I filed a bug report for this, so hopefully it will be fixed soon. Case is #42223 if you’d like to check up on it.

Thanks,

Brent

@Brent Sorrentino Can you point me in the direction of a build I can go live with and push to the app stores that works? This is a core feature of an app we pushed last year that is going to be used by about 30,000 people next week and as of right now I cannot find a way to update the product in the app store. Kind of screwed on this. I need to get this thing in ASAP. The event is in San Francisco.

Hi @beesh,

The bug may not be resolved by next week, so in the meantime, consider the following code which (should) do effectively the same thing. It simply stores the “starting X position” on the “began” phase and then calculates its “delta X” during the “moved” phase. I think this is what you’re looking for, and it should be simple to implement in your app in the meantime.

[lua]

local currentX = 0

local function scrollListener( event )

   if event.phase == “began” then

      currentX = event.x

      --print(currentX)

   elseif event.phase == “moved” then

      --local cx, cy = event.target:getContentPosition()

      --print( “X VALUES (event.x, content X)”, event.x, cx )

      --print( “Y VALUES (event.y, content Y)”, event.y, cy )

      print(event.x - currentX)

   end

end

[/lua]

Brent

Let me try it ASAP and get right back to you. Thanks

This worked. Thanks Brett!