If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
jamiejulius
Posts: 49
Registered: ‎06-06-2012
My Device: Bold 9700
My Carrier: Pelephone
Accepted Solution

Touch event handling - Parents and Children

I have a container containing some controls.

 

What I would like is that the container's onTouch code only execute if no child control handled the onTouch event.

 

Is this possible?

 

Thanks,

 

Jamie

Please use plain text.
BlackBerry Development Advisor (Retired)
gperry
Posts: 138
Registered: ‎05-11-2012
My Device: Developer
My Carrier: Developer

Re: Touch event handling - Parents and Children

https://developer.blackberry.com/cascades/reference/bb__cascades__visualnode.html#touchpropagationmo...

 

Provides the best description of the touch propagation that I can find. Not totally sure that this will provide you with what you are required so you might have to control it deliberately but this should hopefully provide you with the description of what is currently implemented.

 

Graham

Please use plain text.
Developer
jamiejulius
Posts: 49
Registered: ‎06-06-2012
My Device: Bold 9700
My Carrier: Pelephone

Re: Touch event handling - Parents and Children

Thanks for the link.

 

I've read this many times before. As far as I understand this only allows me to control which controls will get the events. 

Please use plain text.
Developer
jamiejulius
Posts: 49
Registered: ‎06-06-2012
My Device: Bold 9700
My Carrier: Pelephone

Re: Touch event handling - Parents and Children

I solved it.

 

Here's how...

 

First of all, there are two touch events, which I now I understand as follows:

 

"touchCapture" is received in a container before the propagation to the children takes place.

"touch" is received in a container after the propagation takes place.

 

I added a property to the container like this:

 

property bool touchHandled

 

I added handlers for both touchCapture and touch, like this:

 

onTouchCapture: {
  touchHandled = false
}

onTouch: {
  if (!touchHandled) {
    //Handle as desired..
  }
}

 

If a child control handles the touch event, I have the child set touchHandled to true. For example, in one of the children, I handle an UP event. I code it like this (in the child):

 

onTouch: {
  if (event.isUp()) {
    //Do whatever...

    touchHandled = true
  }
}

 

Mission accomplished. Comments are welcome...

 

Jamie

 

 

Please use plain text.
BlackBerry Development Advisor (Retired)
gperry
Posts: 138
Registered: ‎05-11-2012
My Device: Developer
My Carrier: Developer

Re: Touch event handling - Parents and Children

Hi Jamie,

 

That looks like a good and neat solution, Congrats.

 

Graham

Please use plain text.