iOS native scroller not registering swipes
Posted: 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
______________________________
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
______________________________