Trouble with scrolling list (clickable) in native scroller

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gregmiller
Posts: 14
Joined: Wed Dec 13, 2006 6:09 am
Location: California

Trouble with scrolling list (clickable) in native scroller

Post by gregmiller » Wed Feb 03, 2016 7:30 am

I am trying to get a scrolling list of links in a text field to work as a native scroller. Using the Native Scroller Example, I got the text field working in my app as a native scroller, but when I add the code to the field to respond to mouseUp (basically to go to another card based on the line clicked), it stops scrolling. The mouseUp executes, but I can no longer scroll the field "natively". I assume the mouseUp message is getting in the way of the scrolling. Any ideas about how to fix this?

Thanks!

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Trouble with scrolling list (clickable) in native scroll

Post by quailcreek » Thu Feb 04, 2016 6:08 pm

HI,
Make sure your field has lockText and listBehavior checked in the Property Inspector. Also your scroller should have
mobileControlSet theScrollID, "delayTouches", "true"

Need to see your field and scroller script to help further.
Tom
MacBook Pro OS Mojave 10.14

gregmiller
Posts: 14
Joined: Wed Dec 13, 2006 6:09 am
Location: California

Re: Trouble with scrolling list (clickable) in native scroll

Post by gregmiller » Fri Feb 05, 2016 7:09 pm

Excellent! Let me try those. I will post code if it does not work. Thanks.

gregmiller
Posts: 14
Joined: Wed Dec 13, 2006 6:09 am
Location: California

Re: Trouble with scrolling list (clickable) in native scroll

Post by gregmiller » Sat Feb 06, 2016 7:37 am

Still not working. So, I am missing something on this. I tested the scroller on my iPhone when it was just a scrolling field and it worked. But, when I added the code to the field, it stopped scrolling. It executes my code fine without errors, but this code seems to take over rather than let the field scroll even though I am moving my finger over the field on the iPhone.

Here is my card script (I started with the scroller example code and tried not to change too much):

Code: Select all

local sScrollerID

on preOpenCard
   local tScrollerRect, tContentRect
   
   // Only create a scroller on a mobile device
   if environment() is not "mobile" then exit preOpenCard
   
   // Set the area of the scroller
   put the rect of group "scrollArea" into tScrollerRect
   
   // Set the are of the content to be scrolled
   put the left of field "lorem",the top of field "lorem",the right of field "lorem",the formattedHeight of field "lorem" into tContentRect
   
   // Create the scroller control
   mobileControlCreate "scroller", "loremScroll"
   put the result into sScrollerID
   
   // Set the properties of the scroller
   mobileControlSet "loremScroll", "rect", tScrollerRect
   mobileControlSet "loremScroll", "contentRect", tContentRect
   mobileControlSet "loremScroll", "visible", true
   mobileControlSet "loremScroll", "scrollingEnabled", true
   mobileControlSet "loremScroll", "vIndicator", true
   mobileControlSet "loremScroll", "vscroll", 0
   mobileControlSet "loremScroll", "delayTouches", "true"
end preOpenCard

on closeCard
   // Delete the scroller
   if environment() is not "mobile" then exit closeCard
   mobileControlDelete sScrollerID
end closeCard

on scrollerDidScroll hOffset, vOffset
   // When the user scrolls move the displayed content
   set the vScroll of group "scrollArea" to vOffset
end scrollerDidScroll
Here is my field script. The field scrolled fine before I put this code in there:

Code: Select all

global gDatabaseID

