mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
fix(android): layout change listeners are ignored when using addEventListener (#10597)
This commit is contained in:

committed by
GitHub

parent
8877becdf9
commit
89fa6ec84d
@ -336,8 +336,8 @@ export class View extends ViewCommon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any) {
|
addEventListener(eventNames: string, callback: (data: EventData) => void, thisArg?: any) {
|
||||||
super.on(eventNames, callback, thisArg);
|
super.addEventListener(eventNames, callback, thisArg);
|
||||||
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) {
|
||||||
@ -345,8 +345,8 @@ export class View extends ViewCommon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
off(eventNames: string, callback?: (data: EventData) => void, thisArg?: any) {
|
removeEventListener(eventNames: string, callback?: (data: EventData) => void, thisArg?: any) {
|
||||||
super.off(eventNames, callback, thisArg);
|
super.removeEventListener(eventNames, callback, thisArg);
|
||||||
const isLayoutEvent = typeof eventNames === 'string' ? eventNames.indexOf(ViewCommon.layoutChangedEvent) !== -1 : false;
|
const isLayoutEvent = typeof eventNames === 'string' ? eventNames.indexOf(ViewCommon.layoutChangedEvent) !== -1 : false;
|
||||||
|
|
||||||
// Remove native listener only if there are no more user listeners for LayoutChanged event
|
// Remove native listener only if there are no more user listeners for LayoutChanged event
|
||||||
@ -687,13 +687,13 @@ export class View extends ViewCommon {
|
|||||||
// if the app is in background while triggering _showNativeModalView
|
// if the app is in background while triggering _showNativeModalView
|
||||||
// then DialogFragment.show will trigger IllegalStateException: Can not perform this action after onSaveInstanceState
|
// then DialogFragment.show will trigger IllegalStateException: Can not perform this action after onSaveInstanceState
|
||||||
// so if in background we create an event to call _showNativeModalView when loaded (going back in foreground)
|
// so if in background we create an event to call _showNativeModalView when loaded (going back in foreground)
|
||||||
if (Application.inBackground && !parent.isLoaded) {
|
if (Application.inBackground && !parent.isLoaded) {
|
||||||
const onLoaded = ()=> {
|
const onLoaded = () => {
|
||||||
parent.off('loaded', onLoaded)
|
parent.off('loaded', onLoaded);
|
||||||
this._showNativeModalView(parent, options);
|
this._showNativeModalView(parent, options);
|
||||||
};
|
};
|
||||||
parent.on('loaded', onLoaded);
|
parent.on('loaded', onLoaded);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
super._showNativeModalView(parent, options);
|
super._showNativeModalView(parent, options);
|
||||||
initializeDialogFragment();
|
initializeDialogFragment();
|
||||||
|
Reference in New Issue
Block a user