iOS native scroller not registering swipes

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Fun days
Posts: 6
Joined: Sat Jul 11, 2020 11:15 pm

iOS native scroller not registering swipes

Post by Fun days » Sun Jul 12, 2020 1:33 am

I have implemented a native scroller to scroll a field of text lines (filenames).

I did manage to get it working fine, but something must have changed since it no longer works. I have no idea what changed since I didn't touch the scroller code before it stopped registering swipes (although I have tried many things with the code since then to get it to work, so it may no longer be the same as the one that worked).

Here is where I have come so far and what I have tested:

1) The mobilecontrol seems to create fine, and when I call getmobilecontrol to check values like rect and others, they all seem to be set right.

I don't think I need to set the scrollingEnabled option, but I did anyway and it returns as "true" when I call getmobilecontrol, so that is not the problem.

Group and field properties:
1) I set both the group and field properties as locked text and location, as is suggested for scrollers.
2) The other settings that are checked are
a) on group: visible, 3-D, focus with keyboard, focus content with keyboard
b) on field: visible, don't wrap, lock text, opaque, focus with keyboard, focus border, 3-D, show border, auto-hilite

I did try changing I think all of those properties (such as the field's "list behaviour" set to ON, among other properties) and so far it didn't seem to make any difference.

I thought maybe the "rect" property is the culprit, and while I am still not sure, I tried a few variations, but that did not seem to make any difference. It is not 100% clear to me from the dictionary whether the contentRect is relative to the top of the group or to the card, but either way it should still work and I set the top left of the contentRect to 0,0 like most of the examples I saw suggested.

I have confirmed (with answer commands to debug) that the card the scroller control is contained in is not receiving any messages like "scrollerBeginDrag" or "scrollerDidScroll" as it should.
So even if the "rect" or "contentRect" properties are not quite right, I would think the control should still send those messages if I drag in the general areas (which is most of the screen).

However, I am pretty sure the mobile control is not registering any swipes since I put a timer checking every 100 msec to see if mobileControlGet("myScroller", "dragging") has any "dragging"=true values and it never goes true when I start swipes.

I thought the problem might be layers since the "fileListField" is higher than the "scrollGroup" layer, but I could not seem to set to group layer to higher than the field it contains. Oddly, trying to do that seems to crash or freeze LiveCode, so I am not sure it is possible, and even if I could, I am not sure it will make any difference to the scrolling.

I do call the "setupScroller" subroutine from openCard rather than preOpenCard, but trying the latter did not seem to help, and the fileListField may change every time I open the card, so I need to reset the scroller settings, and the program does delete the control whenever the program leaves the card anyway.

I did see a forum post where a mouseUp handler on the field to be scrolled stopped it from scrolling. That seems like a potential liveCode bug, and raised my hope since I had added a mouseUp code to that field (to hilite the filename selected), but I believe the scroller was still scrolling even after I added that, and it doesn't seem to make any difference when I tried removing that handler and clear the field script entirely anyway.

So, I am at a loss as to what else to check, and still frustrated that I got it working easily and quickly and it continued fine for a day or so before it stopped scrolling, and I don't know what I could have changed to cause the problem, but I did change a few other things on the card and some other cards.

Below is my code. Any insights would be greatly appreciated!
____________________________________

on setUpScroller
if the environment is not "mobile" then exit setupScroller
local scrollerID, scrollerRect, fldRect, fldHeight, fldWidth

put max(formattedHeight of field "fileListField",height of group "scrollGroup") into fldHeight
set the height of field "fileListField" to fldHeight
put the rectangle of field "fileListField" into fldRect
put the rectangle of group "scrollGroup" into scrollerRect
#put the width of field "fileListField" into fldWidth
set the unboundedVScroll of group "scrollGroup" to true

mobileControlCreate "scroller","myScroller"
mobileControlSet "myScroller", "rect", scrollerRect
mobileControlSet "myScroller", "contentRect", "0,0," & fldWidth & "," & fldHeight
mobileControlSet "myScroller", "canBounce", true
mobileControlSet "myScroller", "decelerationRate", normal
mobileControlSet "myScroller", "scrollingEnabled", true
mobileControlSet "myScroller", "canScrollToTop", true
mobileControlSet "myScroller", "canCancelTouches", true
mobileControlSet "myScroller", "delayTouches", true
mobileControlSet "myScroller", "vIndicator", true
mobileControlSet "myScroller", "hIndicator", true
mobileControlSet "myScroller", "indicatorStyle", black
mobileControlSet "myScroller", "indicatorInsets", "0,0,5,0"
mobileControlSet "myScroller", "hscroll", 0
mobileControlSet "myScroller", "vscroll", 0
mobileControlSet "myScroller", "scrollingEnabled", true
end setUpScroller

on checkDragging
if mobileControlGet("myScroller", "dragging") then
answer "started swipe!"
else
put "." after fld "debugFileManagement"
end if
send "checkDragging" to me in 100 milliseconds
end checkDragging

on scrollerBeginDrag
set the hilitedLine of field "fileListField" to empty
end scrollerBeginDrag

on scrollerScrollToTop
mobileControlSet "myScroller", "vscroll", 0
end scrollerScrollToTop

on scrollerDidScroll hOffset, vOffset
set the vScroll of group "scrollGroup" to vOffset
#put vOffset into field "vscrollHolderField"
end scrollerDidScroll

on closeCard
if the environment is "mobile" then mobileControlDelete "myScroller"
end closeCard
______________________________
Last edited by Fun days on Sun Jul 12, 2020 4:34 pm, edited 4 times in total.

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: iOS native scroller not registering swipes

Post by Mikey » Sun Jul 12, 2020 3:12 pm

i have not read through your code to look for anything else, but when weird things happen on mobile, in my experience the first thing to check is to see if the script silently failed.
unfortunately, on mobile, when there is a script error, the script just stops and fails silently.
so you can use the mobile debugger to step through your code, or, you can embed some answer dialogs in various places to tell you what has achieved, e.g. at the end of handlers. answer "done with <insert event name here>"
in your case, the last line of setupscroller, checkdragging, and even opencard can have one of these answer dialogs.

Fun days
Posts: 6
Joined: Sat Jul 11, 2020 11:15 pm

Re: iOS native scroller not registering swipes

Post by Fun days » Sun Jul 12, 2020 3:53 pm

Thanks Mikey. I am aware of that non-optimal debugging behaviour on iOS, and I have indeed confirmed that the code works with answer dialogues and variables posted into a debug field. For example, the setupScroller subroutine completes fine and all the values are loaded into the scroller settings, and the little periods (".") keep printing as my built-in code timer "checkDragging" continually checks the scroller control's "dragging" value to see if it changed (but it does not change when I try dragging).

It is a great suggestion and I appreciate it, but from what I can tell, the script silently exiting is not the problem, although I have had that problem plenty at other times!

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

Re: iOS native scroller not registering swipes

Post by jacque » Sun Jul 12, 2020 10:28 pm

This is a long-standing issue: https://quality.livecode.com/show_bug.cgi?id=21836. It must be difficult to fix because the PR isn't done yet.

And this list discussion: https://www.mail-archive.com/use-liveco ... 05721.html

And finally, this discussion which has some working suggestions: https://www.mail-archive.com/use-liveco ... 08052.html

What we ended up doing is making the contentRect wider than the scroller rect so that when the user swipes, you get a scrollerDidScroll message. You can use that to detect swipes. For iOS you need to set the lockDirection so the content doesn't jiggle sideways during a swipe. You can remove the "drag" handlers, they don't work.

If you will also build for Android, you need to branch the code since Android doesn't support lockDirection, and also doesn't have the problem anyway. You can track the mouseLoc on mouseDown and mouseUp accurately on Android native scrollers (at least, you can now. For a long time that was broken too, so be sure you're using the lastest LC.)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Fun days
Posts: 6
Joined: Sat Jul 11, 2020 11:15 pm

Re: iOS native scroller not registering swipes

Post by Fun days » Sun Jul 12, 2020 11:21 pm

Thanks Jacque, that is good to know and helpful.

However, I only need to scroll vertically (at this point) and not register horizontal swipes (my bad for confusing/incorrect terminology), so it would be good to know if the vertical scrolling is normally working as it did fine for me for a day or so before it stopped.

It strikes me that if making the scroller group wider than the field seems to allow a potential makeshift solution, I would think being able to have the group on a higher layer than the field would completely solve the problem, and from my (sometimes poor) memory I think that is how I first set it up and got it working for a day though now I cannot seem to have the scroll group layer anything but lower than the field layer.

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

Re: iOS native scroller not registering swipes

Post by jacque » Mon Jul 13, 2020 12:31 am

I see, I misunderstood.

The controls in a group are always a higher layer than the group itself, that's normal. One reason I've found when a scroller does nothing is that it hasn't been synced with the scroll of the group when it was created. I've needed to set the scroll of the group to 0 before creating the scroller. If it's anything else, the native scroller is misaligned. Also, you need to be sure the formattedHeight of the group includes the entire height of the field text.
  • Set the rect of the group to the display size you want.
  • Set the height of the field to the formattedHeight of the field.
  • Set the scroll of the group to zero.
  • Set the top of the field to the top of the group. The field will hang down below the group but you won't see it visually.
  • Create the native scroller.The contentRect should be as wide as the group and the height should be the formattedHeight of the group.
If the field content never changes, you only need to do the steps once during development (except for the scroller creation.) If the field text does change, do it all each time in a handler.

I also usually check to see if the field's formattedHeight will fit in the group, and if it does I don't bother making a native scroller. But that's just me.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Fun days
Posts: 6
Joined: Sat Jul 11, 2020 11:15 pm

Re: iOS native scroller not registering swipes

Post by Fun days » Mon Jul 13, 2020 2:26 am

Thanks so much Jacque for all the clarifications!

Unfortunately, none of those things were the problem, but it inspired me to try more things and I found out what was wrong with me code.

The problem is that there were not enough files in the list field for it to exceed the scroll group height. No messages are sent while the contentRect is smaller (or I think equal to) the scroller group rect height, which I guess makes sense, but I am not sure the scroller even gets created in such cases.

Anyways, problem solved. Thanks again. Maybe this can help someone else in the future, and it is good to know about sideways swipes having potential problems.

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

Re: iOS native scroller not registering swipes

Post by jacque » Mon Jul 13, 2020 9:30 pm

I am not sure the scroller even gets created in such cases.
I'm pretty sure it's created, but since there isn't enough content to scroll, nothing happens. I'd continue to delete the scroller when the card closes.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “iOS Deployment”