Scrolling from a remembered vScroll position on mobile

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
glenn9
Posts: 223
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Scrolling from a remembered vScroll position on mobile

Post by glenn9 » Mon Mar 08, 2021 9:24 pm

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

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

Re: Scrolling from a remembered vScroll position on mobile

Post by SparkOut » Mon Mar 08, 2021 10:13 pm

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.

glenn9
Posts: 223
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Re: Scrolling from a remembered vScroll position on mobile

Post by glenn9 » Tue Mar 09, 2021 8:50 am

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

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Scrolling from a remembered vScroll position on mobile

Post by bogs » Tue Mar 09, 2021 12:57 pm

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.
Image

glenn9
Posts: 223
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Re: Scrolling from a remembered vScroll position on mobile

Post by glenn9 » Tue Mar 09, 2021 2:09 pm

Thanks Bogs, I'll give that a try. Regards, Glenn

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

Re: Scrolling from a remembered vScroll position on mobile

Post by SparkOut » Tue Mar 09, 2021 3:00 pm

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.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7238
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Scrolling from a remembered vScroll position on mobile

Post by jacque » Tue Mar 09, 2021 6:33 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

glenn9
Posts: 223
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Re: Scrolling from a remembered vScroll position on mobile

Post by glenn9 » Wed Mar 10, 2021 8:32 am

jacque wrote:
Tue Mar 09, 2021 6:33 pm
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.
Thank you so much for highlighting this Jacque, have just implemented the workaround and the Android scrolling now works perfectly.

Kind regards,

Glenn

okk
Posts: 176
Joined: Wed Feb 04, 2015 11:37 am

Re: Scrolling from a remembered vScroll position on mobile

Post by okk » Sun Mar 03, 2024 4:10 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7238
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Scrolling from a remembered vScroll position on mobile

Post by jacque » Mon Mar 04, 2024 6:44 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”