mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 01:43:14 +08:00
fix(core): missing parameter for once event listeners (#10715)
This commit is contained in:

committed by
GitHub

parent
50019ecd30
commit
852011c4f9
@ -197,6 +197,7 @@ export class Observable {
|
|||||||
* @param eventName Name of the event to attach to.
|
* @param eventName Name of the event to attach to.
|
||||||
* @param callback A function to be called when some of the specified event(s) is raised.
|
* @param callback A function to be called when some of the specified event(s) is raised.
|
||||||
* @param thisArg An optional parameter which when set will be used as "this" in callback method call.
|
* @param thisArg An optional parameter which when set will be used as "this" in callback method call.
|
||||||
|
* @param once An optional parameter which when set will cause the event listener to fire once.
|
||||||
*/
|
*/
|
||||||
public addEventListener(eventName: string, callback: (data: EventData) => void, thisArg?: any, once?: boolean): void {
|
public addEventListener(eventName: string, callback: (data: EventData) => void, thisArg?: any, once?: boolean): void {
|
||||||
once = once || undefined;
|
once = once || undefined;
|
||||||
|
@ -118,13 +118,13 @@ class MediaQueryListImpl extends Observable implements MediaQueryList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
public addEventListener(eventName: string, callback: (data: EventData) => void, thisArg?: any): void {
|
public addEventListener(eventName: string, callback: (data: EventData) => void, thisArg?: any, once?: boolean): void {
|
||||||
this._throwInvocationError?.();
|
this._throwInvocationError?.();
|
||||||
|
|
||||||
const hasChangeListeners = this.hasListeners(MediaQueryListImpl.changeEvent);
|
const hasChangeListeners = this.hasListeners(MediaQueryListImpl.changeEvent);
|
||||||
|
|
||||||
// Call super method first since it throws in the case of bad parameters
|
// Call super method first since it throws in the case of bad parameters
|
||||||
super.addEventListener(eventName, callback, thisArg);
|
super.addEventListener(eventName, callback, thisArg, once);
|
||||||
|
|
||||||
if (eventName === MediaQueryListImpl.changeEvent && !hasChangeListeners) {
|
if (eventName === MediaQueryListImpl.changeEvent && !hasChangeListeners) {
|
||||||
mediaQueryLists.push(this);
|
mediaQueryLists.push(this);
|
||||||
|
@ -335,8 +335,8 @@ export class View extends ViewCommon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addEventListener(eventNames: string, callback: (data: EventData) => void, thisArg?: any) {
|
addEventListener(eventNames: string, callback: (data: EventData) => void, thisArg?: any, once?: boolean) {
|
||||||
super.addEventListener(eventNames, callback, thisArg);
|
super.addEventListener(eventNames, callback, thisArg, once);
|
||||||
const isLayoutEvent = typeof eventNames === 'string' ? eventNames.indexOf(ViewCommon.layoutChangedEvent) !== -1 : false;
|
const isLayoutEvent = typeof eventNames === 'string' ? eventNames.indexOf(ViewCommon.layoutChangedEvent) !== -1 : false;
|
||||||
|
|
||||||
if (this.isLoaded && !this.layoutChangeListenerIsSet && isLayoutEvent) {
|
if (this.isLoaded && !this.layoutChangeListenerIsSet && isLayoutEvent) {
|
||||||
|
@ -303,7 +303,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
|
|||||||
return this._gestureObservers[type];
|
return this._gestureObservers[type];
|
||||||
}
|
}
|
||||||
|
|
||||||
public addEventListener(eventNames: string, callback: (data: EventData) => void, thisArg?: any) {
|
public addEventListener(eventNames: string, callback: (data: EventData) => void, thisArg?: any, once?: boolean) {
|
||||||
thisArg = thisArg || undefined;
|
thisArg = thisArg || undefined;
|
||||||
|
|
||||||
// TODO: Remove this once we fully switch to the new event system
|
// TODO: Remove this once we fully switch to the new event system
|
||||||
@ -330,7 +330,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
super.addEventListener(normalizedName, callback, thisArg);
|
super.addEventListener(normalizedName, callback, thisArg, once);
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeEventListener(eventNames: string, callback?: (data: EventData) => void, thisArg?: any) {
|
public removeEventListener(eventNames: string, callback?: (data: EventData) => void, thisArg?: any) {
|
||||||
|
@ -17,10 +17,10 @@ export abstract class ScrollViewBase extends ContentView implements ScrollViewDe
|
|||||||
|
|
||||||
private _addedScrollEvent = false;
|
private _addedScrollEvent = false;
|
||||||
|
|
||||||
public addEventListener(arg: string, callback: (data: EventData) => void, thisArg?: any): void {
|
public addEventListener(arg: string, callback: (data: EventData) => void, thisArg?: any, once?: boolean): void {
|
||||||
const hasExistingScrollListeners: boolean = this.hasListeners(ScrollViewBase.scrollEvent);
|
const hasExistingScrollListeners: boolean = this.hasListeners(ScrollViewBase.scrollEvent);
|
||||||
|
|
||||||
super.addEventListener(arg, callback, thisArg);
|
super.addEventListener(arg, callback, thisArg, once);
|
||||||
|
|
||||||
// This indicates that a scroll listener was added for first time
|
// This indicates that a scroll listener was added for first time
|
||||||
if (!hasExistingScrollListeners && this.hasListeners(ScrollViewBase.scrollEvent)) {
|
if (!hasExistingScrollListeners && this.hasListeners(ScrollViewBase.scrollEvent)) {
|
||||||
|
@ -113,8 +113,8 @@ export class Span extends ViewBase implements SpanDefinition {
|
|||||||
return this._tappable;
|
return this._tappable;
|
||||||
}
|
}
|
||||||
|
|
||||||
addEventListener(arg: string, callback: (data: EventData) => void, thisArg?: any): void {
|
addEventListener(arg: string, callback: (data: EventData) => void, thisArg?: any, once?: boolean): void {
|
||||||
super.addEventListener(arg, callback, thisArg);
|
super.addEventListener(arg, callback, thisArg, once);
|
||||||
this._setTappable(this.hasListeners(Span.linkTapEvent));
|
this._setTappable(this.hasListeners(Span.linkTapEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user