Page 1 of 1

Sometimes get white space at top of mobile scroller

Posted: Fri Apr 22, 2016 12:54 am
by KimD
I've got a help card, accessible from the main screen of my app. The contents of this help card is:
A header block
A group "scrollingText", containing
- A group "Info", containing
-- some text (field "feedback1")
-- an image (Image "MainScreen_Features_Reduced.PNG")
-- some more text (field "feedback2")
-- yet more text (field "feedback3")

This content is too big for a single card, so everything except for the header block vertically scrolls.

I've got this scroll working 80% of the time ;-)
- from my main card I hit the help button
- the help card comes up, with my field "feedback 1" showing nicely below my header block and the image positioned perfectly underneath it.
- I vertically scroll, and my three fields and one image scroll nicely, exactly as I would have expected.

20% of the time
- from my main card I hit the help button
- the help card comes up, with my field "feedback 1" showing nicely below my header block and the image positioned perfectly underneath it.
- I vertically scroll, and a seemingly random amount of white space (it changes each time) is suddenly inserted above field "feedback 1"; then the random white space, my three fields and one image all scroll together; but
- the lower portion of my scrolling content becomes unavailable (I lose the same amount of content as the amount of "random" white space that has appeared.

What has me stumped is that I'm not changing anything between good and bad scrolls. If I get on my app, and ONLY toogle back and forward between the main card and help card, then 80% of the time I get a successful scroll on the help card and 20% of the time I get the random white space inserted problem. Despite the fact that the same code is running each time I enter and exit the help card! I haven't yet encountered a bad scroll the first time (after I open the app) that I enter the help card. Once I do start getting bad scrolls, they seem to appear increasingly more often. It feels like something "bad" is accumulating within the help card each time that I open it. Having bad things accumulate in your help card just isn't ... helpful.

Going a little nuts over here ;-)

Thanks in advance for any help

==============================================================

On PreOpenCard
ResizeStack the width of this card, the height of this card
end PreOpenCard

Local rsCombinedheight
On ResizeStack newWidth, newHeight
Set the rectangle of group "scrollingText" to 10, 66, newWidth-10, NewHeight - 10
Set the top of field "Feedback1" of group "info" of group "scrollingText" to 72
Set the width of field "Feedback1" of group "info" of group "scrollingText" to newWidth-35
Set the height of field "Feedback1" of group "info" of group "scrollingText" to the formattedheight of field "Feedback1" of group "info" of group "scrollingText"
Set the top of Image "MainScreen_Features_Reduced.PNG" of group "info" of group "scrollingText" to the bottom of field "Feedback1" of group "info" of group "scrollingText"
Set the xloc of Image "MainScreen_Features_Reduced.PNG" of group "info" of group "scrollingText" to (newWidth/2)
Set the top of field "Feedback2" of group "info" of group "scrollingText" to the bottom of Image "Cogismo_MainScreen_Features_Reduced.PNG"
Set the width of field "Feedback2" of group "info" of group "scrollingText" to newWidth-35
Set the height of field "Feedback2" of group "info" of group "scrollingText" to the formattedheight of field "Feedback2" of group "info" of group "scrollingText"
Set the top of field "Feedback3" of group "info" of group "scrollingText" to the bottom of field "Feedback2" of group "info" of group "scrollingText"
Set the width of field "Feedback3" of group "info" of group "scrollingText" to newWidth-35
Set the height of field "Feedback3" of group "info" of group "scrollingText" to the formattedheight of field "Feedback3" of group "info" of group "scrollingText"
Put (the height of field "Feedback1" of group "info" of group "scrollingText" + the height of Image "MainScreen_Features_Reduced.PNG" of group "info" of group "scrollingText" + the height of field "Feedback2" of group "info" of group "scrollingText" + the height of field "Feedback3" of group "info" of group "scrollingText") into rsCombinedheight
Set the rectangle of group "info" of group "scrollingText" to 14, 72, newWidth-16, 72+rsCombinedheight
SetupScroller
end ResizeStack

Local ssScrollerRect, ssContentRect, ssScrollerID
On SetupScroller
if environment() is "mobile" then
put the rect of group "scrollingText" into ssScrollerRect
put 0, 0, the formattedWidth of group "Info" of group "scrollingText", the formattedHeight of group "Info" of group "scrollingText" into ssContentRect
mobileControlCreate "scroller", "FeedBackScroll"
put the result into ssScrollerID
mobileControlSet "FeedBackScroll", "rect", ssScrollerRect
mobileControlSet "FeedBackScroll", "contentRect", ssContentRect
mobileControlSet "FeedBackScroll", "visible", true
mobileControlSet "FeedBackScroll", "scrollingEnabled", true
mobileControlSet "FeedBackScroll", "vIndicator", true
mobileControlSet "FeedBackScroll", "vscroll", 0
End if
end SetupScroller

on scrollerDidScroll hOffset, vOffset
set the vScroll of group "scrollingText" to vOffset
end scrollerDidScroll

On CloseCard
if environment() is "mobile" then mobileControlDelete "FeedBackScroll"
end CloseCard

