Skip to content

Commit cb887e2

Browse files
committed
fix(android): result not returned on bottomsheet close
1 parent 679da4f commit cb887e2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/bottomsheet/bottomsheet-common.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,15 @@ export abstract class ViewWithBottomSheetBase extends View {
8787
};
8888
this._closeBottomSheetCallback = (...originalArgs) => {
8989
if (this._closeBottomSheetCallback) {
90-
const callback = this._closeBottomSheetCallback;
90+
// const callback = this._closeBottomSheetCallback;
9191
this._closeBottomSheetCallback = null;
9292
this._bottomSheetContext.closeCallback = null;
93-
this._hideNativeBottomSheet(parent, callback);
93+
const whenClosedCallback = () => {
94+
if (typeof options.closeCallback === "function") {
95+
options.closeCallback.apply(undefined, originalArgs);
96+
}
97+
};
98+
this._hideNativeBottomSheet(parent, whenClosedCallback);
9499
}
95100
};
96101
this._bottomSheetContext.closeCallback = this._closeBottomSheetCallback;

src/bottomsheet/bottomsheet.android.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,14 @@ function initializeBottomSheetDialogFragment() {
199199
export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
200200
_bottomSheetFragment: com.google.android.material.bottomsheet.BottomSheetDialogFragment;
201201
protected _hideNativeBottomSheet(parent: View, whenClosedCallback: () => void) {
202+
// call whenClosedCallback first because dismiss will call another one (without result)
203+
whenClosedCallback();
202204
const manager = this._bottomSheetFragment.getFragmentManager();
203205
if (manager) {
204206
this._bottomSheetFragment.dismissAllowingStateLoss();
205207
}
206208

207209
this._bottomSheetFragment = null;
208-
whenClosedCallback();
209210
}
210211

211212
protected _showNativeBottomSheet(parent: View, options: BottomSheetOptions) {

0 commit comments

Comments
 (0)