How to set native PeerComponent Look and feel from CN1 code.

20 views
Skip to first unread message

Hasni Faiçal

unread,
Nov 4, 2019, 5:02:52 AM11/4/19
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA
Desktop OS
Simulator
Device

1- I created a nativeCall to return a PeerComponent as a (UITextField, EditText) for iOS and android respectively.
How to add look and feed for this text field to look the same as CN1 TextField?
2- Is there any way to interact with this native TextField (eg. setting hint) without implementing this behavior in native code?
3- Is there any way to access UITextField and EditText from CN1 TextField in native code?

Steve Hannah

unread,
Nov 4, 2019, 7:42:45 AM11/4/19
to codenameone...@googlegroups.com
When you create a native component, it's up to you to "style" it.  You might want to check out the cn1-native-controls cn1lib as a reference, as I include a native text field component with it.


The strategy that I used here was to add a method to the native interface "updateStyles()", which, when called, updates the styles of the native component based on the styles assigned to its lightweight container.


Note;  I don't recommend creating your own native text field unless you have a really good reason.  There are all kinds of complexities around making native text fields work properly, and the built-in TextField and TextArea components already take care of all of these things for you.

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/a691e1bf-8daa-4e13-be60-b4e6d677a43c%40googlegroups.com.


--
Steve Hannah
Software Developer
Codename One

Hasni Faiçal

unread,
Nov 5, 2019, 5:43:53 AM11/5/19
to CodenameOne Discussions
Thank you for your advice, I am using a native library(android, iOS) that requires a native UITextField/EditText as input, that's why I created a native textfield.

I don't know if is it possible to get access to TextField in native code as UITextField/EditText, if this the case no need to create this native TextField. and i will use this in my native code.

On Monday, November 4, 2019 at 1:42:45 PM UTC+1, Steve Hannah wrote:
When you create a native component, it's up to you to "style" it.  You might want to check out the cn1-native-controls cn1lib as a reference, as I include a native text field component with it.


The strategy that I used here was to add a method to the native interface "updateStyles()", which, when called, updates the styles of the native component based on the styles assigned to its lightweight container.


Note;  I don't recommend creating your own native text field unless you have a really good reason.  There are all kinds of complexities around making native text fields work properly, and the built-in TextField and TextArea components already take care of all of these things for you.

On Mon, Nov 4, 2019 at 2:02 AM Hasni Faiçal <hasni....@gmail.com> wrote:
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA
Desktop OS
Simulator
Device

1- I created a nativeCall to return a PeerComponent as a (UITextField, EditText) for iOS and android respectively.
How to add look and feed for this text field to look the same as CN1 TextField?
2- Is there any way to interact with this native TextField (eg. setting hint) without implementing this behavior in native code?
3- Is there any way to access UITextField and EditText from CN1 TextField in native code?

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.

Shai Almog

unread,
Nov 5, 2019, 9:46:20 PM11/5/19
to CodenameOne Discussions
Unfortunately that isn't practical as we create/discard these fields dynamically as needed.
Reply all
Reply to author
Forward
0 new messages