Front and Back Scripts on Mobile
Richard Gaskin
ambassador at fourthworld.com
Mon Jul 4 10:32:26 EDT 2016
Sannyasin Brahmanathaswami wrote:
> @Richard:
>
> Thanks… confirmed… today it is working, yesterday it was not… go
> figure. create scroller and scrollerdidscroll now in our backscript.
> awesome!
Once I got the hang of it I've been pretty pleased with LC's scroller
handling. And fortunately it seems the Dict entry does a fair job of
describing where the message goes:
The scrollerDidScroll message is sent to the object containing
the script that created the scroller control.
> "Instead, a backscript scans controls during preOpenCard and anything
> that needs a scroller gets one instantiated for it (along the way it
> also turns off scrollbars, since of course those are only useful on
> desktop)."
>
> how does your scan "know" that a scroller is needed or not?
On the desktop, a scrollable object is distinguished by having scrollbars.
On mobile, of course, we don't want the scrollbars shown since that's
not how mobile scrolling interaction works there. But development
occurs on the desktop, so having scrollbars lets me work with the
objects in a way that makes sense in that environment, AND it provides a
flag to let my backscript know which objects will need a scroller
interaction overlay when run on mobile devices.
My backscript walks through all fields and groups on preOpenCard when
running on a mobile OS. When it finds an unlocked field it instantiates
a mobile-native editable field, and when it finds a locked field it
checks if it has scrollbars, and if so instantiates a scroller overlay.
Similarly, when it find a group with scrollbars it also instantiates a
scroller overlay.
> And since I would prefer not to have scrollbars even on desktop…
> I am putting this in to the [field | group] (see below)
If that's working for you then who am I to suggest otherwise? But for
my own projects I try to meet user expectations of how interactions
work, and the LC team has done a good job of providing nice scrolling
behaviors on desktop and mobile.
The scrollBars in LC continue to impress me with the fluidity of their
messaging, and on mobile the OS-native overlay is really the only way to
deliver an experience that meets user expectations, smoothly responding
to touch-and-drag operations and nicely supporting whatever
end-of-scroll behavior the OS provides (the momentary translucent flash
on Android or Apple's patented bounce-back on iOS*).
One of the great things about LC is that it lets us craft nearly any UI
we want. But when it comes to the basics with things like scrolling,
I'm happy to adhere to OS conventions, with extra bonus points that LC
generally makes that the easiest thing to do.
As for generalizing your script, probably the simplest way would be to
move the script to a button or stack and assign it to fields that use it
as a behavior. With that one move it should continue to work for all
fields that need it without modification.
> local sMouseLoc, sStartLoc,
>
> on mouseDown
> put the mouseloc into sMouseLoc
> put sMouseLoc into sStartLoc
> if not isMobile() then setScroll
> end if
> end mouseDown
>
> on setScroll
> if the mouse is down then
> lock screen
> if item 2 of sMouseLoc > the mouseV then
> set the vscroll of me to the vscroll of me - (the mouseV - item 2 of
sMouseLoc)
> else
> set the vscroll of me to the vscroll of me + (item 2 of sMouseLoc -
the mouseV)
> end if
> put the mouseloc into sMouseLoc
> send "setScroll" to me in 20 millisec
> unlock screen
> else
> put empty into sMouseLoc
> end if
> end setScroll
* Note for devs making custom UIs: be very careful when using
bounce-back as an end-of-scroll indicator. On iOS you're probably fine,
but in a few jurisdictions Apple's design patent on that has been
upheld. I'm obliged to note that I'm not an attorney; if you want to
implement custom bounce-back it may be prudent to consult with an
attorney licensed to practice in your area.
--
Richard Gaskin
Fourth World Systems
Software Design and Development for the Desktop, Mobile, and the Web
____________________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the use-livecode
mailing list