Bug when scrolling native.newTextBox on Android

I have a multi-line native.newTextBox (textBox, not textField) which is prepopulated with text which the user can edit before posting to facebook / linkedin etc.

The problem I have is that on Android devices if the user tries to scroll the textbox, it gets stuck and jitters about. The cause of the problem is the cursor. The textbox will not scroll past a point which would mean the cursor is off screen, so if the user wants to scroll down they have to tap the bottom of the text box to move the cursor, scroll a little bit, tap, scroll, tap, scroll, etc.

This happens on a Nexus 7, an HTC Sensation, and an Asus Transformer, presumably it happens on other devices too.

Does anyone else have this problem, and if so do they know how to fix it?

Edit:

I have some additional information. It turns out this only happens if you use native.systemFont, which is somewhat bizarre. If we use a custom font the bug doesn’t happen, and the user can scroll to their hearts content.

However, we did notice that if you use a custom font, you lose some functionality from the text box. You don’t get the little tabs which you can drag to select sections of text, or the copy/paste bar at the top of the screen. Not a concern for us, but it may concern someone else.

Ignore my edit, the bug also happens with custom fonts.

We are fairly certain this didn’t happen before, as we were testing out the text input itself a fair amount before we noticed this problem. The only thing I have changed to test this out is the font, as I mentioned earlier I’ve used the native.systemFont and our own ttf font.

I haven’t changed ANYTHING else in my native.newTextBox code - same font size, same listener etc.

What I find extremely strange is that when I tested out a build using our own font yesterday it worked fine on my HTC Sensation. So I shared the apk with my boss who tested it and found that it didn’t work on his HTC Desire HD and Nexus 7.

I thought that maybe I had accidentally installed an old build on my device, so I rebuilt the app without making any changes and ran it on my Sensation…and it was broken again. I then tried the oldest apks that I had saved, and they too had the problem. But as I’ve already mentioned, at least one build worked - apparently not the oldest or newest builds (and I also tried some in between without any luck).

I’ve also tried using Corona builds 1043, 1076 and 1093 - the same thing happens with each version.

Here is my code for the text box, is there anything that is incorrect here:

local \_W = display.contentWidth local \_H = display.contentHeight local charLimits = {twitter = 140, linkedin = 600} local site = "twitter" --font size is fixed to 2 values, for retina and non-retina screens local inputFontSize = 40 / display.contentScaleX if inputFontSize \< 40 then &nbsp;&nbsp;&nbsp;&nbsp;inputFontSize = 20 else &nbsp;&nbsp;&nbsp;&nbsp;inputFontSize = 40 end local myMessageTxt = "Hi, This is my default text and I would like you to read it\nhttp://plantpot.co" local function textFieldListener( event ) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;if event.phase == "began" then &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--dont need to do anything here &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;elseif event.phase == "editing" then &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--need to truncate the text as it is typed if it is too long &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if #event.target.text \> charLimits[site] then &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;event.target.text = string.sub(event.target.text, 1, charLimits[site]) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;myMessageText = event.target.text &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;elseif event.phase == "submitted" then &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;submitPost()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;end end --create the text box inputTextField = native.newTextBox( \_W \* 0.05, \_H \* 0.15, \_W \* 0.9, \_H \* 0.3 &nbsp;) inputTextField.font = native.newFont( "myFontName", inputFontSize) inputTextField:setReferencePoint(display.CenterReferencePoint) inputTextField.x, inputTextField.y = \_W \* 0.5, \_H \* 0.25 inputTextField.isEditable = true inputTextField:addEventListener( "userInput", textFieldListener ) inputTextField.text = myMessageTxt &nbsp;

In theory none of these phases should be triggered when dragging, but even if they were I don’t see why this would prevent the box from scrolling.

Ignore my edit, the bug also happens with custom fonts.

We are fairly certain this didn’t happen before, as we were testing out the text input itself a fair amount before we noticed this problem. The only thing I have changed to test this out is the font, as I mentioned earlier I’ve used the native.systemFont and our own ttf font.

I haven’t changed ANYTHING else in my native.newTextBox code - same font size, same listener etc.

What I find extremely strange is that when I tested out a build using our own font yesterday it worked fine on my HTC Sensation. So I shared the apk with my boss who tested it and found that it didn’t work on his HTC Desire HD and Nexus 7.

I thought that maybe I had accidentally installed an old build on my device, so I rebuilt the app without making any changes and ran it on my Sensation…and it was broken again. I then tried the oldest apks that I had saved, and they too had the problem. But as I’ve already mentioned, at least one build worked - apparently not the oldest or newest builds (and I also tried some in between without any luck).

I’ve also tried using Corona builds 1043, 1076 and 1093 - the same thing happens with each version.

Here is my code for the text box, is there anything that is incorrect here:

