@@ -51,23 +51,16 @@ class MDCBottomSheetControllerDelegateImpl extends NSObject {
5151 bottomSheetControllerDidDismissBottomSheet ( controller : MDCBottomSheetController ) {
5252 // called when clicked on background
5353 const owner = this . _owner . get ( ) ;
54- if ( owner ) {
55- owner . _onDismissBottomSheetCallback && owner . _onDismissBottomSheetCallback ( ) ;
56- if ( owner && owner . isLoaded ) {
57- owner . callUnloaded ( ) ;
58- }
59- }
54+ owner && owner . _unloadBottomSheet ( ) ;
55+
6056 }
6157 bottomSheetControllerStateChangedState ( controller : MDCBottomSheetController , state : MDCSheetState ) {
6258 // called when swiped
6359 const owner = this . _owner . get ( ) ;
6460 if ( state === MDCSheetState . Closed ) {
6561 if ( owner ) {
66- owner . _onDismissBottomSheetCallback && owner . _onDismissBottomSheetCallback ( ) ;
6762 owner . _onChangeStateBottomSheetCallback && owner . _onChangeStateBottomSheetCallback ( StateBottomSheet . CLOSED ) ;
68- if ( owner && owner . isLoaded ) {
69- owner . callUnloaded ( ) ;
70- }
63+ owner && owner . _unloadBottomSheet ( ) ;
7164 }
7265 } else {
7366 if ( owner && owner . _onChangeStateBottomSheetCallback ) {
@@ -186,12 +179,14 @@ function layoutView(controller: IMDLayoutViewController, owner: View): void {
186179 // adjustedPosition[oppositeKey] += Utils.layout.toDevicePixels(delta);
187180 // adjustedPosition[key] += Utils.layout.toDevicePixels(delta);
188181 }
189- owner . nativeViewProtected . frame = CGRectMake (
190- Utils . layout . toDeviceIndependentPixels ( adjustedPosition . left ) ,
191- Utils . layout . toDeviceIndependentPixels ( adjustedPosition . top ) ,
192- Utils . layout . toDeviceIndependentPixels ( adjustedPosition . right ) ,
193- Utils . layout . toDeviceIndependentPixels ( adjustedPosition . bottom )
194- ) ;
182+ if ( owner . nativeViewProtected ) {
183+ owner . nativeViewProtected . frame = CGRectMake (
184+ Utils . layout . toDeviceIndependentPixels ( adjustedPosition . left ) ,
185+ Utils . layout . toDeviceIndependentPixels ( adjustedPosition . top ) ,
186+ Utils . layout . toDeviceIndependentPixels ( adjustedPosition . right ) ,
187+ Utils . layout . toDeviceIndependentPixels ( adjustedPosition . bottom )
188+ ) ;
189+ }
195190 }
196191 controller . preferredContentSize = CGSizeMake ( Utils . layout . toDeviceIndependentPixels ( effectiveWidth ) , Utils . layout . toDeviceIndependentPixels ( effectiveHeight ) ) ;
197192
@@ -449,6 +444,16 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
449444 const animated = this . viewController . nsAnimated ;
450445 parentController . dismissViewControllerAnimatedCompletion ( animated , whenClosedCallback ) ;
451446 }
447+
448+ _unloadBottomSheet ( ) {
449+ if ( this . isLoaded ) {
450+ this . callUnloaded ( ) ;
451+ }
452+ // it is very important to clear the viewController as N does not do it
453+ // and the destroy of the view from svelte could trigger a layout pass on the viewController
454+ this . viewController = null ;
455+ this . _onDismissBottomSheetCallback && this . _onDismissBottomSheetCallback ( ) ;
456+ }
452457}
453458
454459let mixinInstalled = false ;
0 commit comments