Native scroller: previous vScroll position

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
shoshinsha
Posts: 35
Joined: Fri Jul 18, 2014 5:17 am

Native scroller: previous vScroll position

Post by shoshinsha » Mon Jun 22, 2015 11:29 am

Hi All,

Does anyone know how to save the last vScroll position of a mobile scroller and display the vScroll bar position on the last position after the scroller is recreated?
I have a datagrid that will only show (for example) 10 records on the first time. When user clicks on the [Load More] button, the list will add up another 10 records below, which makes up 20 records, and so on.
Whenever more records are added into the datagrid, I will call the scroller_delete and scroller_create to recreate the scroller.
My problem is that even though the datagrid is able to display at the correct position, I can see that the vScroll bar will go back to the top of the datagrid contentRect (screencap: https://www.dropbox.com/s/k2xx8n6wzgw4y ... 0.png?dl=0). And when I tap on the mobile screen wanting to scroll down, the list will start from the top again!

Tried on scrolling list field, the result is the same. The scroller_create code is as follows:

Code: Select all

function scroller_create
   local tScrollerRect, tContentRect
   put the vScroll of fld "names" into tOldScroll
   if environment() is not "mobile" then exit scroller_create
   put the rect of grp "names" into tScrollerRect
   put 0, 0,(the formattedWidth of fld "names"),(the formattedHeight of fld "names") into tContentRect
   mobileControlCreate "scroller", "listScroll"
   put the result into sScrollerID
   
   mobileControlSet "listScroll", "rect", tScrollerRect
   mobileControlSet "listScroll", "contentRect", tContentRect
   mobileControlSet "listScroll", "visible", true
   mobileControlSet "listScroll", "scrollingEnabled", true
   mobileControlSet "listScroll", "vIndicator", true
   mobileControlSet "listScroll", "vScroll", tOldScroll
end scroller_create
Appreciate if anyone could help out on this :(
Thanks in advance!

zaxos
Posts: 222
Joined: Thu May 23, 2013 11:15 pm

Re: Native scroller: previous vScroll position

Post by zaxos » Mon Jun 22, 2015 1:26 pm

Maybe i'm missing something here but i dont see why you should delete and recreate the scrollbar after adding content, the scrollbar will update its length after you add content to the field plus the vScroll will remain as it is, simple example:

Code: Select all

on mouseUp
repeat 5
put "test"&return after fld 1
end repeat
set the vScroll of fld 1 to the vScroll of fld 1+1 -- to update the scrollBar
end mouseUp
Knowledge is meant to be shared.

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Native scroller: previous vScroll position

Post by SparkOut » Mon Jun 22, 2015 1:47 pm

Sorry zaxos, with a native scroller on android you do need to delete and recreate the scroller. A native scroller has a fixed scroll area.
See here http://forums.livecode.com/viewtopic.php?f=53&t=24258 and see if jacque's tip of setting the group scroll to 0 first works for you. It didn't quite solve my situation, but it did help a bit, although I solved my problem a different way.

shoshinsha
Posts: 35
Joined: Fri Jul 18, 2014 5:17 am

Re: Native scroller: previous vScroll position

Post by shoshinsha » Tue Jun 23, 2015 9:29 am

Hi SparkOut, thanks! :)
Setting the group vScroll to 0 doesn't really solve the problem, so I tried using your workaround, which is changing the blendLevel.
It works! But the scroller position will not change sometimes (like, 1 in 4 times).
I figured that changing the scroller offset (mobileControlSet sScrollerID, "vscroll", tScroll) after unlocking the screen would improve the result (so far the scroller position is able to be set every time).

Post Reply