Author Topic: Distinguishing tap/drag on input field inside scrollview.  (Read 3991 times)

matdru

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Distinguishing tap/drag on input field inside scrollview.
« on: January 22, 2014, 04:42:15 AM »
Hello,

Small question from me -> is there anyway to distinguish tap event from drag one in a scrollview? I have a small form with labels and inputs inside a scrollview, all of them with DragScrollView attached. When i try to scroll the form on mobile device and start my touch on input field, as soon as drag finishes the touch keyboard pops out to write in that input. What i'd like to happen is that if i tap on the input the keyboard pops out, if i'm dragging whole scrollview then it should not. I'm aware that UIinput is separate from DragScrollView and i'd propably need to write my own thing that does that, i was just curious if there is anything that i can use to achieve that?

TL;DR: How to surpress UIInput if DragScrollView is being used  :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Distinguishing tap/drag on input field inside scrollview.
« Reply #1 on: January 22, 2014, 05:02:49 AM »
When you receive your OnDragStart event, set UICamera.currentTouch.press to either null, or something else (prefferably to something else -- like the window). This will prevent the object from receiving OnPress (false). You can do this with other events too. Check UICamera.currentTouch during an NGUI event -- it has a few things inside.

matdru

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: Distinguishing tap/drag on input field inside scrollview.
« Reply #2 on: January 22, 2014, 06:03:18 AM »
Hi,

Thanks for fast reply, just one thing i didn't get -> where can i find or listen to the OnDragStart event? I've seen onDragFinished in UIScrollView, but searched whole project for onDragStart and no luck :( Thanks again for your help! :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Distinguishing tap/drag on input field inside scrollview.
« Reply #3 on: January 22, 2014, 06:08:24 AM »
It's one of NGUI's events sent out by UICamera. Just like OnPress, OnClick, OnSelect, etc.

If you have a script attached to a widget with a collider that has the "void OnDragStart ()" function in it, that function will be called when the drag operation begins.

matdru

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: Distinguishing tap/drag on input field inside scrollview.
« Reply #4 on: January 22, 2014, 06:16:05 AM »
Ahhhh i get it! ( what a brain-lag from me ). I think i can get it from here, thanks a lot for your support Aren! :)

HuyThach

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Distinguishing tap/drag on input field inside scrollview.
« Reply #5 on: July 13, 2015, 03:45:26 AM »
matdru,

I have the same problem. Did you try with NGUI 3.9.0?
I created a script and attach it to the input field object. Inside the script, I write a OnDragStart () function as:

  1. void OnDragStart ()
  2. {
  3. UICamera.currentTouch.pressed = nul;
  4. }
  5.  

But instead of not showing keyboard, now I can't drag the scroll if I start touch in the input field to drag the scroll.

HuyThach

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Distinguishing tap/drag on input field inside scrollview.
« Reply #6 on: July 13, 2015, 07:35:48 PM »
I have checked OnPress and OnDragStart functions which one is called first, and the result is:
- OnPress() is called
- OnDragStart() is called
- OnPress() is called.

Do you know how to make OnDragStart() function is called before OnPress() function?
Thank you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Distinguishing tap/drag on input field inside scrollview.
« Reply #7 on: July 15, 2015, 12:07:44 AM »
Why are you doing this? You are removing the "pressed" object state. Without it events won't work, of course. So you are getting exactly what you should be after removing the pressed object.

HuyThach

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Distinguishing tap/drag on input field inside scrollview.
« Reply #8 on: July 15, 2015, 07:42:37 PM »
Maybe I mis-understand your post:
"When you receive your OnDragStart event, set UICamera.currentTouch.press to either null, or something else"

What should I do to distinguish tap and drag event on an input field?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Distinguishing tap/drag on input field inside scrollview.
« Reply #9 on: July 16, 2015, 11:04:45 AM »
I had to re-read your original post... So if I understand you correctly, you have an input field inside a scroll view, and you want it to be possible to drag the scroll view by pressing on the input field and moving the finger, but currently as soon as you press on it it will start the input logic. You want to prevent this, correct?

First, don't use UIInput as-is. It's written to react to a selection, which happens as soon as you press on it.

Either have it start disabled, or have another invisible widget covering it (ALT+SHIFT+W). This widget will intercept the event (and will have UIDragScrollView on it). Add an OnClick() function to this widget, and inside give your input field selection (UIInput.isSelected = true). To make it possible to interact with it using the mouse/touch, make sure that your dummy widget also happens to be disabled while the input field has focus. As soon as the focus is lost (it gets OnSelect(false)), re-enable your dummy widget.

HuyThach

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Distinguishing tap/drag on input field inside scrollview.
« Reply #10 on: July 18, 2015, 12:24:16 AM »
Yes, this is what I am searching for.
Thank you for your help.