@@ -14,32 +14,56 @@ declare module 'nativescript-vue' {
1414 }
1515}
1616
17+ let sequentialCounter = 0 ;
18+
19+ function serializeModalOptions ( options ) {
20+ if ( process . env . NODE_ENV === 'production' ) {
21+ return null ;
22+ }
23+
24+ const allowed = [ 'fullscreen' ] ;
25+
26+ return Object . keys ( options )
27+ . filter ( key => allowed . includes ( key ) )
28+ . map ( key => `${ key } : ${ options [ key ] } ` )
29+ . concat ( `uid: ${ ++ sequentialCounter } ` )
30+ . join ( ', ' ) + '_bottomsheet' ;
31+ }
32+
1733const BottomSheetPlugin = {
1834 install ( Vue ) {
1935 Vue . prototype . $showBottomSheet = function ( component , options : VueBottomSheetOptions ) {
20- let navEntryInstance = new Vue ( {
21- name : 'BottomSheetEntry' ,
22- parent : this . $root ,
23- render : h =>
24- h ( component , {
25- props : options . props ,
26- key : component . toString ( )
36+ return new Promise ( ( resolve : ( ...args ) => void ) => {
37+ let resolved = false ;
38+ let navEntryInstance = new Vue ( {
39+ name : 'BottomSheetEntry' ,
40+ parent : this . $root ,
41+ render : h =>
42+ h ( component , {
43+ props : options . props ,
44+ key : serializeModalOptions ( options )
45+ } )
46+ } ) ;
47+ navEntryInstance . $mount ( ) ;
48+ this . nativeView . showBottomSheet (
49+ Object . assign ( { } , options , {
50+ view : navEntryInstance . nativeView ,
51+ closeCallback : ( ...args ) => {
52+ if ( resolved ) {
53+ return ;
54+ }
55+ resolved = true ;
56+ if ( navEntryInstance && navEntryInstance . nativeView ) {
57+ options . closeCallback && options . closeCallback . apply ( undefined , args ) ;
58+ resolve ( args ) ;
59+ navEntryInstance . $emit ( 'bottomsheet:close' ) ;
60+ navEntryInstance . $destroy ( ) ;
61+ navEntryInstance = null ;
62+ }
63+ }
2764 } )
65+ ) ;
2866 } ) ;
29- navEntryInstance . $mount ( ) ;
30- this . nativeView . showBottomSheet (
31- Object . assign ( { } , options , {
32- view : navEntryInstance . nativeView ,
33- closeCallback : ( ...args ) => {
34- if ( navEntryInstance && navEntryInstance . nativeView ) {
35- options . closeCallback && options . closeCallback . apply ( undefined , args ) ;
36- navEntryInstance . $emit ( 'bottomsheet:close' ) ;
37- navEntryInstance . $destroy ( ) ;
38- navEntryInstance = null ;
39- }
40- }
41- } )
42- ) ;
4367 } ;
4468 Vue . prototype . $closeBottomSheet = function ( ...args ) {
4569 ( this . nativeView ) . closeBottomSheet . apply ( this . nativeView , args ) ;
0 commit comments