@@ -18,31 +18,30 @@ function getId(id: string) {
18
18
19
19
@NativeClass
20
20
class ChangeStateBottomSheet extends com . google . android . material . bottomsheet . BottomSheetBehavior . BottomSheetCallback {
21
- private owner : ViewWithBottomSheet ;
22
-
23
- constructor ( owner : ViewWithBottomSheet ) {
21
+ constructor ( private owner : WeakRef < ViewWithBottomSheet > ) {
24
22
super ( ) ;
25
- this . owner = owner ;
26
23
return global . __native ( this ) ;
27
24
}
28
25
29
26
onSlide ( bottomSheet : android . view . View , slideOffset : number ) {
30
- if ( this . checkActiveCallback ( ) ) {
31
- this . owner . _onChangeStateBottomSheetCallback ( StateBottomSheet . DRAGGING , slideOffset ) ;
27
+ const owner = this . owner ?. get ( ) ;
28
+ if ( owner && this . checkActiveCallback ( ) ) {
29
+ owner . _onChangeStateBottomSheetCallback ( StateBottomSheet . DRAGGING , slideOffset ) ;
32
30
}
33
31
}
34
32
35
33
onStateChanged ( bottomSheet : android . view . View , newState : number ) {
36
- if ( this . checkActiveCallback ( ) ) {
34
+ const owner = this . owner ?. get ( ) ;
35
+ if ( owner && this . checkActiveCallback ( ) ) {
37
36
const status = this . getStateBottomSheetFromBottomSheetBehavior ( newState ) ;
38
37
if ( status !== undefined ) {
39
- this . owner . _onChangeStateBottomSheetCallback ( status ) ;
38
+ owner . _onChangeStateBottomSheetCallback ( status ) ;
40
39
}
41
40
}
42
41
}
43
42
44
43
private checkActiveCallback ( ) {
45
- return this . owner && this . owner . _onChangeStateBottomSheetCallback ;
44
+ return this . owner ?. get ( ) ? ._onChangeStateBottomSheetCallback ;
46
45
}
47
46
48
47
public getStateBottomSheetFromBottomSheetBehavior ( state : number ) : StateBottomSheet | undefined {
@@ -77,7 +76,7 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
77
76
78
77
protected _showNativeBottomSheet ( parent : View , options : BottomSheetOptions ) {
79
78
this . _commonShowNativeBottomSheet ( parent , options ) ;
80
- const owner = this ;
79
+ const that = new WeakRef ( this ) ;
81
80
const domId = this . _domId ;
82
81
const bottomSheetOptions : BottomSheetDataOptions = {
83
82
owner : this ,
@@ -100,7 +99,7 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
100
99
if ( bottomSheetOptions . options && bottomSheetOptions . options . dismissOnBackButton === false ) {
101
100
return true ;
102
101
}
103
-
102
+ const owner = that ?. get ( ) ;
104
103
if ( ! owner ) {
105
104
return false ;
106
105
}
@@ -145,13 +144,21 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
145
144
container : android . view . ViewGroup ,
146
145
savedInstanceState : android . os . Bundle
147
146
) : android . view . View {
148
- owner . _setupAsRootView ( fragment . getActivity ( ) ) ;
149
- owner . parent = Application . getRootView ( ) ;
150
- owner . _isAddedToNativeVisualTree = true ;
151
- return owner . nativeViewProtected ;
147
+ const owner = that ?. get ( ) ;
148
+ if ( owner ) {
149
+ owner . _setupAsRootView ( fragment . getActivity ( ) ) ;
150
+ owner . parent = Application . getRootView ( ) ;
151
+ owner . _isAddedToNativeVisualTree = true ;
152
+ return owner . nativeViewProtected ;
153
+ }
154
+ return null ;
152
155
} ,
153
156
154
157
onStart ( fragment : com . nativescript . material . bottomsheet . BottomSheetDialogFragment ) : void {
158
+ const owner = that ?. get ( ) ;
159
+ if ( ! owner ) {
160
+ return ;
161
+ }
155
162
const contentViewId = getId ( 'design_bottom_sheet' ) ;
156
163
const view = fragment . getDialog ( ) . findViewById ( contentViewId ) ;
157
164
const transparent = bottomSheetOptions . options ?. transparent === true ;
@@ -195,9 +202,9 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
195
202
196
203
const onChangeState = bottomSheetOptions . options ?. onChangeState ;
197
204
if ( onChangeState ) {
198
- const changeStateBottomSheet = new ChangeStateBottomSheet ( owner ) ;
205
+ const changeStateBottomSheet = new ChangeStateBottomSheet ( that ) ;
199
206
behavior . addBottomSheetCallback ( changeStateBottomSheet ) ;
200
- owner . _onChangeStateBottomSheetCallback ( changeStateBottomSheet . getStateBottomSheetFromBottomSheetBehavior ( behavior . getState ( ) ) ) ;
207
+ that ?. get ( ) ? ._onChangeStateBottomSheetCallback ( changeStateBottomSheet . getStateBottomSheetFromBottomSheetBehavior ( behavior . getState ( ) ) ) ;
201
208
}
202
209
203
210
if ( owner && ! owner . isLoaded ) {
@@ -224,6 +231,7 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
224
231
} ,
225
232
226
233
onDismiss ( fragment : com . nativescript . material . bottomsheet . BottomSheetDialogFragment , dialog : android . content . DialogInterface ) : void {
234
+ const owner = that ?. get ( ) ;
227
235
if ( owner ) {
228
236
owner . _bottomSheetCloseIgnore = true ;
229
237
}
@@ -232,6 +240,7 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
232
240
233
241
onDestroy ( fragment : com . nativescript . material . bottomsheet . BottomSheetDialogFragment ) : void {
234
242
( df as any ) . nListener = null ;
243
+ const owner = that ?. get ( ) ;
235
244
if ( owner ) {
236
245
owner . _bottomSheetCloseIgnore = false ;
237
246
owner . _bottomSheetClosed ( ) ;
0 commit comments