在NativeScript中为UI插件定义自定义事件需要什么?
我试图做到的,是触发foo
该给的工作原理类似于事件tap
事件上Button
,并且可以挂到如下:
<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>
我所做的基本上可以归结为在插件代码中使用fromnotify
的eventName
值调用函数foo
(忽略内存泄漏注意事项):
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);
}
}
还有其他我想念的东西,我需要做才能完成这项工作?
创建属性public static fooEvent="foo"
该属性的名称很重要,应该eventname
+Event
现在应该可以使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句