I feel stupid... not only that I had to program some "fake newTextField" routines to not constantly have to go back to the device for placement and usability tests...
No ... I also try to find how to remove those fields from the display since an hour...
Is there a bug that you can remove those?
It s mentioned that they do not behave to standard display object hierarchy... ok...
Can we please get a replacement function in the simulator (which looks like.. but not actually needs to be the original)
And please document how to deallocate them.. Just moving them to hide them .. is ugly...
May I ask you to try that? I bet you never did....
I would not file a bug if that would work...
And obj.parent:remove(obj) or obj:removeSelf() would be a better general recommendation for display objects ... Later on still used by devs in the forum and still not documented it seems.
My guess is that they are NOT in "yourGroup". They do not obey to the display object groups... But there should be a way to deallocate or to remove them from the stage... But I repeat myself...
What's up!? Can we please continue to evaluate this problem and having it fixed?
Your guess is right OderWat, they are not in "yourGroup", that's why you cannot remove them
If you insert a text field in a group, and set the x coordinate of the group to 320, the text field should not show up on the screen, yet it does...
I also noticed that whenever i tap on the field to type, on the Organizer console i get the message:
Mobile Safari warning, Safari got memory level warning, killing all documents except active...
There are no other elements, other than the text field, to consume memory
The native.newTextBox has the same problem
You insert it in a group, you place the group off the screen, but the TextBox shows up as if group.x were 0
Yep.. This is "documented" and was expected by me (hence their "does not obey to object hierarchy").
I do not care about this... I care about a way to remove it from the stage and deallocate it.
The whole "my guess" part tries to give Gilbert a "hint" ... and he may need to inform himself about the facts before he answers a "bug report" that way. I am really getting upset about this kind of replies lately. I still try to be calm and not return the favor to obviously.
Still there is no bug id assigned or any other helpful information given...
I want a big "escalation" button which sends stuff to actual developers which care about their baby...
Sorry about that. I escalated this. It's filed as bug #301.
NativeUI objects can't be removed in any way. You must hide them using isVisible=false.
I've filed the bug to provide a way to remove them.
Thanks,
Gilbert
Thank you Gilbert! Much appreciated!
@OderWat, We are working to resolve bugs like this and bugs that crash the simulator/device ASAP.
@OderWat,
Can you provide some sample code showing the problem where the textField is not removed from the group?
I'm playing with a fix but can't find a test case under Beta 6 where the native.textField is not removed.
Thanks,
Tom
Hey Tom,
I sent you this test code in an email.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | myGroup = display.newGroup() --Add a text field to the screen myTextField = native.newTextField( 0, 0, display.contentWidth*.6, 25) myGroup:insert(myTextField) myTextField.x = display.contentWidth/2 - myTextField.width/2 myTextField.y = display.contentHeight/3 --Add a button myButton = display.newGroup() buttonColor = display.newRoundedRect(0, 0, 200, 40, 20) buttonColor:setFillColor(255, 0, 0) myButton:insert(buttonColor) buttonText = display.newText("Remove TextField", 0, 0, native.systemFontBold, 14) buttonText:setTextColor(255, 255, 255) myButton:insert(buttonText) buttonText.x = myButton.width/2 buttonText.y = 18 myButton.y = display.contentHeight/2 myButton.x = display.contentWidth/2 - myButton.width/2 --Add a button2 myButton2 = display.newGroup() button2Color = display.newRoundedRect(0, 0, 200, 40, 20) button2Color:setFillColor(255, 0, 0) myButton2:insert(button2Color) button2Text = display.newText("Hide TextField", 0, 0, native.systemFontBold, 14) button2Text:setTextColor(255, 255, 255) myButton2:insert(button2Text) button2Text.x = myButton2.width/2 button2Text.y = 18 myButton2.y = myButton.y + myButton.height + 20 myButton2.x = display.contentWidth/2 - myButton.width/2 function dismissTextField(event) if(event.phase == "ended") then myGroup:remove(myTextField) --myTextField = nil buttonText.text = "Removed?" end end myButton:addEventListener("touch", dismissTextField) function hideTextField(event) if(event.phase == "ended") then myTextField.isVisible = not myTextField.isVisible button2Text.text = "Show TextField" end end myButton2:addEventListener("touch", hideTextField) |
Hi Gilbert,
Thanks for the code. The problem is this code works in Beta 4, 5, and 6. If I click on the "Remove TextField" button, the textField disappears (as it should).
This code does have a problem because there is no listener for the textField and therefore no way to dismiss the keyboard (which hides the buttons).
I added this code to remove the keyboard after pressing Return.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | local function fieldHandler( event ) if ( "began" == event.phase ) then -- This is the "keyboard has appeared" event -- In some cases you may want to adjust the interface when the keyboard appears. elseif ( "ended" == event.phase ) then -- This event is called when the user stops editing a field: for example, when they touch a different field elseif ( "submitted" == event.phase ) then -- This event occurs when the user presses the "return" key (if available) on the onscreen keyboard -- Hide keyboard native.setKeyboardFocus( nil ) end end |
I added the listener to the text field.
1 | myTextField = native.newTextField( 0, 0, display.contentWidth*.6, 25, fieldHandler) |
It never worked in the past ... I did not try it again with beta 6 yet. may do so tomorrow.
Tom,
this doesn't work in Beta 5
the text field is not removed
and if you replace myTextField.isVisible = not myTextField.isVisible
with myGroup.x=100, the text field doesn't move even though it belongs to myGroup.
you can hide it by using
myTextField.isVisible=false or
myTextField.x=500
but it cannot be removed, and it behaves as if it doesn't actually belong to the group.
the way it is right now, there's no meaning into inserting a native text field in a group.
Okay, I was wrong. It turns out I was testing with a version of the SDK that fixed the "removal" issue. I was attempting to prove that the previous versions didn't work and couldn't. I guess that proves the upcoming fix DOES work.
I have verified that the test code does fail in beta 6 and works in the upcoming beta version. Stay tuned.
-Tom
@tetu,
The fix will allow you to remove native.textField/textBox from the screen with object:selfRemove().
The Corona documentation states that the native objects do not obey the Corona display object hierarchy nor do they inherit display group properties (i.e. isVisible, x, y, and alpha). You still need to set the properties on the native objects directly. That part hasn't changed.
When objects (native or otherwise) are created, they are part of the current stage, which is a group. Since the native objects don't inherit any of the group properties, it doesn't make sense to add them to another group. Generally they would be displayed temporary (i.e. to input some text) and then dismissed.
-Tom
The following code doesn't work :
choix_single = native.newTextField( 20, 60, 280, 30, fieldHandler )
choix_single:selfRemove()
I have the following error message : attempt to call method 'selfRemove' (a nil value)
What's wrong with this code ?
Thanks in advance !
(nb : of course, I've made the fieldHandler listener in my textField)
I guess you are trying this on the simulator.
The simulator does not support "native.newTextField()" and the "replacement" table which is returned does not contain "removeSelf()".
It seems like they want to program a stub for this functionality on the simulator and that is not finished yet.
You need to check if you are on the device and may use your own replacement function otherwise!
Try choix_single:removeSelf()
That should work better. :)
-Tom
@Tom ... lol... yeah! 1:0 :)
Is it possible to limit the number of characters entered into the native.newTextField( 20, 60, 280, 30, fieldHandler )?
I want to limit to only 8 characters in the native.newTextField, is this possible?
Try using
yourGroup:remove(yourTextFieldObject), where "yourGroup" is a group that contains the text field.-Gilbert