@@ -575,21 +575,26 @@ export class CustomLayoutView extends View {
575575 }
576576}
577577
578- function isScrollable ( controller : UIViewController , owner : View ) : boolean {
579- let scrollable = ( < any > owner ) . scrollableContent ;
580- if ( scrollable === undefined ) {
581- const view : UIView = controller . view . subviews . count > 0 ? controller . view . subviews [ 0 ] : null ;
582- if ( view instanceof UIScrollView ) {
583- scrollable = true ;
578+ const majorVersion = iosUtils . MajorVersion ;
579+
580+ export namespace ios {
581+ export function isContentScrollable ( controller : UIViewController , owner : View ) : boolean {
582+ let scrollableContent = ( < any > owner ) . scrollableContent ;
583+ if ( scrollableContent === undefined ) {
584+ const view : UIView = controller . view . subviews . count > 0 ? controller . view . subviews [ 0 ] : null ;
585+ if ( view instanceof UIScrollView ) {
586+ scrollableContent = true ;
587+ }
584588 }
585- }
586589
587- return scrollable === true || scrollable === "true" ; ;
588- }
590+ return scrollableContent === true || scrollableContent === "true" ; ;
591+ }
589592
590- const majorVersion = iosUtils . MajorVersion ;
593+ export function updateAutoAdjustScrollInsets ( controller : UIViewController , owner : View ) : void {
594+ const scrollable = isContentScrollable ( controller , owner ) ;
595+ controller . automaticallyAdjustsScrollViewInsets = scrollable ;
596+ }
591597
592- export namespace ios {
593598 export function updateConstraints ( controller : UIViewController , owner : View ) : void {
594599 const root = controller . view ;
595600 if ( ! root . safeAreaLayoutGuide ) {
@@ -619,67 +624,56 @@ export namespace ios {
619624 }
620625
621626 export function layoutView ( controller : UIViewController , owner : View ) : void {
622- const fullscreen = controller ===
623- iosUtils . getter ( UIApplication , UIApplication . sharedApplication ) . keyWindow . rootViewController ;
624-
625627 let left : number , top : number , width : number , height : number ;
626628
627629 const frame = controller . view . frame ;
628630 const fullscreenOrigin = frame . origin ;
629631 const fullscreenSize = frame . size ;
630-
631- if ( fullscreen ) {
632- left = layout . toDevicePixels ( fullscreenOrigin . x ) ;
633- top = layout . toDevicePixels ( fullscreenOrigin . y ) ;
634- width = layout . toDevicePixels ( fullscreenSize . width ) ;
635- height = layout . toDevicePixels ( fullscreenSize . height ) ;
632+ const safeArea = controller . view . safeAreaLayoutGuide . layoutFrame ;
633+ const safeOrigin = safeArea . origin ;
634+ const safeAreaSize = safeArea . size ;
635+
636+ const navController = controller . navigationController ;
637+ const navBarHidden = navController ? navController . navigationBarHidden : true ;
638+ const scrollable = isContentScrollable ( controller , owner ) ;
639+ const hasChildControllers = controller . childViewControllers . count > 0 ;
640+
641+ const safeAreaTopLength = safeOrigin . y - fullscreenOrigin . y ;
642+ const safeAreaBottomLength = fullscreenSize . height - safeAreaSize . height - safeAreaTopLength ;
643+
644+ if ( ! ( controller . edgesForExtendedLayout & UIRectEdge . Top ) ) {
645+ const statusBarHeight = getStatusBarHeight ( controller ) ;
646+ const navBarHeight = controller . navigationController ? controller . navigationController . navigationBar . frame . size . height : 0 ;
647+ fullscreenOrigin . y = safeOrigin . y ;
648+ fullscreenSize . height -= ( statusBarHeight + navBarHeight ) ;
649+ }
650+
651+ left = safeOrigin . x ;
652+ width = safeAreaSize . width ;
653+
654+ if ( hasChildControllers ) {
655+ // If not inner most extend to fullscreen
656+ top = fullscreenOrigin . y ;
657+ height = fullscreenSize . height ;
658+ } else if ( ! scrollable ) {
659+ // If not scrollable dock under safe area
660+ top = safeOrigin . y ;
661+ height = safeAreaSize . height ;
662+ } else if ( navBarHidden ) {
663+ // If scrollable but no navigation bar dock under safe area
664+ top = safeOrigin . y ;
665+ height = navController ? ( fullscreenSize . height - top ) : safeAreaSize . height ;
636666 } else {
637- const safeArea = controller . view . safeAreaLayoutGuide . layoutFrame ;
638- const safeOrigin = safeArea . origin ;
639- const safeAreaSize = safeArea . size ;
640-
641- const navController = controller . navigationController ;
642- const navBarHidden = navController ? navController . navigationBarHidden : true ;
643- const scrollable = isScrollable ( controller , owner ) ;
644- const hasChildControllers = controller . childViewControllers . count > 0 ;
645-
646- const safeAreaTopLength = safeOrigin . y - fullscreenOrigin . y ;
647- const safeAreaBottomLength = fullscreenSize . height - safeAreaSize . height - safeAreaTopLength ;
648-
649- if ( ! ( controller . edgesForExtendedLayout & UIRectEdge . Top ) ) {
650- const statusBarHeight = getStatusBarHeight ( controller ) ;
651- const navBarHeight = controller . navigationController ? controller . navigationController . navigationBar . frame . size . height : 0 ;
652- fullscreenOrigin . y = safeOrigin . y ;
653- fullscreenSize . height -= ( statusBarHeight + navBarHeight ) ;
654- }
655-
656- left = safeOrigin . x ;
657- width = safeAreaSize . width ;
658-
659- if ( hasChildControllers ) {
660- // If not inner most extend to fullscreen
661- top = fullscreenOrigin . y ;
662- height = fullscreenSize . height ;
663- } else if ( ! scrollable ) {
664- // If not scrollable dock under safe area
665- top = safeOrigin . y ;
666- height = safeAreaSize . height ;
667- } else if ( navBarHidden ) {
668- // If scrollable but no navigation bar dock under safe area
669- top = safeOrigin . y ;
670- height = navController ? ( fullscreenSize . height - top ) : safeAreaSize . height ;
671- } else {
672- // If scrollable and navigation bar extend to fullscreen
673- top = fullscreenOrigin . y ;
674- height = fullscreenSize . height ;
675- }
676-
677- left = layout . toDevicePixels ( left ) ;
678- top = layout . toDevicePixels ( top ) ;
679- width = layout . toDevicePixels ( width ) ;
680- height = layout . toDevicePixels ( height ) ;
667+ // If scrollable and navigation bar extend to fullscreen
668+ top = fullscreenOrigin . y ;
669+ height = fullscreenSize . height ;
681670 }
682671
672+ left = layout . toDevicePixels ( left ) ;
673+ top = layout . toDevicePixels ( top ) ;
674+ width = layout . toDevicePixels ( width ) ;
675+ height = layout . toDevicePixels ( height ) ;
676+
683677 const widthSpec = layout . makeMeasureSpec ( width , layout . EXACTLY ) ;
684678 const heightSpec = layout . makeMeasureSpec ( height , layout . EXACTLY ) ;
685679
@@ -736,7 +730,13 @@ export namespace ios {
736730 public viewWillAppear ( animated : boolean ) : void {
737731 super . viewWillAppear ( animated ) ;
738732 const owner = this . owner . get ( ) ;
739- if ( owner && ! owner . parent ) {
733+ if ( ! owner ) {
734+ return ;
735+ }
736+
737+ updateAutoAdjustScrollInsets ( this , owner ) ;
738+
739+ if ( ! owner . parent ) {
740740 owner . callLoaded ( ) ;
741741 }
742742 }
0 commit comments