local \_W = display.contentWidth local \_H = display.contentHeight local charLimits = {twitter = 140, linkedin = 600} local site = "twitter" --font size is fixed to 2 values, for retina and non-retina screens local inputFontSize = 40 / display.contentScaleX if inputFontSize \< 40 then &nbsp;&nbsp;&nbsp;&nbsp;inputFontSize = 20 else &nbsp;&nbsp;&nbsp;&nbsp;inputFontSize = 40 end local myMessageTxt = "Hi, This is my default text and I would like you to read it\nhttp://plantpot.co" local function textFieldListener( event ) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;if event.phase == "began" then &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--dont need to do anything here &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;elseif event.phase == "editing" then &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--need to truncate the text as it is typed if it is too long &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if #event.target.text \> charLimits[site] then &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;event.target.text = string.sub(event.target.text, 1, charLimits[site]) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;myMessageText = event.target.text &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;elseif event.phase == "submitted" then &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;submitPost()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;end end --create the text box inputTextField = native.newTextBox( \_W \* 0.05, \_H \* 0.15, \_W \* 0.9, \_H \* 0.3 &nbsp;) inputTextField.font = native.newFont( "myFontName", inputFontSize) inputTextField:setReferencePoint(display.CenterReferencePoint) inputTextField.x, inputTextField.y = \_W \* 0.5, \_H \* 0.25 inputTextField.isEditable = true inputTextField:addEventListener( "userInput", textFieldListener ) inputTextField.text = myMessageTxt &nbsp;

In theory none of these phases should be triggered when dragging, but even if they were I don’t see why this would prevent the box from scrolling.

Well, I also have severe problems with textbox functions, but only when testing under windows and android. For some reason it works well under Mac and on iphone/ipad.

Has anyone else seen this type of device incompability on textBox?

Well, I also have severe problems with textbox functions, but only when testing under windows and android. For some reason it works well under Mac and on iphone/ipad.

Has anyone else seen this type of device incompability on textBox?

+1

Hi @Mars Interactive,

The original posts in this thread are over 1.5 years old, so please be more specific about the issues you’re currently having. We’ll need some usage case examples and quite likely some code as well.

Thanks,

Brent

hey bratt what’s up

look i’m really having problems with another thing i have,

ive sent you 2 personal assistance messages, and posted in the forum a question and jumped it 3 times

and still no reply

please can you reply to that post ? >

http://forums.coronalabs.com/topic/53205-how-to-do-the-most-basic-post-how-do-i-add-an-image-to-network-call/

Hi @Mars,

I responded to your other post. Can I consider this thread issue resolved, or is there something else in this?

Thanks,

Brent

+1

Hi @Mars Interactive,

The original posts in this thread are over 1.5 years old, so please be more specific about the issues you’re currently having. We’ll need some usage case examples and quite likely some code as well.

Thanks,

Brent

hey bratt what’s up

look i’m really having problems with another thing i have,

ive sent you 2 personal assistance messages, and posted in the forum a question and jumped it 3 times

and still no reply

please can you reply to that post ? >

http://forums.coronalabs.com/topic/53205-how-to-do-the-most-basic-post-how-do-i-add-an-image-to-network-call/

Hi @Mars,

I responded to your other post. Can I consider this thread issue resolved, or is there something else in this?

Thanks,

Brent

This thread /issue is not resolved. I too am having the scroll problem with native.textBox on Android. If I populate the textbox with multiple lines of text using "sample text \n " etc, it will let me scroll to the bottom of the text with iphone device and simulator, but on android device it just jitters and does not scroll, always staying at the top. Please help. Unless you have a better solution to create a chat window that scrolls text for BOTH android and ios. 

Is there a reason you’re not using display.newText() in a widget.newScrollView()?

Can you put together some sample code that has this issue?

Rob

I just did that and wasn’t happy with it, so now I think I’m going to implement tableview and just populate it, re-render on new message, then scroll to top. I believe it will be a better option bc I can add more items like a time stamp on the right side.

Just want to add that this issue still occurs as of build 2635.

The best solution I’ve found is to make it “editable,” but just close the keyboard when it’s touched. It’s a nasty workaround, but it makes it much easier to scroll for some reason.

Example:

local function inputListener( event ) if event then native.setKeyboardFocus(nil); end end local textBox = native.newTextBox(200, 200, 200, 200); textBox:addEventListener("userInput", inputListener); textBox.isEditable = true;

This thread /issue is not resolved. I too am having the scroll problem with native.textBox on Android. If I populate the textbox with multiple lines of text using "sample text \n " etc, it will let me scroll to the bottom of the text with iphone device and simulator, but on android device it just jitters and does not scroll, always staying at the top. Please help. Unless you have a better solution to create a chat window that scrolls text for BOTH android and ios. 

Is there a reason you’re not using display.newText() in a widget.newScrollView()?

Can you put together some sample code that has this issue?

Rob

I just did that and wasn’t happy with it, so now I think I’m going to implement tableview and just populate it, re-render on new message, then scroll to top. I believe it will be a better option bc I can add more items like a time stamp on the right side.