What is required to define a custom event for a UI plugin in NativeScript?
What I'm trying to achieve is to trigger a foo
event that works similar to the tap
event on a Button
and can be hooked into as follows:
<Page xmlns="http://schemas.nativescript.org/tns.xsd"
xmlns:fooplugin="nativescript-foo-plugin">
<StackLayout>
<Button text="Tap Me!" tap="{{ onTap }}" />
<fooplugin:FooPlugin foo="{{ onFoo }}" />
</StackLayout>
</Page>
What I've done essentially boils down to calling the notify
function with the eventName
value of foo
from within the plugin code (ignoring memory leak considerations):
import * as view from 'ui/core/view';
export class FooPlugin extends view.View {
constructor() {
super();
setTimeout(() => {
this.notify({
eventName: 'foo',
object: this,
});
// also tried this._emit('foo');
}, 1000);
}
}
Is there something else that I'm missing and that I need to do to make this work?
create a property public static fooEvent="foo"
the name of the property is important it should be eventname
+ Event
now it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With