Skip to content

Commit f4e4674

Browse files
committed
fix(bottomsheet): options closeCallback not being called on background dismiss.
feat(bottomsheet): `options.closeCallback` now as a second argument which is the framework instance of the bottomsheet component (can be used to retrieve data)
1 parent 0ebe287 commit f4e4674

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

src/bottomsheet/bottomsheet-common.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,15 @@ export abstract class ViewWithBottomSheetBase extends View {
105105
}
106106
this._raiseClosedBottomSheetEvent();
107107
this._onDismissBottomSheetCallback = null;
108-
this._closeBottomSheetCallback = null;
109108
this._bottomSheetClosed();
110109
if (this._bottomSheetContext.closeCallback) {
110+
this._bottomSheetContext.closeCallback();
111111
// only called if not already called by _closeBottomSheetCallback
112-
if (typeof options.closeCallback === 'function') {
113-
options.closeCallback.apply(undefined, originalArgs);
114-
}
112+
// if (typeof options.closeCallback === 'function') {
113+
// options.closeCallback.apply(undefined, originalArgs);
114+
// }
115115
}
116+
this._closeBottomSheetCallback = null;
116117
this._bottomSheetContext = null;
117118
};
118119
this._closeBottomSheetCallback = (...originalArgs) => {
@@ -164,7 +165,7 @@ export abstract class ViewWithBottomSheetBase extends View {
164165
public closeBottomSheet(...args) {
165166
const closeCallback = this._closeBottomSheetCallback;
166167
if (closeCallback) {
167-
closeCallback.apply(undefined, arguments);
168+
closeCallback.apply(undefined, args);
168169
} else {
169170
const parent = this.parent as ViewWithBottomSheetBase;
170171
if (parent) {

src/bottomsheet/svelte/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ export function showBottomSheet<T = any, U = any>(modalOptions: SvelteShowBottom
4141
let resolved = false;
4242
const closeCallback = (result: T) => {
4343
if (resolved) return;
44-
modalStack.pop();
4544
resolved = true;
45+
if (options.closeCallback) {
46+
options.closeCallback(result,componentInstanceInfo.viewInstance);
47+
}
48+
modalStack.pop();
4649
resolve(result);
4750
modalView._tearDownUI();
4851
componentInstanceInfo.viewInstance.$destroy(); // don't let an exception in destroy kill the promise callback

src/bottomsheet/vue/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ const BottomSheetPlugin = {
5252
this.nativeView.showBottomSheet(
5353
Object.assign({}, options, {
5454
view: navEntryInstance.nativeView,
55-
closeCallback: (...args) => {
55+
closeCallback: (result) => {
5656
if (resolved) {
5757
return;
5858
}
5959
resolved = true;
60+
if (options.closeCallback) {
61+
options.closeCallback(result, navEntryInstance);
62+
}
63+
resolve(result);
6064
if (navEntryInstance && navEntryInstance.nativeView) {
61-
options.closeCallback && options.closeCallback.apply(undefined, args);
62-
resolve(...args);
6365
navEntryInstance.$emit('bottomsheet:close');
6466
navEntryInstance.$destroy();
6567
navEntryInstance = null;

src/bottomsheet/vue3/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ const showSheet = (component, options: VueBottomSheetOptions) =>
4545
viewAttached.showBottomSheet(
4646
Object.assign({}, options, {
4747
view: navEntryInstance.nativeView,
48-
closeCallback: (...args) => {
48+
closeCallback: (result) => {
4949
if (resolved) {
5050
return;
5151
}
52-
resolved = true;
52+
if (options.closeCallback) {
53+
options.closeCallback(result, navEntryInstance);
54+
}
55+
resolve(result);
5356
if (navEntryInstance && navEntryInstance) {
54-
options.closeCallback && options.closeCallback.apply(undefined, args);
55-
resolve(...args);
5657
navEntryInstance.unmount();
5758
modalStack.pop();
5859
}

0 commit comments

Comments
 (0)