on mouseUp
   --set up Categories card (the go to card)
   put word 2 of the clickLine into whatLine
   put line whatLine of target into field "Subcategory" of card "Categories"
   put line whatLine of field CategoryIDs into whatID
   
   switch whatID
     --switch stuff goes here; it's the same as the default database code below but for special cases; I deleted for brevity.
      
      default
         
         put empty into field "Data" of card "Categories"
         -- Go get data for Categories in SuperCategory from SQL
         -- check the global connection ID to make sure we have a database connection
         global gDatabaseID
         if gDatabaseID is not a number then
            answer error "Please connect to the database first."
            exit to top
         end if
             
         put "SELECT category.name, category.id FROM category JOIN supercategorycategory ON category.id=supercategorycategory.cid where supercategorycategory.scid='" & whatID & "'  order by category.name" into tSQL
         
         -- query the database
         put revDataFromQuery(tab, cr, gDatabaseID, tSQL) into tData
             
         -- check the result and display the data or an error message
         if item 1 of tData = "revdberr" then
            answer error "There was a problem querying the database:" & cr & tData
         else
            -- separate the results in the display names and IDs
            set the itemDel to tab
            put empty into categoryList
            put empty into IDlist
            repeat with x = 1 to the number of lines of tData
               put item 1 of line x of tData & return after categoryList
               put item 2 of line x of tData & return after IDlist
            end repeat
            -- set up the Category card with results
            put IDlist into field "CategoryIDs" of card Categories
            put categoryList into field "Data" of card Categories
            
            -- set the image of Categories card to match selection
            hideCategoryImages
            put whatID & ".jpg" into showImage
            set the visible of image showImage of card Categories to true
            
            -- place ad for Categories Page
            put "SELECT supercategory.ad, supercategory.adlink FROM supercategory where supercategory.id=" & whatID into adSQL
            
            -- query the database
            put revDataFromQuery(tab, cr, gDatabaseID, adSQL) into adData
            -- check the result and display the data or an error message
            if item 1 of adData = "revdberr" then
               put URL "http://building.com/BPads/building.gif" into image "CategoryAd" of card Categories
               put "on mouseUp" & return & "launch url " & quote & "http://www.building.com" & quote & return & "end mouseUp" into whatScript
               set the script of image  "CategoryAd" of card Categories to whatScript
            else
               -- separate the results
               set the itemDel to tab
               put empty into adImage
               put empty into adURL
               put item 1 of line 1 of adData  after adImage
               put item 2 of line 1 of adData  after adURL
               -- set up the Category Ad with results
               put "http://building.com/BPads/" & adImage into whatImage
               put URL whatimage into image "CategoryAd" of card Categories
               put "on mouseUp" & return & "launch url " & quote & adURL & quote & return & "end mouseUp" into whatScript
               set the script of image  "CategoryAd" of card Categories to whatScript
               
               
               go to card Categories
            end if
            
         end if
         
   end switch
   
end mouseUp

on hideCategoryImages
   repeat with x = 1 to (the number of lines of field "CategoryIDs")
      put line x of field "CategoryIDs" & ".jpg" into whatImage
      set the visible of image whatImage of card Categories to false
   end repeat
end hideCategoryImages

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

Re: Trouble with scrolling list (clickable) in native scroll

Post by jacque » Sat Feb 06, 2016 7:35 pm

What is the scroll of the field when you create the scroller? If it isn't zero, the scroller will be out of sync with the field and you can get unexpected results. Try setting the scroll to 0 just before the native scroller is made.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Trouble with scrolling list (clickable) in native scroll

Post by quailcreek » Sat Feb 06, 2016 7:57 pm

Just to avoid potential trouble.
go to card Categories
should be
go to card "Categories"
anywhere in your script you refer to... card "Categories"

Same here:
set the visible of image "showImage" of card "Categories" to true

There are 3 ways to refer to objects in LC. The object ID, the object number or the object name.

The object name can be changed and is a "literal".
Anytime you refer to an object (card, field, stack etc.) by its name, you should put the name in quotes. card “fred”

If you refer to the object by its number it would be like this: card number 1
Card number 1 is the first card in the stack, number 2 the second and so on. If you reorder the cards, the number is changed.

If you refer to the object by its ID it would be like this: card ID 123
The ID of an object is assigned by LC when the object is created and it never changes.

The advantage of referring to an object by its ID is that its ID never changes. So for instance with cards, you can rename or reorder the cards in a stack and, if you have refer to the cards by their ID, your code will still work. Not a big deal if you have 3 or 4 cards in your stack. If you have 40 or 50 it makes a big difference.
Tom
MacBook Pro OS Mojave 10.14

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

Re: Trouble with scrolling list (clickable) in native scroll

Post by jacque » Sat Feb 06, 2016 9:33 pm

