Skip to content

Commit 05299fe

Browse files
authored
Merge pull request #126 from alexander-mai/feature/bottm-sheet-closeable
feature: angular bottomsheet service returns close callback
2 parents 3b2989f + bc5b2cf commit 05299fe

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/bottomsheet/angular/bottomsheet.service.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { ComponentFactoryResolver, ComponentRef, Injectable, Injector, Type, Vie
22
import { DetachedLoader } from '@nativescript/angular/common/detached-loader';
33
import { AppHostView } from '@nativescript/angular/app-host-view';
44
import { once } from '@nativescript/angular/common/utils';
5-
import { BottomSheetOptions as MaterialBottomSheetOptions } from '../bottomsheet-common';
6-
import { ViewWithBottomSheetBase } from '../bottomsheet-common';
5+
import { BottomSheetOptions as MaterialBottomSheetOptions, ViewWithBottomSheetBase } from '../bottomsheet-common';
76
import { Observable, Subject } from 'rxjs';
87
import { filter, first, map } from 'rxjs/operators';
98
import { ProxyViewContainer } from '@nativescript/core/ui/proxy-view-container';
@@ -34,6 +33,10 @@ export class BottomSheetService {
3433
private currentId = 0;
3534

3635
show<T = any>(type: Type<any>, options: BottomSheetOptions): Observable<T> {
36+
return this.showWithCloseCallback(type, options).observable;
37+
}
38+
39+
showWithCloseCallback<T = any>(type: Type<any>, options: BottomSheetOptions): { observable: Observable<T>, closeCallback: () => void } {
3740
if (!options.viewContainerRef) {
3841
throw new Error('No viewContainerRef: Make sure you pass viewContainerRef in BottomSheetOptions.');
3942
}
@@ -53,11 +56,14 @@ export class BottomSheetService {
5356
});
5457
});
5558

56-
return this.subject$.pipe(
57-
filter(item => item && item.requestId === requestId),
58-
map(item => item.result),
59-
first()
60-
);
59+
return {
60+
observable: this.subject$.pipe(
61+
filter(item => item && item.requestId === requestId),
62+
map(item => item.result),
63+
first()
64+
),
65+
closeCallback: bottomSheetParams.closeCallback
66+
};
6167
}
6268

6369
private getParentView(viewContainerRef: ViewContainerRef): ViewWithBottomSheetBase {

0 commit comments

Comments
 (0)