Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: jindave on June 25, 2014, 05:25:35 AM

Title: UIInput on canceled event
Post by: jindave on June 25, 2014, 05:25:35 AM
Hello Tasharen team,
I found that I often need to handle situation when mobile keyboard was canceled by user (He touched outside of keyboard). You reset the state like this:

Update function:
  1. if (!mKeyboard.wasCanceled) Submit();
  2. mKeyboard = null;
  3. isSelected = false;
  4. mCached = "";

I did small update which I guess can be handy for all:

Event declaration:
  1. public List<EventDelegate> onCanceled = new List<EventDelegate>();

Update function:
  1. if (!mKeyboard.wasCanceled) Submit();
  2. else Canceled();
  3. mKeyboard = null;
  4. isSelected = false;
  5. mCached = "";

Canceled function:
  1. public void Canceled()
  2. {
  3.     if (NGUITools.GetActive(this))
  4.     {
  5.         if (current == null)
  6.         {
  7.             current = this;
  8.             EventDelegate.Execute(onCanceled);
  9.             current = null;
  10.         }
  11.     }
  12. }
Title: Re: UIInput on canceled event
Post by: ArenMook on June 25, 2014, 06:29:49 AM
You will get OnSelect(false) when you cancel it. Another advantage of OnSelect(false) is that it will work with more than just mobile keyboards -- stand-alone builds also send out OnSelect(false) when you click somewhere else.
Title: Re: UIInput on canceled event
Post by: jindave on June 25, 2014, 07:00:43 AM
Thanks for clarification!