Re: Sometimes get white space at top of mobile scroller

Posted: Fri Apr 22, 2016 5:44 pm
by jacque
Try setting the scroll of the group to 0 before creating the native scroller. It sounds like the two starting positions aren't synched.

Re: Sometimes get white space at top of mobile scroller

Posted: Tue Apr 26, 2016 12:20 am
by KimD
Thanks Jacque. As a result of your prompt I now have a better understanding of how this works
1) Livecode stores a system property vScroll, for the group which contains the objects that will scroll.
2) vScroll is set to zero upon app start; but upon exiting the card that contains the objects to be scrolled - vScroll is a value corresponding to the amount that those objects were actually scrolled.
3) Upon re-entering the card - the scrolling objects are displayed at their zero position; but upon starting a scroll action - the scrolling objects immediately re-displayed at their vScroll position.
4) mobileControlDelete does NOT re-zero the vScroll of the corresponding scrolling group.

So my "random" appearance of white space was an artifact of where my group was scrolled to when I previously exited the card. If I scrolled my group all of the way back to its starting position (which is what I did 80% of the time) then I did not get white space the next time that I entered the card.

I haven't had any white space problems since adding the following to my CloseCard handler - set the vScroll of group "scrollingText" to 0

Thanks again

Re: Sometimes get white space at top of mobile scroller

Posted: Wed May 04, 2016 8:25 am
by MaxV
Just to remember: contentRect must always starts from 0,0:

Code: Select all

mobileControlSet "myScroller", "ContentRect", "0,0,100,500"
It's used by livecode for calculation purpose and has no other meaning. If it doesn't start from 0,0; it doesn't work correctly.

Re: Sometimes get white space at top of mobile scroller

Posted: Wed May 04, 2016 10:37 pm
by KimD
Thanks Max. I did manage to get it working. For anyone else that wants to set up an Android vertical scroller made up of multiple objects - I've attached my working code below.

============================================================

Local rsCombinedheight
On ResizeStack newWidth, newHeight
Set the rectangle of group "scrollingText" to 10, 66, newWidth-10, NewHeight - 10
Set the top of field "Feedback1" of group "info" of group "scrollingText" to 72
Set the width of field "Feedback1" of group "info" of group "scrollingText" to newWidth-35
Set the height of field "Feedback1" of group "info" of group "scrollingText" to the formattedheight of field "Feedback1" of group "info" of group "scrollingText"
Set the top of Image "MyApp_MainScreen_Features_Reduced.PNG" of group "info" of group "scrollingText" to the bottom of field "Feedback1" of group "info" of group "scrollingText"
Set the xloc of Image "MyApp_MainScreen_Features_Reduced.PNG" of group "info" of group "scrollingText" to (newWidth/2)
Set the top of field "Feedback2" of group "info" of group "scrollingText" to the bottom of Image "MyApp_MainScreen_Features_Reduced.PNG"
Set the width of field "Feedback2" of group "info" of group "scrollingText" to newWidth-35
Set the height of field "Feedback2" of group "info" of group "scrollingText" to the formattedheight of field "Feedback2" of group "info" of group "scrollingText"
Set the top of field "Feedback3" of group "info" of group "scrollingText" to the bottom of field "Feedback2" of group "info" of group "scrollingText"
Set the width of field "Feedback3" of group "info" of group "scrollingText" to newWidth-35
Set the height of field "Feedback3" of group "info" of group "scrollingText" to the formattedheight of field "Feedback3" of group "info" of group "scrollingText"
Put (the height of field "Feedback1" of group "info" of group "scrollingText" + the height of Image "MyApp_MainScreen_Features_Reduced.PNG" of group "info" of group "scrollingText" + the height of field "Feedback2" of group "info" of group "scrollingText" + the height of field "Feedback3" of group "info" of group "scrollingText") into rsCombinedheight
Set the rectangle of group "info" of group "scrollingText" to 14, 72, newWidth-16, 72+rsCombinedheight
SetupScroller
end ResizeStack

Local ssScrollerRect, ssContentRect, ssScrollerID
On SetupScroller
if environment() is "mobile" then
put the rect of group "scrollingText" into ssScrollerRect
put 0, 0, the formattedWidth of group "Info" of group "scrollingText", the formattedHeight of group "Info" of group "scrollingText" into ssContentRect
mobileControlCreate "scroller", "FeedBackScroll"
put the result into ssScrollerID
mobileControlSet "FeedBackScroll", "rect", ssScrollerRect
mobileControlSet "FeedBackScroll", "contentRect", ssContentRect
mobileControlSet "FeedBackScroll", "visible", true
mobileControlSet "FeedBackScroll", "scrollingEnabled", true
mobileControlSet "FeedBackScroll", "vIndicator", true
mobileControlSet "FeedBackScroll", "vscroll", 0
End if
end SetupScroller

on scrollerDidScroll hOffset, vOffset
set the vScroll of group "scrollingText" to vOffset
end scrollerDidScroll

On CloseCard
set the vScroll of group "scrollingText" to 0
if environment() is "mobile" then mobileControlDelete "FeedBackScroll"
end CloseCard