Swiping with native scroller?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

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

Re: Swiping with native scroller?

Post by jacque » Thu Jul 30, 2020 6:14 pm

There were fixes to another bug that largely solved the problem for me.
https://quality.livecode.com/show_bug.cgi?id=12419
Most of the info you need is farther down the report on February 7 of last year when it was finally addressed. For iOS you need to set a couple of scroller properties correctly, for Android the missing messages are now sent.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Jim Mac
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 32
Joined: Wed Jun 28, 2006 9:22 pm

Re: Swiping with native scroller?

Post by Jim Mac » Thu Jul 30, 2020 8:19 pm

marksmithhfx wrote:
Thu Jul 30, 2020 2:43 pm
Hi Jim, I'm going down the same path. Is it possible to post an example of your solution?

Thanks
Mark
Here's what I use... so simple as to be embarrassing.
In card script so I don't accidentally have swiping when not wanted on card.
As I said, people seem to figure out you can't swipe on another object (scroller).. a little swearing till they figure it out then good....
Make sure user can actually access card... no blocking fields, etc.
Need 50+ pixels to get a swipe. Could change.

NOTE: Seems only scrollers don't react to this approach. I use same script in graphics and groups to trigger other behaviors...

############################
## Touch data
##############################
local lStart,lFinish

########################
## TOUCH BASED SWIPE ###
########################
on touchStart theID -- Initiate the swipe
put empty into lStart
put empty into lFinish
end touchStart

on touchMove theID, pH -- Capture start and end points
if lStart is empty then
put pH into lStart
else
put pH into lFinish
end if
end touchMove

on touchEnd theID
-- The next line is included if you want to do something depending on which card you're on (e.g. go Home if o the first of a series of cards)
put word -1 of the short name of me into tWhichIntro
if lStart is not empty and sFinish is not empty then
if lStart > lFinish and abs(lStart - lFinish) > 50 then -- A real swipe..... swipe left, go next card
visual effect push left very fast
go next cd
else if lStart < lFinish and abs(lStart - lFinish) > 50 then -- A real swipe..... swipe right, go preview card
visual effect push right very fast
go prev cd
end if

end if
put empty into lStart
put empty into lFinish
-- mobileClearTouches Included this but never have had trouble with too many swipes in queue. Still good idea?
end touchEnd

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

Re: Swiping with native scroller?

Post by jacque » Sat Aug 01, 2020 8:32 pm

Here is one of my standard scroller behavior scripts. I assign it to any group that will have a native scroller. I've edited out app-specific commands but hopefully the skeleton code is correct.

Code: Select all

-- the behavior for any group that should be scrollable.
-- The target must have a "doScrollerTap" handler to catch user taps.

local sStartLoc

on mouseDown
  put the mouseloc into sStartLoc
end mouseDown

on mouseUp
  if abs(the mouseH - item 1 of sStartLoc) <= 10 and abs(the mouseV - item 2 of sStartLoc) <= 10 then -- a tap
    send "doScrollerTap" to the target
  else
    if isSwipe(sStartLoc) then
      doSwipe sStartLoc -- navigate
    end if
  end if
end  mouseup

on mouseRelease
  put "" into sStartLoc
end mouseRelease
I use mouse messages rather than touch messages because touch is only required for pinch-zoom and you always get both touch and mouse messages on mobile. Using mouse messages avoids duplication and allows me to test some things on desktop (handlers not included here.)

This goes into the card or stack script, or wherever you need to manage a swipe:

Code: Select all

on doSwipe pStartLoc -- navigate
  -- called from scrollerBehavior
  put the mouseH into x
  if item 1 of pStartLoc > x then -- swipe forward (right to left)
    -- handle forward swipes
  else if item 1 of pStartLoc < x then -- swipe back (left to right)
    -- handle back swipes
  end if
end doSwipe
This script requires that the target has a "doScrollerTap" handler to manage user taps. If your scroller doesn't need to respond to taps you can omit that.

Edit: I forgot to include this:

Code: Select all

function isSwipe pStartLoc -- calculate if a gesture is a swipe
  -- called from scrollerBehavior
  -- pStartLoc = initial mouseloc at mouseDown
  put abs(the mouseH - item 1 of pStartLoc) into tHDist
  put abs(the mouseV - item 2 of pStartLoc) into tVDist
  return tHDist > (tVDist + 15) -- swipe must be more than 15 px
end isSwipe
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “iOS Deployment”