@@ -18,31 +18,30 @@ function getId(id: string) {
1818
1919@NativeClass
2020class ChangeStateBottomSheet extends com . google . android . material . bottomsheet . BottomSheetBehavior . BottomSheetCallback {
21- private owner : ViewWithBottomSheet ;
22-
23- constructor ( owner : ViewWithBottomSheet ) {
21+ constructor ( private owner : WeakRef < ViewWithBottomSheet > ) {
2422 super ( ) ;
25- this . owner = owner ;
2623 return global . __native ( this ) ;
2724 }
2825
2926 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 ) ;
3230 }
3331 }
3432
3533 onStateChanged ( bottomSheet : android . view . View , newState : number ) {
36- if ( this . checkActiveCallback ( ) ) {
34+ const owner = this . owner ?. get ( ) ;
35+ if ( owner && this . checkActiveCallback ( ) ) {
3736 const status = this . getStateBottomSheetFromBottomSheetBehavior ( newState ) ;
3837 if ( status !== undefined ) {
39- this . owner . _onChangeStateBottomSheetCallback ( status ) ;
38+ owner . _onChangeStateBottomSheetCallback ( status ) ;
4039 }
4140 }
4241 }
4342
4443 private checkActiveCallback ( ) {
45- return this . owner && this . owner . _onChangeStateBottomSheetCallback ;
44+ return this . owner ?. get ( ) ? ._onChangeStateBottomSheetCallback ;
4645 }
4746
4847 public getStateBottomSheetFromBottomSheetBehavior ( state : number ) : StateBottomSheet | undefined {
@@ -77,7 +76,7 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
7776
7877 protected _showNativeBottomSheet ( parent : View , options : BottomSheetOptions ) {
7978 this . _commonShowNativeBottomSheet ( parent , options ) ;
80- const owner = this ;
79+ const that = new WeakRef ( this ) ;
8180 const domId = this . _domId ;
8281 const bottomSheetOptions : BottomSheetDataOptions = {
8382 owner : this ,
@@ -100,7 +99,7 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
10099 if ( bottomSheetOptions . options && bottomSheetOptions . options . dismissOnBackButton === false ) {
101100 return true ;
102101 }
103-
102+ const owner = that ?. get ( ) ;
104103 if ( ! owner ) {
105104 return false ;
106105 }
@@ -145,13 +144,21 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
145144 container : android . view . ViewGroup ,
146145 savedInstanceState : android . os . Bundle
147146 ) : 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 ;
152155 } ,
153156
154157 onStart ( fragment : com . nativescript . material . bottomsheet . BottomSheetDialogFragment ) : void {
158+ const owner = that ?. get ( ) ;
159+ if ( ! owner ) {
160+ return ;
161+ }
155162 const contentViewId = getId ( 'design_bottom_sheet' ) ;
156163 const view = fragment . getDialog ( ) . findViewById ( contentViewId ) ;
157164 const transparent = bottomSheetOptions . options ?. transparent === true ;
@@ -195,9 +202,9 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
195202
196203 const onChangeState = bottomSheetOptions . options ?. onChangeState ;
197204 if ( onChangeState ) {
198- const changeStateBottomSheet = new ChangeStateBottomSheet ( owner ) ;
205+ const changeStateBottomSheet = new ChangeStateBottomSheet ( that ) ;
199206 behavior . addBottomSheetCallback ( changeStateBottomSheet ) ;
200- owner . _onChangeStateBottomSheetCallback ( changeStateBottomSheet . getStateBottomSheetFromBottomSheetBehavior ( behavior . getState ( ) ) ) ;
207+ that ?. get ( ) ? ._onChangeStateBottomSheetCallback ( changeStateBottomSheet . getStateBottomSheetFromBottomSheetBehavior ( behavior . getState ( ) ) ) ;
201208 }
202209
203210 if ( owner && ! owner . isLoaded ) {
@@ -224,6 +231,7 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
224231 } ,
225232
226233 onDismiss ( fragment : com . nativescript . material . bottomsheet . BottomSheetDialogFragment , dialog : android . content . DialogInterface ) : void {
234+ const owner = that ?. get ( ) ;
227235 if ( owner ) {
228236 owner . _bottomSheetCloseIgnore = true ;
229237 }
@@ -232,6 +240,7 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
232240
233241 onDestroy ( fragment : com . nativescript . material . bottomsheet . BottomSheetDialogFragment ) : void {
234242 ( df as any ) . nListener = null ;
243+ const owner = that ?. get ( ) ;
235244 if ( owner ) {
236245 owner . _bottomSheetCloseIgnore = false ;
237246 owner . _bottomSheetClosed ( ) ;
0 commit comments