Stop event propagation in NativeScript ios tap event

Viewed 3063

I have a tap event in my code. Its parent(not an immediate parent) also has tap event. In Android, everything works fine. But in ios, the event is propagating upwards to that parent. How to stop that event propagation (such as event.stopPropagation() in javascript).

Sample XML code:

<StackLayout  tap="newsDetails" data-args="{{ $value }}">
     <StackLayout orientation="horizontal" >
         <Label text="Share" class="icon" tap="shareNews" data-args="{{ $value }}"/>
     </StackLayout>
</StackLayout>

Note: I am using NativeScript core

Thank you.

2 Answers

You can use the boolean property isUserInteractionEnabled, however, this won't solve the issue as it will stop the user interaction for all nested elements as well. It is simply not good practice to have multiple tap events in the same area.

I had the same issue on android, here's a simple solution i came up with, not elegant but works :

private ignoreTap = false;

shareNews(){
  this.ignoreTap = true;
  // ...
}

newsDetails(){
  if (this.ignoreTap) { this.ignoreTap = false; return; }
  // ...
}

The flag ignoreTap will stop the root function execution.

Related