Page 1 of 1

Can't get to create a native scrolling text field

Posted: Mon Jan 20, 2014 12:37 pm
by Mag
Hi all,

I'm trying to create a native text scrolling field that work on Android. The field is created but you can't scroll it. Works fine on iOS, not in Android. Here is the code I'm using.

Code: Select all

on openCard
   createNativeField
end openCard

on createNativeField
   if environment() = "mobile" then
      mobileControlCreate "multiline", "testField"
      
      mobileControlSet "testField", "rect", the rect of graphic "testFieldGraphic"
      mobileControlSet "testField", "text", field "sourceField"
      
      mobileControlSet "testField", "visible", "true"
      mobileControlSet "testField", "editable", "false"
      
      mobileControlSet "testField", "dataDetectorTypes", "link"
      mobileControlSet "testField", "textAlign", "center"
      mobileControlSet "testField", "fontSize", "16"
      
      mobileControlSet "testField", "autoCorrectionType", "no"
      mobileControlSet "testField", "scrollingEnabled", "true"
      
      mobileControlSet "testField", "opaque", "false"
      mobileControlSet "testField", "scrollingEnabled", "true"
      
      if the platform is "iphone" then
         mobileControlSet "testField", "borderStyle", "none"
         mobileControlSet "testField", "indicatorStyle", "white"
         mobileControlSet "testField", "canBounce", "true"
         mobileControlSet "testField", "canScrollToTop", "true"
      end if
      
      if the platform is "android" then
         mobileControlSet "testField", "multiline", "true"
      end if
      
   end if
end createNativeField


Here is the test stack

Re: Can't get to create a native scrolling text field

Posted: Mon Jan 20, 2014 4:24 pm
by Klaus
HI Mag,

your script will only CREATE that scroller and nothing else :D

You need another handler "scrollerDidScroll" to add the actual scrolling functionality:

Code: Select all

on scrollerDidScroll tHScroll, tVScroll
   set the VScroll of fld "your field 2B scrolled here" to tVScroll
  ## or whatever you want to scroll
end scrollerDidScroll
Best

Klaus

Re: Can't get to create a native scrolling text field

Posted: Mon Jan 20, 2014 6:54 pm
by jacque
Here are the commands I use to create a multiline input field that scrolls on both iOS and Android:

Code: Select all

  mobileControlCreate "multiline", "displayInput"
  mobileControlSet "displayInput", "rect", the rect of fld "display"
  mobileControlSet "displayInput", "vScroll", "0"
  mobileControlSet "displayInput", "visible", "true"
  mobileControlSet "displayInput", "text", fld "display"
  mobileControlSet "displayInput", "autocorrectionType", "no"
  -- iOS only:
  mobileControlSet "displayInput", "editable", "false"
  mobileControlSet "displayInput", "scrollingEnabled", true
  mobileControlSet "displayInput", "enabled", true
You don't need to distinguish between iOS and Android for the iOS-only properties, they will just be ignored on Android.

(Klaus, he isn't using a scroller, he's using a native input control, so it shouldn't require any scripted scrolling.)

Re: Can't get to create a native scrolling text field

Posted: Tue Jan 21, 2014 10:44 am
by Mag
Hi Klaus, thank you for the code I will use it when implementing a scroller!

Hi jacque, I will try it right now!

Re: Can't get to create a native scrolling text field

Posted: Tue Jan 21, 2014 1:19 pm
by Klaus
jacque wrote:(Klaus, he isn't using a scroller, he's using a native input control, so it shouldn't require any scripted scrolling.)
Oh, well yes, sorrry, my fault. 8)

Re: Can't get to create a native scrolling text field

Posted: Thu Jan 23, 2014 3:15 pm
by Mag
It works.

The problem the field has are:

- I'ts editable. I use it to show credits so it's better to avoid this.
- On Kindle about every word is underlined in red
- Links are not clickable

:oops:

Re: Can't get to create a native scrolling text field

Posted: Thu Jan 23, 2014 4:58 pm
by jacque
Yes, I had the same problems. The red underline is a user preferences setting, it means that spell checking is turned on. You can't really control that. The editable property on Android has been deprecated and no longer works except in older versions of Android. I'm not sure about the links, I wasn't using those, but I think there's a property you can set to enable them.

Since you are just displaying static text I think the best solution is to just use a LC field and lay a native scroller over it. That means that Klaus was right after all. :-)

Re: Can't get to create a native scrolling text field

Posted: Fri Jan 24, 2014 1:37 am
by Mag
jacque wrote:Yes, I had the same problems. The red underline is a user preferences setting, it means that spell checking is turned on. You can't really control that. The editable property on Android has been deprecated and no longer works except in older versions of Android. I'm not sure about the links, I wasn't using those, but I think there's a property you can set to enable them.

Since you are just displaying static text I think the best solution is to just use a LC field and lay a native scroller over it. That means that Klaus was right after all. :-)
Great advice. Is there some trick to make the field large enough to show all the text? I've a lot of text to put inside and it's a bit difficult to enlarge the stack manually to set the field dimension correctly... :roll:

PS
Oh, yes, the foresight of that guy is known all over the world!

Re: Can't get to create a native scrolling text field

Posted: Fri Jan 24, 2014 1:51 am
by Mag
Oops, sorry, maybe I have just to use the Fit Content button on the Inspector... :mrgreen: