Skip to content

Commit b571fc7

Browse files
committed
fix(bottomsheet): ios fix on bottomsheet close
1 parent d72a2fd commit b571fc7

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/bottomsheet/bottomsheet-common.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ export abstract class ViewWithBottomSheetBase extends View {
7777
const _rootModalViews = this._getRootModalViews();
7878
const modalIndex = _rootModalViews.indexOf(this);
7979
_rootModalViews.splice(modalIndex);
80-
this._tearDownUI();
80+
81+
this._isAddedToNativeVisualTree = false;
82+
this._tearDownUI(true);
83+
this.parent = null;
8184
// if a frame _removeFromFrameStack will be called from _tearDownUI
8285
// if (this instanceof Frame) {
8386
// this._removeFromFrameStack();
@@ -182,7 +185,7 @@ export abstract class ViewWithBottomSheetBase extends View {
182185
options.view instanceof View
183186
? (options.view as any as ViewWithBottomSheetBase)
184187
: (Builder.createViewFromEntry({
185-
moduleName: options.view as string
188+
moduleName: options.view
186189
}) as ViewWithBottomSheetBase);
187190
view._showNativeBottomSheet(this, options);
188191
return view;

src/bottomsheet/bottomsheet.ios.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ class MDCBottomSheetControllerDelegateImpl extends NSObject {
5050
}
5151
bottomSheetControllerDidDismissBottomSheet(controller: MDCBottomSheetController) {
5252
// called when clicked on background
53-
const owner = this._owner.get();
54-
owner && owner._unloadBottomSheet();
53+
// this is called too soon to "dispose" the view. But we dont have a way
54+
// to know when the animation is finished.
55+
//Consequently with background tap we see the view disappear
56+
// so we timeout a bit
57+
setTimeout(() => {
58+
const owner = this._owner.get();
59+
owner && owner._unloadBottomSheet();
60+
}, 200);
5561
}
5662
bottomSheetControllerStateChangedState(controller: MDCBottomSheetController, state: MDCSheetState) {
5763
// called when swiped
@@ -434,13 +440,25 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
434440
}
435441

436442
_bottomSheetClosed() {
443+
console.log('_bottomSheetClosed');
444+
super._bottomSheetClosed();
445+
437446
if (this.bottomSheetController) {
438447
this.bottomSheetController.delegate = null;
439448
this.bottomSheetController = null;
440449
}
441450
this.bottomSheetControllerDelegate = null;
451+
// it is very important to clear the viewController as N does not do it
452+
// and the destroy of the view from svelte could trigger a layout pass on the viewController
453+
this.viewController = null;
442454
}
443455
protected _hideNativeBottomSheet(parent: View, whenClosedCallback: () => void) {
456+
if (!this.viewController) {
457+
// when clicking on background we dont need to dismiss, already done
458+
whenClosedCallback?.();
459+
return;
460+
}
461+
console.log('_hideNativeBottomSheet', new Error().stack);
444462
const parentWithController = IOSHelper.getParentWithViewController(parent);
445463
if (!parent || !parentWithController) {
446464
Trace.error('Trying to hide bottom-sheet view but no parent with viewController specified.');
@@ -453,17 +471,11 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
453471
}
454472

455473
_unloadBottomSheet() {
474+
console.log('_unloadBottomSheet');
456475
if (this.isLoaded) {
457476
this.callUnloaded();
458477
}
459-
this._isAddedToNativeVisualTree = false;
460-
this._tearDownUI(true);
461-
this.parent = null;
462-
463478
this._onDismissBottomSheetCallback && this._onDismissBottomSheetCallback();
464-
// it is very important to clear the viewController as N does not do it
465-
// and the destroy of the view from svelte could trigger a layout pass on the viewController
466-
this.viewController = null;
467479
}
468480
}
469481

0 commit comments

Comments
 (0)