newtextfield.text appears only when user clicks on it

Dear Corona community,

In my scene:create function, I set up a newTextfield:

usernameInput = native.newTextField(display.contentCenterX, galleryButton.y - galleryButton.contentHeight - 10, display.contentWidth - 60, 50) usernameInput.font = native.newFont(native.systemFontBold) usernameInput.hasBackground = false usernameInput:setTextColor(0.35) usernameInput.align="center" usernameInput.anchorY = 1 usernameInput.text = "Test"

Problem is: I see “Test” only when I click on the textfield. It sort of swipes in from the right side. I want it to be there from the beginning on though. It works fine on simulator, but not an Honor 8 or Galaxy S5 mini.

Any ideas?

// edit: Wow, narrowed it down to the line

usernameInput.align=“center”

If I leave it out, the username shows right away when the scene appears (positioned on the left side, as expected). But when I insert this line, the username only appears when I click on the textfield (positioned centered).

To me this does not make sense at all. Did I miss something? Why would aligning input text have such an impact on when the text appears on screen?

Text input will vary across operating systems. Most text input is left aligned. Centering it seems like it could be a little weird.

Rob

All right, not the answer I was hoping for, but thank you Rob for clarifying.

If anybody had an idea how to bypass this behaviour, I’d appreciate any hints :slight_smile:

/edit: Wow, what a weird behaviour. For testing purposes, I used

align="left"

in the :create function, and a

timer.performWithDelay(500, function() usernameInput.align=“center” end)

in the “show:did - phase”.

On my two android devices, the username is shown left-aligned and then, once timer kicks in, it disappears and only reappears when user clicks on the textfield.

Sorry for the answer Christopher. It’s really hard to discuss specifics without a lot of details and trying to understand your goals. Right now my capacity to try and investigate these is somewhat limited given I only have one Android tablet and I don’t have a project to look at and see what’s happening.

So I’m left with some generalities and sometimes I’m left to draw conclusions from that.

I could suggest that you look at our native.newTextField() sample app in Corona/SampleCode/Interface/NativeKeyboard and see how that behaves.

Rob

Rob, didnt mean to offend you in any way, sorry if there was a misunderstanding. I was just hoping that I did something wrong and could achieve my center-alignment by changing a simple line or something :slight_smile:

I just created a new project and this is my main.lua

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- -- Your code here local defaultField local function textListener( event ) if ( event.phase == "began" ) then -- User begins editing "defaultField" elseif ( event.phase == "ended" or event.phase == "submitted" ) then -- Output resulting text from "defaultField" print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end -- Create text field defaultField = native.newTextField( 150, 150, 180, 30 ) defaultField:addEventListener( "userInput", textListener ) defaultField.align = "center" defaultField.text = "blub"

This is the sample code from here

I just added the lines

defaultField.align = "center"

defaultField.text = "blub"

Same result: In the simulator this works perfectly. As soon as the app gets launched, I see the “blub” centered. But when I launch it on my android devices, I get an empty text field. Only when I click on it, the “blub” appears.

If I leave out the

defaultField.align = "center"

“blub” is shown instantly, left-aligned, and no tap on the field is necessary. Hope it gets clearer now.

To me, this seems like a bug. But I understand all those difficulties you guys from Corona have with native, so I try to find a workaround…

/edit: Tested on Honor 8, Galaxy S5 mini and Samsung Tab S8. They all show a blank textfield when the app gets started. “Blub” only apears when user taps on textfield.

Can you make a complete project for this (main.lua, build.settings, config.lua) and drop it into a .zip file?

Thanks

Rob

There you go. Thanks for having a look :slight_smile:

I ran it on my Google Nexus 9 (Android 7) and it works like you expect it would.  “Username” was in the field when it started and stayed there as I tapped on the field.

I’ll see if I can get some additional testing on this.

Rob

We had someone else test on a couple of Android devices, but both are running more modern OS’s and it’s working as expected.  At that point, perhaps you should go ahead and file a bug report. 

Rob

Thank you for your efforts Rob. Hm, interesting. As I said, on all my three Android devices (even on my Honor 8) the “username” only shows up when I tap on the textfield.

Might I ask you to upload the .apk file that you put on your devices? I’d like to try exactly the same version that you install.

In the meantime I’ll read on how to file a bug report…

https://www.dropbox.com/s/jcarl6t3a15ibt1/testapp.apk?dl=0

Ok, now I’m completely confused. Your version works perfectly.

So, to crosscheck afterwards, I recompiled my version and send it to my phone. Doesnt work, “username” does not appear.

How can this happen? As far as I know, the actual compilation happens on your servers. Why would the server compile my code different from yours (which is exactly the same as mine)?

Any ideas where to look at or what to do? :slight_smile:

What version of Corona are you using?

Rob

Corona Simulator 2017.3135 (2017.9.7)

I’m using 3157.

There have been text field fixes since 3135.

Rob

3.1.59 did the trick :slight_smile:

3135 was the latest public release, thats why I had this version.

So, problem solved, thank you very much Rob :slight_smile:

Text input will vary across operating systems. Most text input is left aligned. Centering it seems like it could be a little weird.

Rob

All right, not the answer I was hoping for, but thank you Rob for clarifying.

If anybody had an idea how to bypass this behaviour, I’d appreciate any hints :slight_smile:

/edit: Wow, what a weird behaviour. For testing purposes, I used

align="left"

in the :create function, and a

timer.performWithDelay(500, function() usernameInput.align=“center” end)

in the “show:did - phase”.

On my two android devices, the username is shown left-aligned and then, once timer kicks in, it disappears and only reappears when user clicks on the textfield.

Sorry for the answer Christopher. It’s really hard to discuss specifics without a lot of details and trying to understand your goals. Right now my capacity to try and investigate these is somewhat limited given I only have one Android tablet and I don’t have a project to look at and see what’s happening.

So I’m left with some generalities and sometimes I’m left to draw conclusions from that.

I could suggest that you look at our native.newTextField() sample app in Corona/SampleCode/Interface/NativeKeyboard and see how that behaves.

Rob

Rob, didnt mean to offend you in any way, sorry if there was a misunderstanding. I was just hoping that I did something wrong and could achieve my center-alignment by changing a simple line or something :slight_smile:

I just created a new project and this is my main.lua

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- -- Your code here local defaultField local function textListener( event ) if ( event.phase == "began" ) then -- User begins editing "defaultField" elseif ( event.phase == "ended" or event.phase == "submitted" ) then -- Output resulting text from "defaultField" print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end -- Create text field defaultField = native.newTextField( 150, 150, 180, 30 ) defaultField:addEventListener( "userInput", textListener ) defaultField.align = "center" defaultField.text = "blub"

This is the sample code from here

I just added the lines

defaultField.align = "center"

defaultField.text = "blub"

Same result: In the simulator this works perfectly. As soon as the app gets launched, I see the “blub” centered. But when I launch it on my android devices, I get an empty text field. Only when I click on it, the “blub” appears.

If I leave out the

defaultField.align = "center"

“blub” is shown instantly, left-aligned, and no tap on the field is necessary. Hope it gets clearer now.

To me, this seems like a bug. But I understand all those difficulties you guys from Corona have with native, so I try to find a workaround…

/edit: Tested on Honor 8, Galaxy S5 mini and Samsung Tab S8. They all show a blank textfield when the app gets started. “Blub” only apears when user taps on textfield.