widget.newScrollView strange behaviour

Could someone explain me why the scrollView behaviour is different when its content is populated whithin an event ?
Please look at my example below, you’ll see in the 2nd scrollView that you’re not able to scroll to the end, text is bouncing back to the top each time you’ll release your finger ! very strange
I’m using Solar2D 2022.3677 on win10, building android stuff.

local widget = require("widget")

display.setDefault("anchorX", 0)
display.setDefault("anchorY", 0)

local longText = string.rep("bla ", 100) .. "\nEND"

local scrollView1 = widget.newScrollView {
	left = 0,
	top = 100,
	width = display.contentWidth,
	height = 100 
}
local myText1 = display.newText("", 0, 0, scrollView1.width, 0, native.systemFont, 25)
myText1:setTextColor(0, 0, 255)
scrollView1:insert(myText1)
myText1.text = "Scroll IS working !!\n" .. longText

local scrollView2 = widget.newScrollView {
	left = 0,
	top = 300,
	width = display.contentWidth,
	height = 100 
}
local myText2 = display.newText("", 0, 0, scrollView1.width, 0, native.systemFont, 25)
myText2:setTextColor(255, 0, 0)
scrollView2:insert(myText2)

local function myEvent()
	myText2.text = "Scroll is NOT working !!\n" .. longText
end
timer.performWithDelay(10, myEvent)

My config.lua is :

application =
{
	content =
	{
		width = 320,
		height = 480,
		scale = "letterbox"
	},
}

Thanks for your help

We’ll keep it simple….

After inserting new content in the scrollVew, the scroll content area needs to be updated. This should probably be automatically done, but current is not.

The following is a fix for your code.

local function myEvent()
	myText2.text = "Scroll is NOT working !!\n" .. longText
	scrollView2:updateScrollAreaSize() -- new function added
end

The function “scrollView:updateScrollAreaSize()” is not in the documentation, and it doesn’t have an “internal” naming convention so maybe it should be added in the future. :slightly_smiling_face:

Thanks for you help !

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.