native.newTextField sizing issues on Android

My game is currently released and running well under iOS and I’ve now been working on Android integration. The one weird problem I am seeing is that text using native.newTextField is so tiny it can’t be read…

My testing phone is a Samsung Galaxy S3 and everything else seems to be ok

Nothing weird in the initialization code

 InputBox = native.newTextField( 320, \_G.yMin + 300, 240, 30 ) native.setKeyboardFocus( InputBox ) InputBox:addEventListener( "userInput", onKeyboard ) FadeView:insert(InputBox) 

When I run the app in the simulator as a Galaxy S3 it looks as expected but on the phone itself it looks like this

Screenshot_2016_11_24_18_22_33.png

I know that this was an issue a few years ago but this was fixed last year according to:

https://coronalabs.com/blog/2014/12/16/tutorial-new-native-text-input-features/

Any help would be appreciated,

Thanks,

Roy

Are you calling this: https://docs.coronalabs.com/daily/api/type/TextField/resizeFontToFitHeight.html

If not, you should be.

BTW: You can’t rely on the simulator for native.* testing.  You must check on the real OS targets.

If you’re running the simulator on OS X, then all simulated devices are using the OS X native text field.  

If you’re running the simulator on Windows, then all simulated devices are using the Windows native text field.  

The only way to get the Android or iOS Native text field is to test on device.

I was not calling but that’s supposed to be the default behavior - the blog post mentions:

“The first of these functions (object:resizeFontToFitHeight()) is useful if you change the input field’s height sometime after the field is created, and you want to resize the font to fit within the field”

I checked anyways and changed the code to:

 InputBox = native.newTextField( 320, \_G.yMin + 300, 240, 30 ) InputBox:resizeFontToFitHeight() native.setKeyboardFocus( InputBox ) InputBox:addEventListener( "userInput", onKeyboard ) FadeView:insert(InputBox) 

but same problem

I just noticed you added to your comment - this testing is being done on the device, a Samsung Galaxy S3 - the screen shot I posted is grabbed directly from the device.  On the simulator (and on every iOS device I have tested on) it does look ok.

Thanks,

Roy

Roy,

  1. Hi.  I didn’t read the article, sorry.  If it says that is the default behavior AND if the docs agree (may have changed since the blog), then  you should file a bug.

  2. If ‘resizeFontToFitHeight()’ didn’t work I’d make a small sample test case, verify it still fails to behave properly, then submit a bug.

  3. Device versus Simuated - Yeah, I always edit after posting to clean up and add more thoughts.  I like a nice clean post.  Please note.  The point I was making is you cannot depend on what you see in the simulator.

