Skip to content

Commit c16ce20

Browse files
committed
feat(bottomsheet): closedBottomSheet event
1 parent e7e04f6 commit c16ce20

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

src/bottomsheet/bottomsheet-common.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type onChangeStateBottomSheet = (stateBottomSheet: StateBottomSheet, slid
2525

2626
export const shownInBottomSheetEvent = 'shownInBottomSheet';
2727
export const showingInBottomSheetEvent = 'showingInBottomSheet';
28+
export const closedSheetEvent = 'closedBottomSheet';
2829

2930
export interface BottomSheetOptions {
3031
view: string | ViewBase; // View instance to be shown in bottom sheet. Or the name of the module to load starting from the application root.
@@ -43,7 +44,7 @@ export interface BottomSheetOptions {
4344
peekHeight?: number; // optional parameter to set the collapsed sheet height. To work on iOS you need to set trackingScrollView.
4445
ignoreKeyboardHeight?: boolean; //(iOS only) A Boolean value that controls whether the height of the keyboard should affect the bottom sheet's frame when the keyboard shows on the screen. (Default: true)
4546
onChangeState?: onChangeStateBottomSheet; // One works to be called on the scroll of the sheet. Parameters: state (CLOSED, DRAGGING, DRAGGING, COLLAPSED) and slideOffset is the new offset of this bottom sheet within [-1,1] range. Offset increases as this bottom sheet is moving upward. From 0 to 1 the sheet is between collapsed and expanded states and from -1 to 0 it is between hidden and collapsed states.
46-
canTouchBehind?: boolean //(Android only) allows to interact with the screen behind the sheet. For it to work properly need dismissOnBackgroundTap set to true
47+
canTouchBehind?: boolean; //(Android only) allows to interact with the screen behind the sheet. For it to work properly need dismissOnBackgroundTap set to true
4748
}
4849

4950
export abstract class ViewWithBottomSheetBase extends View {
@@ -102,6 +103,7 @@ export abstract class ViewWithBottomSheetBase extends View {
102103
if (!this._onDismissBottomSheetCallback) {
103104
return;
104105
}
106+
this._raiseClosedBottomSheetEvent();
105107
this._onDismissBottomSheetCallback = null;
106108
this._closeBottomSheetCallback = null;
107109
this._bottomSheetClosed();
@@ -150,6 +152,15 @@ export abstract class ViewWithBottomSheetBase extends View {
150152
this.notify(args);
151153
}
152154

155+
_raiseClosedBottomSheetEvent() {
156+
const args = {
157+
eventName: closedSheetEvent,
158+
object: this,
159+
context: this._bottomSheetContext
160+
};
161+
this.notify(args);
162+
}
163+
153164
public closeBottomSheet(...args) {
154165
const closeCallback = this._closeBottomSheetCallback;
155166
if (closeCallback) {
@@ -168,10 +179,10 @@ export abstract class ViewWithBottomSheetBase extends View {
168179
} else {
169180
const view =
170181
options.view instanceof View
171-
? (options.view as ViewWithBottomSheetBase)
182+
? (options.view as any as ViewWithBottomSheetBase)
172183
: (Builder.createViewFromEntry({
173-
moduleName: options.view as string
174-
}) as ViewWithBottomSheetBase);
184+
moduleName: options.view as string
185+
}) as ViewWithBottomSheetBase);
175186
view._showNativeBottomSheet(this, options);
176187
return view;
177188
}

src/bottomsheet/bottomsheet.d.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* Material BottomSheet component
43
* @module @nativescript-community/ui-material-bottomsheet
@@ -14,28 +13,28 @@ export declare abstract class ViewWithBottomSheetBase extends View {
1413
/**
1514
* @hidden
1615
*/
17-
protected _closeBottomSheetCallback: Function;
16+
protected _closeBottomSheetCallback: Function;
1817

1918
// used when the bottomSheet is dismissed
2019
/**
2120
* @hidden
2221
*/
23-
public _onDismissBottomSheetCallback: Function;
22+
public _onDismissBottomSheetCallback: Function;
2423

2524
/**
2625
* @hidden
2726
*/
28-
_bottomSheetFragment: any; // com.google.android.material.bottomsheet.BottomSheetDialogFragment
27+
_bottomSheetFragment: any; // com.google.android.material.bottomsheet.BottomSheetDialogFragment
2928

3029
/**
3130
* @hidden
3231
*/
33-
protected abstract _hideNativeBottomSheet(parent: any, whenClosedCallback: any): void;
32+
protected abstract _hideNativeBottomSheet(parent: any, whenClosedCallback: any): void;
3433

3534
/**
3635
* @hidden
3736
*/
38-
protected _bottomSheetContext: any;
37+
protected _bottomSheetContext: any;
3938

4039
/**
4140
* @hidden
@@ -55,22 +54,20 @@ export declare abstract class ViewWithBottomSheetBase extends View {
5554
/**
5655
* @hidden
5756
*/
58-
protected _commonShowNativeBottomSheet(parent: View, options: BottomSheetOptions): void;
59-
57+
protected _commonShowNativeBottomSheet(parent: View, options: BottomSheetOptions): void;
58+
6059
/**
6160
* @hidden
6261
*/
6362
protected _raiseShowingBottomSheetEvent(): void;
6463

65-
6664
/**
6765
* closes the current BottomSheet
6866
*
6967
* @param args anything you want as a result of the `showBottomSheet` Promise
7068
*/
7169
public closeBottomSheet(...args: any): void;
7270

73-
7471
/**
7572
* shows a modal BottomSheet
7673
*
@@ -87,3 +84,10 @@ declare module '@nativescript/core/ui/core/view' {
8784
showBottomSheet(options: BottomSheetOptions): ViewBase;
8885
}
8986
}
87+
88+
declare module '@nativescript/core' {
89+
interface View {
90+
closeBottomSheet(...args: any): void;
91+
showBottomSheet(options: BottomSheetOptions): ViewBase;
92+
}
93+
}

0 commit comments

Comments
 (0)