0

Charles B posted an interesting alternative to the native scroller in Android using LiveCode. His code may be found here: Scrolling in iphone and android devices in LiveCode (and I'll reproduce his code at the bottom of this post)

It really does work; however, there is no inertia. In other words, when you remove your finger, the scrolling stops dead in its tracks. I'm wondering if an alteration to his code might provide some inertial scrolling - perhaps some sort of timer added to the mouseRelease or mouseUp handlers?

While I know this is not the official method provided by LiveCode (it's not a "native" scroller), it's certainly a snap to implement and, in fact, is the first example code that actually worked for me in terms of scrolling all the way to the end of my provided text. If I could add inertial scrolling, it would be awesome.

Thanks,

Barry

local allowMove

on mouseDown
   put mouseH(),mouseV() into allowMove
end mouseDown

on mouseMove X,Y
   if allowMove is not empty then
      lock screen
      if the hScrollbar of me then
         set the hScroll of me to the hScroll of me + (item 1 of allowMove-X)
      end if
      if the vScrollbar of me then
         set the vScroll of me to the vScroll of me + (item 2 of allowMove-Y)
      end if
      put X into item 1 of allowMove
      put Y into item 2 of allowMove
      unlock screen
   end if
end mouseMove

on mouseUp
  put empty into allowMove
end mouseUp

on mouseRelease
  mouseUp
end mouseRelease
Linus Juhlin
  • 1,175
  • 10
  • 31

1 Answers1

0

An inertia type effect can be achieve with some repeat loops in the mouseUp handler.

local allowMove, sScrollPos

on mouseDown
   put mouseH(),mouseV() into allowMove
   put the vScroll of me into sScrollPos
end mouseDown

on mouseMove X,Y
   if allowMove is not empty then
      lock screen
      if the hScrollbar of me then
            set the hScroll of me to the hScroll of me + (item 1 of allowMove-X)
      end if
      if the vScrollbar of me then
            set the vScroll of me to the vScroll of me + (item 2 of allowMove-Y)
      end if
      put X into item 1 of allowMove
      put Y into item 2 of allowMove
      unlock screen
   end if
end mouseMove

on mouseUp

   put the vScroll of me into tVscroll

   if tVscroll > sScrollPos then
      put "down"
      repeat with x = 1 to 20
         set the vScroll of me to the vScroll of me + (20-x)
         end repeat
   end if
     if tVscroll < sScrollPos then
        put "up"
        repeat with x = 1 to 20
         set the vScroll of me to the vScroll of me - (20-x)
         end repeat
   end if
      if tVscroll = sScrollPos then
      put "same"
   end if

    put empty into allowMove
end mouseUp

on mouseRelease
  mouseUp
end mouseRelease

Basically on the mouseUp, the vScroll of a field is being set to its vScorll +/- an ever decreasing valued defined in the various repeat loops.. I have also added a little bit of debugging that tells you if the scroll is up, down or stays the same.

The values in the repeat loop can be changed to give a more/less dramatic inertia effect

Neil Roger
  • 681
  • 3
  • 6