Search Unity

Advanced Input Field

Discussion in 'Assets and Asset Store' started by fennecx_development, Jul 29, 2017.

  1. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    General Note:
    Version 2.0.0 is available on the AssetStore. Current 1.9.* versions will still be updated with bugfixes, but new features will be implemented in version 2 of the plugin. So, if you are starting a new project it's better to use version 2 of the plugin.

    The upgrade to version 2 of the plugin is free for existing users.
    Support thread for version 2


    Upgrade Notes when upgrading from an earlier version than 1.6.0 to 1.6.0 or newer.:

    Following files and directories should be removed before importing new package:
    - Plugins/Scripts/Helper/PointerListener.cs

    The format/structure has changed to support both Unity and TextMeshPro Text Renderers. This means that AdvancedInputField instances made with an earlier version than 1.6.0 are deprecated and should be converted with the included ConversionTool (located in the "Advanced Input Field" dropdown).

    UWP Note:
    Please use XAML as build type, D3D seems to give issues.

    General:
    While I was developing a mobile app I noticed that default Unity InputField behaved differently than I would expect on Android & iOS. Also there were differences in behaviour on Android & iOS. Some implementations were had to realize, such as filling in a form inside a ScrollRect easily. Pressing the inputfield (to drag inside the ScrollRect) would show the TouchScreenKeyboard, making scrolling inside the ScrollRect annoying.

    This plugin started as only a new native binding for the TouchScreenKeyboard, but in the end a reimplementation of the InputField was needed too (to handle some other annoying issues/bugs) and to add new features.


    Advanced Input Field:
    Asset Store Link

    Android samples:
    These are builds (apk) of the Sample scenes of the plugin build using the latest version of the plugin.
    Samples (Android)

    This plugin is a custom implementation of the Unity Input Field (it still inherits from Selectable base class). It adds several features and fixes multiple bugs that were in the original Unity Input Field. The logic has been split over multiple (platform specific) classes to improve readability. For Mobile platforms (Android, iOS & UWP) a whole new implementation has been written, because these were the platforms with the most annoying bugs. Also new bindings for the native keyboards on Android, iOS & UWP have been added to control more keyboard settings.

    Supported platforms:
    PC, Mac, Android, iOS & UWP (Smartphone, Tablet & PC)

    Features:
    - Default features on the original Unity InputField
    - Process edited text on deselect (using PostProcessingFilters)
    - Next Input Field option to control which InputField should be selected when done editing. (Tab key
    on Standalone platforms and Done/Next key on Mobile platforms).
    - Mobile only: Show ActionBar with cut, copy, paste and select all options
    - Mobile only: Selection Cursors (Draws selection sprites for start and end of text selection to control
    the selected text more easily in large text blocks)
    - Gestures for Mobile added: Single Tap: show ActionBar (if enabled)
    Double Tap: Select word
    Hold: Select word + show ActionBar (if enabled)
    - Event for keyboard height changes in the new NativeTouchScreenKeyboard binding.
    - Added a KeyboardScroller component to scroll content when TouchScreenKeyboard appears/hides.
    - Support for TextMeshPro Text Renderers
    - Multiple InputField Modes (indicates how to handle text bounds changes): SCROLL_TEXT, HORIZONTAL_RESIZE_FIT_TEXT and VERTICAL_RESIZE_FIT_TEXT

    Feel free to contact me for feature requests and reporting bugs.
    Please check the Trello board of the plugin before reporting bugs/asking for features:
    Trello board

    Changelog:
    Pastebin link
     
    Last edited: Jan 11, 2021
    GamerPET likes this.
  2. reese015

    reese015

    Joined:
    Nov 29, 2014
    Posts:
    34
    Hello and first of all thank you for this amazing Plugin! So far I am really happy with it, but there is something that I'd like to know. Currently the OnEndEdit function gets called when the inputfield is deselected so also when I dont press enter/done. Id only like it to get called when I submit and not when I just deselect it. Is this possible? and if so could you please help me to achieve this?
     
  3. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    It should be possible as both events are handled separately internally in the plugin. OnDeselect event gets called from Unity side and OnKeyboardDone event gets called from Native (Android/iOS) side.
    I'll try to add a parameter to the OnEndEdit UnityEvent. Probably something named like "endEditReason".
     
    reese015 likes this.
  4. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    This patch should do the job ;)

    Example:
    Code (CSharp):
    1. public void OnInputEnd(string result, EndEditReason reason)
    2. {
    3.          if(reason == EndEditReason.KEYBOARD_DONE || reason == EndEditReason.KEYBOARD_NEXT)
    4.          {
    5.  
    6.          }
    7. }
    Please report back if working properly, so I can add it in the main version
     

    Attached Files:

    Ardito92ITA likes this.
  5. eximarus

    eximarus

    Joined:
    Apr 14, 2017
    Posts:
    1
    this works like a charm! exactly what I needed. this will be a easy 5 star review
     
    fennecx_development likes this.
  6. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    Version 1.0.2 Released:
    • Changed event callback signature for OnEndEdit(String) to OnEndEdit(String, EndEditReason)
      EndEditReason is a enum that specifies the reason for ending edit mode(Deselect, Keyboard Cancel, Keyboard Done, Keyboard Next)
    • Bugfix Android: Back key dismisses keyboard properly now
     
  7. jluki

    jluki

    Joined:
    Aug 11, 2013
    Posts:
    24
    Hi,

    I would need a UWP solution :) Are there any plans to extend AdvancedInputField in this direction?
     
  8. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    There weren't any plans yet to support UWP, but I'm willing to look into it. Haven't worked with UWP in Unity before.
    What are your target devices, because UWP covers multiple types of devices? Phone, Tablet, PC?
     
  9. jluki

    jluki

    Joined:
    Aug 11, 2013
    Posts:
    24
    My target devices are Tablet and PC.
     
  10. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    That should be manageable. Other device types like Xbox and HoloLens would be more difficult.
    I have a Surface Pro Tablet/PC, so I can use that for testing. For completion sake I would also need to test on a Phone. I'll see if I can get a test phone somewhere.

    I'll try to experiment a bit with UWP when I have time this weekend to see how easily I can make a native TouchScreenKeyboard binding for that platform.
     
  11. jluki

    jluki

    Joined:
    Aug 11, 2013
    Posts:
    24
    Great news! :) Thank you very much for your efforts!
     
  12. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    Just a small update: UWP binding is mostly working. Still need to fix some platform specific issues like handling change between tablet mode and pc mode. I'll probably submit a new package to the Asset Store next week.
     
  13. jluki

    jluki

    Joined:
    Aug 11, 2013
    Posts:
    24
    These are really good news! Thank you very much! :)
     
  14. elviz3k

    elviz3k

    Joined:
    Dec 4, 2013
    Posts:
    1
    Hello,

    We tried using your solution for input field and it works ok only for Single Line (Line Type). If we select "Multi Line Newline" it does not work (Android):
    - When you move to a next line and start typing the upper line will just disappear
    - It's not possible to scroll (it feels that the upper line is deleted)
    - The "caret" position has around -28.0f offset on Y (is just upper than normal and it looks strange)
    - If you keep pressing back to delete characters you will hit an "Index out of range" and eventually a "Null ref" that will cause a crash (at least on Android).

    Are you planning to support multi line any time soon?

    Thank you!
     
  15. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    This will probably take some time. I'll put it on my TODO list for this plugin, so I won't forget to look into it.
     
  16. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    Version 1.1.0 has just been released.
    It includes UWP support and fixes some other issues.
     
  17. jluki

    jluki

    Joined:
    Aug 11, 2013
    Posts:
    24
    That's really great! I'll try this on weekend. Thank you very much for releasing UWP support that quickly.:)
     
  18. by342854406

    by342854406

    Joined:
    Mar 12, 2017
    Posts:
    4
    I set character limit 0 and single line , when the text I entered is out of view scope, the text displayed is a problem. The text content does not move to the left.
     
  19. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    That looks like it will be annoying to the end user. I'll try to fix this ASAP and I'll probably post a patch here in this thread. Asset Store approval usually takes longer.
     
  20. jluki

    jluki

    Joined:
    Aug 11, 2013
    Posts:
    24
    Just to give an update: I cannot compile because I've updated to VS 2017.3 and am waiting for a patch for unity.:(
     
  21. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    An update on this issue: I managed to fix it on PC and partly on Android, but if the user rapidly enters keys on Android it causes other glitches now.
    This is probably caused by Unity's Text component not being updated properly on time (It's not possible to force a text update immediately). The plugin currently uses coroutines to wait for next frame, which doesn't always seems to work properly when a lot of events are executed.

    I'll need to rewrite some internal methods of the plugin to handle events better, so it will probably take a while longer to fix this completely.

    Sorry for the delay
     
  22. Gustavo-Quiroz

    Gustavo-Quiroz

    Joined:
    Jul 26, 2013
    Posts:
    38
    Hello,

    Do this plug in removes the annoying text box in the Android Keyboard?
    Is it compatible with Text Mesh Pro or Material UI?
     
  23. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    1. Yes, That text box attached to the Android keyboard is removed:


    2. No, there isn't a binding for other text rendering plugins yet. Will probably look into a binding for Text Mesh Pro eventually.
     
    Gustavo-Quiroz likes this.
  24. GGeff

    GGeff

    Joined:
    Nov 11, 2014
    Posts:
    40
    Issue 1:
    I'm getting a compile error:

    G:\MyApp\Temp\StagingArea\AndroidManifest-main.xml:4:92-124 Error:
    Attribute application@label value=(@String/app_name) from AndroidManifest-main.xml:4:92-124
    is also present at AndroidManifest.xml:13:9-44 value=(TouchScreenKeyboard).
    Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest-main.xml:4:3-12:17 to override.

    I can fix this by using an overiding AndroidManifest.xml in Assets/Plugins/Android/ containing the suggested line from above, however, it would be preferable to be able to use the addon with the Unity autogenerated manifest.

    Issue 2:
    When I set the .Text of an AdvancedInputField via script, it is still displaying the placeholder text until I click the box. Do I need to force it to update somehow?
    Edit: this is because I'm modifying the .Text prior to the Advanced Input Field being initialized. I can work around it.
     
    Last edited: Sep 5, 2017
  25. GGeff

    GGeff

    Joined:
    Nov 11, 2014
    Posts:
    40
    What is the proper way to programmatically select, ie focus on, an Advanced Input Field? There is no ActivateInputField() and Select() is an empty override.

    All my tests have been with the InputField prefab located in Plugins/Advanced Input Field/Prefabs
     
    Last edited: Sep 5, 2017
  26. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    For issue 1: I'm guessing you are using a Mac for the Android build, another user reported it too via personal message.
    The fix will be included in next release. But you can replace the file manually. Replace the file TouchScreenKeyboard.aar in Assets/Plugins/Android with the one in the attached rar.

    For issue 2: I'll see if I show can show changed Text before the Initialization happens.

    For issue 3: I needed to override the normal Select() behaviour to prevent Unity from reselecting when it shouldn't. I'll try to add a public method to select in programmatically.

    Not sure yet if I can fix it all before next release, next release candidate is in testing phase right now. So I'll probably submit that one first when if it's ready.
     

    Attached Files:

    Last edited: Sep 5, 2017
  27. ChisomoMbeza

    ChisomoMbeza

    Joined:
    Jun 14, 2017
    Posts:
    15
    Hello

    I have a problem in unity whereby the unity input fields fill up the memory whenever on is opened, even after closing the field the memory is still used up so after some usage the application slows down, most notably when I open the AR camera which is extremely slow(this is an issue unity has not solved), I tried the native edit plugin which actually does work, the app continues to run smoothly long after the the fields have been opened, filled in and closed but the problem with that was that if the field is low enough that the keyboard will have to move the UI up on the screen so that the input field is visible as the user types the text becomes invisible. Would your asset Advanced Input Fields be able to get around this issue?
     
  28. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    If you need something to detect when the TouchScreenKeyboard appears/height changes, then yes, there's functionality for that in the plugin.
    For the native keyboards of Android, iOS & UWP (phone & tablet) there a method to register for keyboard height changes:
    Code (CSharp):
    1. NativeTouchScreenKeyboard.AddKeyboardHeightChangedListener(OnKeyboardHeightChanged);
    It will send the keyboard height in pixels to the registered method.
    In the sample scene there also an example on how to use this value to scroll a ScrollRect.

    Memory wise haven't really tested thoroughly yet, but the plugin should only allocate RAM when functionality is accessed the first time.
    For example: On Android when the first inputfield gets selected it will create an instance of the Android native keyboard binding and keeps that in the RAM, so that other inputfields can use that instance too.
     
  29. ChisomoMbeza

    ChisomoMbeza

    Joined:
    Jun 14, 2017
    Posts:
    15
    Zoom.jpg
    The focus isn't the problem.


    Check What happens in the screenshots Before_Focus.png After_Focus.png
     
  30. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    I'm sorry if I don't understand correctly, but the issue is that the plugin you're using currently has invisible text when editing on Android, right?
    In my plugin "Advanced Input Field" it just keeps rendering the text of the inputfield whenever the TouchScreenKeyboard appears and whenever the users presses a key on that keyboard. (if that was your question)
     
  31. ChisomoMbeza

    ChisomoMbeza

    Joined:
    Jun 14, 2017
    Posts:
    15
    is it native keyboard?
     
  32. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    Yes, this plugin has it's own bindings for the native keyboards of Android, iOS & UWP.
    This project/plugin actually started because of the fact that the API Unity itself provides for the native TouchScreenKeyboard was too limited for my use cases ;)
     
  33. ChisomoMbeza

    ChisomoMbeza

    Joined:
    Jun 14, 2017
    Posts:
    15
    It does sound like it might be able to solve my problem
     
  34. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    Version 1.2.0 has just been released.
     
  35. toddfiore

    toddfiore

    Joined:
    Dec 16, 2016
    Posts:
    12
    Plugin seems to be unusable when the object is instantiated at runtime. Whenever I begin typing I keep getting this exception and the input stops working:

    NullReferenceException: Object reference not set to an instance of an object
    AdvancedInputField.TextNavigator.UpdateCaret () (at Assets/Plugins/Advanced Input Field/Scripts/InputField/TextNavigator.cs:455)
    AdvancedInputField.TextNavigator.set_CaretPosition (Int32 value) (at Assets/Plugins/Advanced Input Field/Scripts/InputField/TextNavigator.cs:94)
    AdvancedInputField.TextNavigator.MoveCaret (Int32 amount) (at Assets/Plugins/Advanced Input Field/Scripts/InputField/TextNavigator.cs:749)
    AdvancedInputField.TextManipulator.Insert (Char c) (at Assets/Plugins/Advanced Input Field/Scripts/InputField/TextManipulator.cs:157)
    AdvancedInputField.StandaloneTextInputHandler.TryInsertChar (Char c) (at Assets/Plugins/Advanced Input Field/Scripts/InputField/StandaloneTextInputHandler.cs:162)
    AdvancedInputField.StandaloneTextInputHandler.ProcessKeyboardEvent (UnityEngine.Event keyboardEvent) (at Assets/Plugins/Advanced Input Field/Scripts/InputField/StandaloneTextInputHandler.cs:145)
    AdvancedInputField.StandaloneTextInputHandler.Process () (at Assets/Plugins/Advanced Input Field/Scripts/InputField/StandaloneTextInputHandler.cs:39)
    AdvancedInputField.AdvancedInputField.OnUpdateSelected (UnityEngine.EventSystems.BaseEventData eventData) (at Assets/Plugins/Advanced Input Field/Scripts/InputField/AdvancedInputField.cs:788)
    UnityEngine.EventSystems.ExecuteEvents.Execute (IUpdateSelectedHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:99)
    UnityEngine.EventSystems.ExecuteEvents.Execute[IUpdateSelectedHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
    UnityEngine.EventSystems.EventSystem:Update()

    Same thing on Android. Is this intended?
     
  36. toddfiore

    toddfiore

    Joined:
    Dec 16, 2016
    Posts:
    12
    Also, how do I disable the giant pointer on mobile. Its huge and completely unnecessary, that is what the caret is for.
     

    Attached Files:

  37. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    For issue 1:
    Just to make sure: You created an Advanced Input Field using the menu dropdown: Advanced Input Field => Create InputField and then made a prefab of the gameobject?
    Based on the error it looks it's missing the reference to the caret renderer.

    For issue 2:
    The mobile caret selector should adjust correctly the physical screen of the device. In your screenshot I noticed that it's way to huge on your device. That's something I need to look into (testing and compare on more Android devices).

    As for the selector itself. It's normally used to show the action bar with options like cut, copy, paste, select all. But if you don't need those, I can understand you want it gone.
    I'll change it in the plugin to just hide/disable it when the "mobile only" options on the InputField aren't enabled.
     
  38. toddfiore

    toddfiore

    Joined:
    Dec 16, 2016
    Posts:
    12
    For issue 1:
    You can even reproduce it in your demo scene. Make a prefab out of the FormView object, run the game and drag the Object into the scene, when you start typing you'll get the null exceptions.

    For issue 2:
    For reference I've attached my Canvas settings which Im guessing is the problem. Is there anyway to control how big the caret is on mobile? And if not is there anyway to disable it?
     

    Attached Files:

  39. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    I fixed the first issue and for the second issue I just disabled it when none of "mobile only" options are enabled.
    Use the attached package to patch those issues.
     

    Attached Files:

  40. toddfiore

    toddfiore

    Joined:
    Dec 16, 2016
    Posts:
    12
    Its fixed when using the editor but is still broken on mobile. Tested on an Android. The box wont show any placeholder text and is unselectable when instantiated in the scene. I've attached the exception but it doesn't have line numbers.
     

    Attached Files:

  41. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    Sorry. I thought I tested it on Android too. I could reproduce and fix it for Android.

    Small side note: If you want to see the line numbers on Android you have to enable "development mode" in Unity when building for Android.
     

    Attached Files:

  42. toddfiore

    toddfiore

    Joined:
    Dec 16, 2016
    Posts:
    12
    Sorry to keep bringing you bad news but it doesn't build on iOS. I get a "Linker command failed with exit code 1" when XCode tries to link the project. I removed your plugin completely and the build worked so I am sure its with your plugin.

    I am using a few different plugins, one even created by me so it could be a conflict somewhere but I am not an iOS developer at all so my expertise is minimal. I wish Xcode gave me a better error message as it is super vague and idk how to see a detailed log.

    As for Android it seems to be working great so thank you for that.
     
  43. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    Those linker errors are always annoying in XCode. I've send you a PM so you we communicate without filling this thread too much.
     
  44. fidelsoto

    fidelsoto

    Joined:
    Aug 7, 2012
    Posts:
    87
    Hi, does this plugin support different Content Types? I'm in need of specifically numpad only.
     
  45. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    Yes, the plugin supports numeric only input. It will only allow numbers and will display a numpad on mobile devices when that content type is chosen.
    Small note: On UWP tablets en iPads it will show the full keyboard, but it will still only allow numbers to be inserted into the inputfield. (This is the default native behaviour for those devices).
     
  46. fidelsoto

    fidelsoto

    Joined:
    Aug 7, 2012
    Posts:
    87
    Godsent. Buying and trying it out as we speak.

    Edit:
    Ok, I tested it.
    I have struggled with Unity's input fields for such a long time it's ridiculous. I tried so many different things and spent so many hours trying to make them more user friendly but to no avail. I have no words to express my gratitude for finally having a competent solution to this problem. Thank you. THANK YOU.
     
    Last edited: Sep 15, 2017
    GGeff and fennecx_development like this.
  47. fidelsoto

    fidelsoto

    Joined:
    Aug 7, 2012
    Posts:
    87
    I'm observing an issue on android:
    My inputs are pre-filled with text programatically, ie: anAdvancedInputField.Text = someString; on Start()
    The first advanced input field I click gets its text erased.
    It only happens the very first time I open the app, to the very first input I select.
    My device is an android phone (Samsung J7) with android 6.0.1
    I'm using Unity 5.6.3p3
     
    Last edited: Sep 19, 2017
  48. fidelsoto

    fidelsoto

    Joined:
    Aug 7, 2012
    Posts:
    87
    Ok the issue disappeared, I must have been doing something weird in code.
    I will describe my escenario: I want to modify the text of the input field as the user is typing, but when I do that I get wrong caret placements or some index error. I managed to create a workaround by waiting for one frame and calling ManualSelect, but that creates other problems. Any ideas on how to do what I want? Basically I want to postprocess on the fly (which technically isn't "post" processing).

    Edit:
    Ok I fixed it by moving the caret ie: textNavigator.CaretPosition++;
    Edit 2:
    Nvm, crashes on android.
     
    Last edited: Sep 19, 2017
  49. fennecx_development

    fennecx_development

    Joined:
    Sep 24, 2014
    Posts:
    427
    That's an interesting use case. The PostProcessingFilters are safe to use, because it simply shows the processed text renderer when deselected. It doesn't modify the original .Text property.

    How would you expect it too work? Manually determining and setting the correct caret position after a text correction?
    Could you give me an example?

    I'll see if I can figure out of way of making this work.
     
  50. fidelsoto

    fidelsoto

    Joined:
    Aug 7, 2012
    Posts:
    87
    If you have Uber check out how they do input fields on their payment screen. For example their credit card field automatically puts a space (and keeps it there) in between every 4 characters.