fix(android): layout change listeners are ignored when using addEventListener (#10597)

This commit is contained in:
Dimitris-Rafail Katsampas
2024-08-06 01:07:37 +03:00
committed by GitHub
parent 8877becdf9
commit 89fa6ec84d

View File

@ -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();