Author Topic: UIInput on canceled event  (Read 3442 times)

jindave

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 6
    • View Profile
UIInput on canceled event
« 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. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput on canceled event
« Reply #1 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.

jindave

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: UIInput on canceled event
« Reply #2 on: June 25, 2014, 07:00:43 AM »
Thanks for clarification!