Filing A Bug (https://developer.coronalabs.com/content/bug-submission)

You’ll be asked for an example demonstrating the problem.  It should have main.lua, config.lua, and a basic build.settings file.  You will package this in a ZIP and attach it to the bug report.

If you do this, you may as well share a link to the zip file here too. That way others can test it and give feedback if they have time to help.

Cheers,

Ed

You should also consider posting a link to the test case here.  It should have main.lua, config.lua, and a basic build.settings.  It should also demonstrate just this problem.  That way we are all sure we’re testing the same thing.  

(Note: You’ll need this for your bug submission anyways.)

PS - I forgot to ask, but you’re using a current version of Corona right?

So I created a test project and of course found the issue almost right away - I believe it’s a bug since the goal of the changes from that blog post are to make the newTextField behave like display.newText on all devices

In config.lua if you set width and height to the default of 320x480 then it works as expected but if you set it to 640x960 (like I have with my project) then you get the problem where native.newTextField is half as big as the display.newText equivalent (but only on Android devices or at least the Samsung Galaxy S3 which is the only one I have to test on)

I take it that nobody sets their project to 640x960 otherwise this would be a more common issue.  I set my project to 640x960 when I started working on it ages ago to get more granular placement of things - not sure if it makes any difference but to go back and change everything would be a huge pain!

I can code a workaround now at least - is this worth submitting a bug for?

Thanks again for the help

Roy

Roy,

You forgot to share a link to your sample.  I’d love to look at it, before you file a bug.

I’m not convinced what I’m hearing is a bug.  Note: You cant’ rely on the blog post as ‘it should work this way’, but rather on what the API docs say.  

PS - I use 640x960 or larger as my primary size, but I don’t use text fields much.

PPS - Reading the first part of the article, I would agree with you that (even though I don’t see the same statements in the API docs after a quick look) this seems like a bug.

I’ll submit the bug to Corona, really easy to duplicate

Main.lua is just this:

local InputBox = native.newTextField( 160, 100, 240, 30 ) native.setKeyboardFocus( InputBox )

In the config.lua if you set width and height to 320x480 then it looks great on the Android device, if you set it to 640x960 it looks microscopic.  On all iOS devices 320x480 and 640x960, the text size looks the exact same.

In my game I just check the device type and if it is Android I set the height in native.newTextField to double

Roy

Hey, any update on this?

I was experiencing the exact same behavior (using build 3046, latest) and found this post.

I’m using a similar workaround (height 1.5 times as big as it should be), but would be nice to have this fixed.

Best regards,

jaime

Are you calling this: https://docs.coronalabs.com/daily/api/type/TextField/resizeFontToFitHeight.html

If not, you should be.

BTW: You can’t rely on the simulator for native.* testing.  You must check on the real OS targets.

If you’re running the simulator on OS X, then all simulated devices are using the OS X native text field.  

If you’re running the simulator on Windows, then all simulated devices are using the Windows native text field.  

The only way to get the Android or iOS Native text field is to test on device.

I was not calling but that’s supposed to be the default behavior - the blog post mentions:

“The first of these functions (object:resizeFontToFitHeight()) is useful if you change the input field’s height sometime after the field is created, and you want to resize the font to fit within the field”

I checked anyways and changed the code to:

 InputBox = native.newTextField( 320, \_G.yMin + 300, 240, 30 ) InputBox:resizeFontToFitHeight() native.setKeyboardFocus( InputBox ) InputBox:addEventListener( "userInput", onKeyboard ) FadeView:insert(InputBox) 

but same problem

I just noticed you added to your comment - this testing is being done on the device, a Samsung Galaxy S3 - the screen shot I posted is grabbed directly from the device.  On the simulator (and on every iOS device I have tested on) it does look ok.

Thanks,

Roy

Roy,

  1. Hi.  I didn’t read the article, sorry.  If it says that is the default behavior AND if the docs agree (may have changed since the blog), then  you should file a bug.

  2. If ‘resizeFontToFitHeight()’ didn’t work I’d make a small sample test case, verify it still fails to behave properly, then submit a bug.

  3. Device versus Simuated - Yeah, I always edit after posting to clean up and add more thoughts.  I like a nice clean post.  Please note.  The point I was making is you cannot depend on what you see in the simulator.

Filing A Bug (https://developer.coronalabs.com/content/bug-submission)

You’ll be asked for an example demonstrating the problem.  It should have main.lua, config.lua, and a basic build.settings file.  You will package this in a ZIP and attach it to the bug report.

If you do this, you may as well share a link to the zip file here too. That way others can test it and give feedback if they have time to help.

Cheers,

Ed

You should also consider posting a link to the test case here.  It should have main.lua, config.lua, and a basic build.settings.  It should also demonstrate just this problem.  That way we are all sure we’re testing the same thing.  

(Note: You’ll need this for your bug submission anyways.)

PS - I forgot to ask, but you’re using a current version of Corona right?

So I created a test project and of course found the issue almost right away - I believe it’s a bug since the goal of the changes from that blog post are to make the newTextField behave like display.newText on all devices

In config.lua if you set width and height to the default of 320x480 then it works as expected but if you set it to 640x960 (like I have with my project) then you get the problem where native.newTextField is half as big as the display.newText equivalent (but only on Android devices or at least the Samsung Galaxy S3 which is the only one I have to test on)

I take it that nobody sets their project to 640x960 otherwise this would be a more common issue.  I set my project to 640x960 when I started working on it ages ago to get more granular placement of things - not sure if it makes any difference but to go back and change everything would be a huge pain!

I can code a workaround now at least - is this worth submitting a bug for?

Thanks again for the help

Roy

Roy,

You forgot to share a link to your sample.  I’d love to look at it, before you file a bug.

I’m not convinced what I’m hearing is a bug.  Note: You cant’ rely on the blog post as ‘it should work this way’, but rather on what the API docs say.  

PS - I use 640x960 or larger as my primary size, but I don’t use text fields much.

PPS - Reading the first part of the article, I would agree with you that (even though I don’t see the same statements in the API docs after a quick look) this seems like a bug.

I’ll submit the bug to Corona, really easy to duplicate

Main.lua is just this:

local InputBox = native.newTextField( 160, 100, 240, 30 ) native.setKeyboardFocus( InputBox )

In the config.lua if you set width and height to 320x480 then it looks great on the Android device, if you set it to 640x960 it looks microscopic.  On all iOS devices 320x480 and 640x960, the text size looks the exact same.

In my game I just check the device type and if it is Android I set the height in native.newTextField to double

Roy

Hey, any update on this?

I was experiencing the exact same behavior (using build 3046, latest) and found this post.

I’m using a similar workaround (height 1.5 times as big as it should be), but would be nice to have this fixed.

Best regards,

jaime