If you refer to the object by its number it would be like this: card number 1
This will error because of the word "number". I think you meant "card 1".
The advantage of referring to an object by its ID is that its ID never changes.
Actually, it is possible to change the ID of objects (it was only possible for images originally, but that's been expanded.) Presumably if the developer changes the ID they will know about it and account for it in the scripts.
Last edited by jacque on Sat Feb 06, 2016 9:35 pm, edited 1 time in total.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Trouble with scrolling list (clickable) in native scroll

Post by quailcreek » Sat Feb 06, 2016 9:34 pm

Thanks you, Jacqueline. I stand corrected.
Tom
MacBook Pro OS Mojave 10.14

gregmiller
Posts: 14
Joined: Wed Dec 13, 2006 6:09 am
Location: California

Re: Trouble with scrolling list (clickable) in native scroll

Post by gregmiller » Sat Feb 20, 2016 8:28 pm

Still banging my head against that wall on this one. I had to so some wrestling with Xcode for the past week or so first. Got that sorted out. To fix this scrolling list problem, I have:

1. Made sure the field has lockText and listBehavior checked in the Property Inspector. This is the field that is part of the scroller group.
2. I have added:
mobileControlSet theScrollID, "delayTouches", "true"
then changed it to
mobileControlSet theScrollID, "delayTouches", true
to the script that sets up the scroller (which is in the card script); tried it both ways.
3. Made sure both the scroller group and the field itself has their layer modes set to "Scrolling" in properties
4. Cleaned up the code to refer to cards with quotes and took out some extraneous code just for good measure.
5. Played around with various other properties.
6. Upgraded to LC 7.1.1 and Xcode 7.1

So far, nothing has changed the behavior of my scrolling list. It does not scroll in iOS, but the mouseUp message in the field script works fine. If I take out the field script, then it scrolls fine. It looks to me like you can't have both an iOS scroller and list behavior. Has anybody made both work at the same time? It would seem a must have capability since scrolling lists such as you see on many apps are a basic UI thing for iOs (and Android). But, I have not given up yet! Suggestions welcome.

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Trouble with scrolling list (clickable) in native scroll

Post by quailcreek » Sat Feb 20, 2016 9:10 pm

Look this over.
Attachments
Scrolling Fld.zip
(2.7 KiB) Downloaded 243 times
Tom
MacBook Pro OS Mojave 10.14

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

Re: Trouble with scrolling list (clickable) in native scroll

Post by jacque » Sat Feb 20, 2016 9:43 pm

It looks to me like you can't have both an iOS scroller and list behavior. Has anybody made both work at the same time?
You should be able to. One thing you might try is to specifically set the scroll of the lorem field to 0 before creating the scroller. I've noticed that if both the field and the scroller aren't both at zero to begin with, scrolling can be inaccurate. If you need a different scroll in the final display, set it after the scroller is already in place.

I'm not sure why just having a field script might affect that (seems like it shouldn't.) I don't see anything in there that should make a difference.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

gregmiller
Posts: 14
Joined: Wed Dec 13, 2006 6:09 am
Location: California

Re: Trouble with scrolling list (clickable) in native scroll

Post by gregmiller » Thu Feb 25, 2016 6:08 am

One thing you might try is to specifically set the scroll of the lorem field to 0 before creating the scroller.
ll

I should have listed that too. I am setting the scroll of the field to 0 before creating the scroller. Unfortunately, that did not fix the issue either. Also, to be clear, it is not that the scroller acts odd or is unpredictable in any way. It simply does not scroll at all. The field goes right into handling the click in the list and does not appear to attempt scrolling. So, when I take out the script for the list and the field is just a text field again, it starts scrolling fine.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4036
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Trouble with scrolling list (clickable) in native scroll

Post by bn » Thu Feb 25, 2016 10:55 am

Hi Greg,

have a look at Tom's example stack and how he sets the contentRect.

Code: Select all

mobileControlSet myScroller, "contentRect", (0, 0, the width of fld "Awards", the formattedHeight of fld "Awards")
in your code you say

Code: Select all

 put the left of field "lorem",the top of field "lorem",the right of field "lorem",the formattedHeight of field "lorem" into tContentRect
contentRect always has a topLeft of 0,0 and is relative to "rect"

What happens when you set:

Code: Select all

 put 0,0,the width of field "lorem",the formattedHeight of field "lorem" into tContentRect
Kind regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4036
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Trouble with scrolling list (clickable) in native scroll

Post by bn » Sat Mar 05, 2016 2:47 pm

Hi Greg,

is your problem solved? Or is there anything we can do for you.

Kind regards
Bernd

Post Reply

Return to “iOS Deployment”