Page 1 of 1
Scrolling from a remembered vScroll position on mobile
Posted: Mon Mar 08, 2021 9:24 pm
by glenn9
Hi Everyone,
on desktop I can return to a scrolling list field at the same scroll position that I left it by noting the vScroll of the scrolling list field using the following code:
Code: Select all
-- when leaving the field the vScroll position is put into tScrollPosition
put the vScroll of field"display" into tScrollPosition
-- and returning to that vScroll position by the code in the 'go back' handler
set the vScroll of field "display" to tScrollPosition
and (importantly) the user can then scroll up and down from this vScroll position as needed.
I thought that this would also work in the same way on mobile but hadn't appreciated that although the user returns to the vScroll position, as soon as the mobile user starts to scroll, the tScrollPosition is replaced by the pVScroll of scrollerDidScroll (see below) and the field starts to scroll from the top rather than the returned to vScroll position!
Code: Select all
on scrollerDidScroll pHScroll, pVScroll
set the vScroll of field "display" to pVScroll
end scrollerDidScroll
I was therefore wondering if anyone knew of a way for a user on mobile to scroll from the remembered vScroll position, rather from the top each time??
Hope this makes sense!
Many thanks,
Kind regards,
Glenn
Re: Scrolling from a remembered vScroll position on mobile
Posted: Mon Mar 08, 2021 10:13 pm
by SparkOut
I'm not sure if I have got your process correctly, but I think what you should be doing is noting the scroll position and resetting the scroll positions of the field and native scroller to 0 when "offscreen" then they will be in sync when you reset the scroll positions.
Re: Scrolling from a remembered vScroll position on mobile
Posted: Tue Mar 09, 2021 8:50 am
by glenn9
Hi SparkOut,
Thanks for the reply.
Not sure I understand how to set the native scroller to 0, could you show me an example?
The code of my native scroller at the moment looks like this:
Code: Select all
on opencard
if the environment is "mobile" then
mobileControlCreate "scroller" , "AndroidScroll"
mobileControlSet "AndroidScroll", "visible", true
mobileControlSet "AndroidScroll", "rect", the rect of field"display"
put 0,0, the width of field"display", the formattedHeight of field"display" into tContentRect
mobileControlSet "AndroidScroll", "contentRect", tContentRect
mobileControlSet "AndroidScroll", "vIndicator", true
set the vScrollbar of field"display" to false
end if
end opencard
on scrollerDidScroll pHScroll, pVScroll
if the environment is "mobile" then
set the vScroll of field "display" to pVScroll
end if
end scrollerDidScroll
Re: Scrolling from a remembered vScroll position on mobile
Posted: Tue Mar 09, 2021 12:57 pm
by bogs
glenn9 wrote: ↑Tue Mar 09, 2021 8:50 am
Not sure I understand how to set the native scroller to 0, could you show me an example?
I'm not SparkOut, and I don't work with mobile, but doesn't -
Code: Select all
set the scroll of field "yourField" to 0
work on mobile? It works on desktop that way.
Re: Scrolling from a remembered vScroll position on mobile
Posted: Tue Mar 09, 2021 2:09 pm
by glenn9
Thanks Bogs, I'll give that a try. Regards, Glenn
Re: Scrolling from a remembered vScroll position on mobile
Posted: Tue Mar 09, 2021 3:00 pm
by SparkOut
That will set the vscroll of the LC field, but to sync the native scroller you need to
Code: Select all
mobileControlSet tScrollerId, "vscroll", tVscroll
(use appropriate variables/values, of course).
If the content area changes, then you would also need to delete and recreate the native scroller to match the new underlying content area.
Re: Scrolling from a remembered vScroll position on mobile
Posted: Tue Mar 09, 2021 6:33 pm
by jacque
It's a bug. The workaround is here:
https://quality.livecode.com/show_bug.cgi?id=22453
Note that when creating a native scroller it's important to set the LC field scroll to 0 first. Otherwise the contentRect isn't calculated properly.
Re: Scrolling from a remembered vScroll position on mobile
Posted: Wed Mar 10, 2021 8:32 am
by glenn9
Thank you so much for highlighting this Jacque, have just implemented the workaround and the Android scrolling now works perfectly.
Kind regards,
Glenn
Re: Scrolling from a remembered vScroll position on mobile
Posted: Sun Mar 03, 2024 4:10 pm
by okk
Hi, in case someone stumbles upon this issue: I just noticed that the suggested workaround didn't work for me when I had
Code: Select all
set the acceleratedRendering of this stack to true
... still trying to master the mobile scroller...
Best,
Oliver
Re: Scrolling from a remembered vScroll position on mobile
Posted: Mon Mar 04, 2024 6:44 pm
by jacque
Here's an explanation:
https://lessons.livecode.com/m/4069/l/9 ... ll-a-field
Setting the enclosing group's layermode to "scrolling" will allow it to work with acceleratedRendering.