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: 5658
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: 5658
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

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 609
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: Swiping with native scroller?

Post by marksmithhfx » Thu Aug 06, 2020 2:29 pm

Jim/Jacque, thanks for the suggestions. I’m sure it will be a great “leg up” when I get to that part of the project. Still working on some other components at the moment, but hope to get to this issue in a week or so. I’ll keep you posted.

Mark
macOS 10.15.7, Xcode 11.5, LC 9.6.1, iOS 13.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 609
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: Swiping with native scroller?

Post by marksmithhfx » Thu Sep 17, 2020 3:00 pm

jacque wrote:
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.
Thanks Jacque, this definitely got me started in the right direction (stack attached). I'll have to fool around with this as sometimes it is very easy to trip an "isSwipe" message (all code in row behaviour script) and sometimes really difficult. Not sure what the correct "formula" is yet to get this to behave like swipes on other scrolling objects (for example mail messages in Apple mail, or the iReminders app). If I move my finger over the row in a very deliberate sort of fashion, then when I lift my finger I can trigger an iSwipe message. But really you want the control to respond sooner in the process and in fact to stay in "swipe mode" while your finger is just moving back and forth on it.

No use crying over spilled milk, but I am a bit disappointed. I thought this had all been resolved in the DG2 project (which many of us heavily funded), but apparently not.

Onward. Thanks for sharing your code example... saved me hours of time hunting down all of the relevant information.

Also, I suspect the documentation in LC needs updating. It still says things like:
When enable swipe is set to true, users can drag and swipe rows of form style data grids left and right, gradually revealing controls at either side of the row. The default appearance of the revealed controls and the behavior of the swipe actions can be customized.
At present, I would say that sounds a little aspirational.

Cheers,
Mark
Attachments
test swipe1.livecode.zip
(8.33 KiB) Downloaded 18 times
macOS 10.15.7, Xcode 11.5, LC 9.6.1, iOS 13.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 609
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: Swiping with native scroller?

Post by marksmithhfx » Fri Sep 18, 2020 9:40 am

Jacque,

Don't know if I should leave my previous message up or take it down. Probably leave it up for now, and take it down in a bit. All the documentation for the new swipe actions in DG2 is in Michael McCreary's 2019 LC San Jose presentation. I've just been listening to that and it looks like there are some good possibilities. I don't have time to explore in much detail at the moment, since I have back to back appointments for the next 2 hours but I'm encouraged.

Will post further when I have more time to play.

M
macOS 10.15.7, Xcode 11.5, LC 9.6.1, iOS 13.6.1
Targets: Mac, iOS

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

Re: Swiping with native scroller?

Post by jacque » Fri Sep 18, 2020 5:51 pm

I was going to mention that I saw it demoed at the conference but I haven't needed to use it yet. My sample script may not be applicable to a datagrid, but I remember Mark saying that the new behavior was implemented specifically to support those.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 609
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: Swiping with native scroller?

Post by marksmithhfx » Sat Sep 19, 2020 11:46 am

I saw the same. But I was a bit puzzled because he demoes swipes and the new Edit Mode (which allows re-ordering rows and has a little button thing on the left you can click to initiate a swipe) but I wasn't able to get swipes to work. So I downloaded his stack (I've slightly re-organized it to fit an iPhone 6) and discovered something "undocumented". It looks like you can have one or the other but not both at once. I was using Edit Mode in my DG all the time so when I tried swipes it didn't work. When I tried this in his stack I found the same thing. So I turned off Edit Mode and swipes started working. Turned it back on (buttons on the card) and it stopped working again. So I think that was my stumbling block... I just didn't realize you couldn't have both at once. This is all under programmable control so it's possible (and his stack demonstrates it) to have swipes and Edit Mode (I use it just for re-ordering so I disabled the little icon on the left of the screen) in the same DG, just not at the same time. Sheesh, took me at least 2 days to figure this out.

I'll make a "bug" report that documentation needs updating to reflect this so it doesn't take someone else 2 days to figure out. I've attached the stack. With just 1 line of code (set the dgProp("enable swipe") of group "Datagrid" to true) you get some pretty fancy swipe action (left and right). And in the demo stack turning edit mode on (another 1 liner) you get some pretty fancy row re-ordering). Very impressive.

Mark
Attachments
DG2 Sample.livecode.zip
(14.05 KiB) Downloaded 19 times
macOS 10.15.7, Xcode 11.5, LC 9.6.1, iOS 13.6.1
Targets: Mac, iOS

Post Reply

Return to “iOS Deployment”