Skip to content

Commit 4668bd0

Browse files
committed
fix(bottomsheet):android fix lifecycle
1 parent 80a863e commit 4668bd0

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/bottomsheet/bottomsheet-common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ export abstract class ViewWithBottomSheetBase extends View {
7373
this.notify(args);
7474
}
7575

76+
_bottomSheetCloseIgnore = false;
7677
public _bottomSheetClosed(): void {
78+
if (this._bottomSheetCloseIgnore) {
79+
return;
80+
}
7781
const _rootModalViews = this._getRootModalViews();
7882
const modalIndex = _rootModalViews.indexOf(this);
7983
_rootModalViews.splice(modalIndex);
@@ -108,6 +112,7 @@ export abstract class ViewWithBottomSheetBase extends View {
108112
}
109113
this._raiseClosedBottomSheetEvent();
110114
this._onDismissBottomSheetCallback = null;
115+
console.log('_onDismissBottomSheetCallback', this);
111116
this._bottomSheetClosed();
112117
if (this._bottomSheetContext.closeCallback) {
113118
this._bottomSheetContext.closeCallback();

src/bottomsheet/bottomsheet.android.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
7575
this._bottomSheetFragment = null;
7676
}
7777

78+
7879
protected _showNativeBottomSheet(parent: View, options: BottomSheetOptions) {
7980
this._commonShowNativeBottomSheet(parent, options);
8081
const owner = this;
@@ -218,27 +219,17 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
218219
},
219220

220221
onDismiss(fragment: com.nativescript.material.bottomsheet.BottomSheetDialogFragment, dialog: android.content.DialogInterface): void {
221-
const manager = fragment.getFragmentManager();
222-
if (manager) {
223-
bottomSheetOptions.dismissCallback();
224-
}
225-
226-
if (owner && owner.isLoaded) {
227-
owner.callUnloaded();
222+
if (owner) {
223+
owner._bottomSheetCloseIgnore = true;
228224
}
225+
bottomSheetOptions.dismissCallback();
229226
},
230227

231228
onDestroy(fragment: com.nativescript.material.bottomsheet.BottomSheetDialogFragment): void {
232229
(df as any).nListener = null;
233230
if (owner) {
234-
// Android calls onDestroy before onDismiss.
235-
// Make sure we unload first and then call _tearDownUI.
236-
if (owner.isLoaded) {
237-
owner.callUnloaded();
238-
}
239-
owner._isAddedToNativeVisualTree = false;
240-
owner._tearDownUI(true);
241-
owner.parent = null;
231+
owner._bottomSheetCloseIgnore = false;
232+
owner._bottomSheetClosed();
242233
}
243234
}
244235
});

0 commit comments

Comments
 (0)