halfnelson / svelte-native

Svelte controlling native components via Nativescript
MIT License
1.82k stars 78 forks source link

how to control on:tap #343

Open wvq opened 1 year ago

wvq commented 1 year ago

I want to control enable/disable on:tap, but:

<script>
let on = View.prototype.addEventListener

View.prototype.addEventListener = function (arg: string | GestureTypes, callback: (data: EventData) => void, thisArg?: any) {
  console.log(this, arg, callback)
  on.call(this, arg, callback, thisArg)
}
let disabled = true
$: handleTap = disabled ? undefined : () => { console.log('tapped') }
</script>

<flexboxLayout on:tap={handleTap}>

why handleTap is undefined, but still call addEventListener.

vallemar commented 1 year ago

@wvq alternatively you can use isUserInteractionEnabled https://stackoverflow.com/questions/41468742/nativescript-angular-2-disable-background-tap-events