Author Topic: UIInput - pressing outside input area resets input data  (Read 3444 times)

TypoStraw

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 19
    • View Profile
UIInput - pressing outside input area resets input data
« on: April 07, 2015, 04:06:35 PM »
The issue I'm having is pretty much the complete opposite of this post: http://www.tasharen.com/forum/index.php?topic=11493

I have a search feature that gets updated on input change: http://i.imgur.com/4tNtuMz.png

When you press outside (or even the hide keyboard button) the input field all changes are removed: http://i.imgur.com/cAggCVD.png
If you press Submit or OK on the keyboard itself, the changes get saved properly.

I'm using NGUI 3.8.2 and Unity Personal 5.0.1f1. I have tested it on Android 4.2.2 and 5.0.2 with the same result on both.
I also made an iOS build using Unity 5.0.0f4, where it works as usual (pretty sure it's just because of it being iOS and not the version, but will try to check it tomorrow).

I tried editing UIInput so Submit is called in OnDeselectEvent with no luck. It seems like mValue gets reset before the event is fired.

Any ideas?
« Last Edit: April 07, 2015, 04:16:18 PM by TypoStraw »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput - pressing outside input area resets input data
« Reply #1 on: April 09, 2015, 03:28:12 PM »
I suggest adding a Debug.Log in the UIInput to see where mValue gets changed to see where it's coming from.

TypoStraw

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: UIInput - pressing outside input area resets input data
« Reply #2 on: April 09, 2015, 05:42:52 PM »
I found the bug, and have made a hotfix for it.

At line 685 of UIInput:
  1. else if (mCached != text)
  2. {
  3.         mCached = text;
  4.         value = text;
  5. }
Changed to:
  1. else if (mCached != text)
  2. {
  3.         mCached = text;
  4. }
  5. else if (!mKeyboard.done || mKeyboard.active)
  6. {
  7.     value = mCached;
  8. }

This will cause the value to get set in the next frame instead of immediately after the text is changed.

The bug is that mKeyboard.text returns an empty string while it is actually closing down.
mKeyboard.done is still false and mKeyboard.active is still true, but no text value can be received.

EDIT: Tested it on iOS with Unity 5.0.1f1 - the bug was there as well, so it's a bug in Unity. The above code fixes it there as well.
« Last Edit: April 10, 2015, 05:08:06 AM by TypoStraw »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput - pressing outside input area resets input data
« Reply #3 on: April 12, 2015, 04:02:41 PM »
Thanks for looking into it. So wouldn't changing the section to this work?
  1.                                 else if (mCached != text)
  2.                                 {
  3.                                         mCached = text;
  4.                                         if (!mKeyboard.done && mKeyboard.active) value = text;
  5.                                 }
Edit: Or better yet simply change the retrieval above:
  1. string text = (mKeyboard.done || !mKeyboard.active) ? mCached : mKeyboard.text;
« Last Edit: April 12, 2015, 04:10:13 PM by ArenMook »

ryan

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 90
    • View Profile
Re: UIInput - pressing outside input area resets input data
« Reply #4 on: April 14, 2015, 01:33:05 PM »
I ran into this recently, as well.  The behavior that I was seeing was that unity would return an empty string (or null, I forget which) for mKeyboard.text the frame *before* the keyboard was deactivated.  I worked around it by caching the last non-empty string and which frame the text was cleared on, so if the keyboard was deactivated on the very next frame, I could restore the text to what it was supposed to be.  All of this was conditional on android only, since iOS works fine.