@@ -789,36 +789,32 @@ export namespace ios {
789789 }
790790
791791 export function expandBeyondSafeArea ( view : View , frame : CGRect ) : CGRect {
792- const locationInWindow = view . getLocationInWindow ( ) ;
793- const inWindowLeft = layout . round ( layout . toDevicePixels ( locationInWindow . x ) ) ;
794- const inWindowTop = layout . round ( layout . toDevicePixels ( locationInWindow . y ) ) ;
795- const inWindowRight = inWindowLeft + layout . round ( layout . toDevicePixels ( frame . size . width ) ) ;
796- const inWindowBottom = inWindowTop + layout . round ( layout . toDevicePixels ( frame . size . height ) ) ;
797-
798- const availableSpace = getAvailableSpaceFromParent ( view ) ;
792+ const availableSpace = getAvailableSpaceFromParent ( view , frame ) ;
799793 const safeArea = availableSpace . safeArea ;
800794 const fullscreen = availableSpace . fullscreen ;
795+ const inWindow = availableSpace . inWindow ;
801796
802797 const position = ios . getPositionFromFrame ( frame ) ;
803798 const safeAreaPosition = ios . getPositionFromFrame ( safeArea ) ;
804799 const fullscreenPosition = ios . getPositionFromFrame ( fullscreen ) ;
800+ const inWindowPosition = ios . getPositionFromFrame ( inWindow ) ;
805801
806802 const adjustedPosition = position ;
807803
808- if ( position . left && inWindowLeft <= safeAreaPosition . left ) {
804+ if ( position . left && inWindowPosition . left <= safeAreaPosition . left ) {
809805 adjustedPosition . left = fullscreenPosition . left ;
810806 }
811807
812- if ( position . top && inWindowTop <= safeAreaPosition . top ) {
808+ if ( position . top && inWindowPosition . top <= safeAreaPosition . top ) {
813809 adjustedPosition . top = fullscreenPosition . top ;
814810 }
815811
816- if ( inWindowRight < fullscreenPosition . right && inWindowRight >= safeAreaPosition . right + fullscreenPosition . left ) {
817- adjustedPosition . right += fullscreenPosition . right - inWindowRight ;
812+ if ( inWindowPosition . right < fullscreenPosition . right && inWindowPosition . right >= safeAreaPosition . right + fullscreenPosition . left ) {
813+ adjustedPosition . right += fullscreenPosition . right - inWindowPosition . right ;
818814 }
819815
820- if ( inWindowBottom < fullscreenPosition . bottom && inWindowBottom >= safeAreaPosition . bottom + fullscreenPosition . top ) {
821- adjustedPosition . bottom += fullscreenPosition . bottom - inWindowBottom ;
816+ if ( inWindowPosition . bottom < fullscreenPosition . bottom && inWindowPosition . bottom >= safeAreaPosition . bottom + fullscreenPosition . top ) {
817+ adjustedPosition . bottom += fullscreenPosition . bottom - inWindowPosition . bottom ;
822818 }
823819
824820 const adjustedFrame = CGRectMake ( layout . toDeviceIndependentPixels ( adjustedPosition . left ) , layout . toDeviceIndependentPixels ( adjustedPosition . top ) , layout . toDeviceIndependentPixels ( adjustedPosition . right - adjustedPosition . left ) , layout . toDeviceIndependentPixels ( adjustedPosition . bottom - adjustedPosition . top ) ) ;
@@ -849,37 +845,54 @@ export namespace ios {
849845 layoutParent ( view . parent ) ;
850846 }
851847
852- function getAvailableSpaceFromParent ( view : View ) : { safeArea : CGRect , fullscreen : CGRect } {
848+ function getAvailableSpaceFromParent ( view : View , frame : CGRect ) : { safeArea : CGRect , fullscreen : CGRect , inWindow : CGRect } {
853849 if ( ! view ) {
854850 return ;
855851 }
856852
857- let fullscreen = null ;
858- let safeArea = null ;
853+ let scrollView = null ;
854+ let viewControllerView = null ;
859855
860856 if ( view . viewController ) {
861- const nativeView = view . viewController . view ;
862- safeArea = nativeView . safeAreaLayoutGuide . layoutFrame ;
863- fullscreen = nativeView . frame ;
857+ viewControllerView = view . viewController . view ;
864858 } else {
865859 let parent = view . parent as View ;
866860 while ( parent && ! parent . viewController && ! ( parent . nativeViewProtected instanceof UIScrollView ) ) {
867861 parent = parent . parent as View ;
868862 }
869863
870864 if ( parent . nativeViewProtected instanceof UIScrollView ) {
871- const nativeView = parent . nativeViewProtected ;
872- const insets = nativeView . safeAreaInsets ;
873- safeArea = CGRectMake ( insets . left , insets . top , nativeView . contentSize . width - insets . left - insets . right , nativeView . contentSize . height - insets . top - insets . bottom ) ;
874- fullscreen = CGRectMake ( 0 , 0 , nativeView . contentSize . width , nativeView . contentSize . height ) ;
865+ scrollView = parent . nativeViewProtected ;
875866 } else if ( parent . viewController ) {
876- const nativeView = parent . viewController . view ;
877- safeArea = nativeView . safeAreaLayoutGuide . layoutFrame ;
878- fullscreen = nativeView . frame ;
867+ viewControllerView = parent . viewController . view ;
879868 }
880869 }
881870
882- return { safeArea : safeArea , fullscreen : fullscreen }
871+ let fullscreen = null ;
872+ let safeArea = null ;
873+
874+ if ( viewControllerView ) {
875+ safeArea = viewControllerView . safeAreaLayoutGuide . layoutFrame ;
876+ fullscreen = viewControllerView . frame ;
877+ }
878+ else if ( scrollView ) {
879+ const insets = scrollView . safeAreaInsets ;
880+ safeArea = CGRectMake ( insets . left , insets . top , scrollView . contentSize . width - insets . left - insets . right , scrollView . contentSize . height - insets . top - insets . bottom ) ;
881+ fullscreen = CGRectMake ( 0 , 0 , scrollView . contentSize . width , scrollView . contentSize . height ) ;
882+ }
883+
884+ const locationInWindow = view . getLocationInWindow ( ) ;
885+ let inWindowLeft = locationInWindow . x ;
886+ let inWindowTop = locationInWindow . y ;
887+
888+ if ( scrollView ) {
889+ inWindowLeft += scrollView . contentOffset . x ;
890+ inWindowTop += scrollView . contentOffset . y ;
891+ }
892+
893+ const inWindow = CGRectMake ( inWindowLeft , inWindowTop , frame . size . width , frame . size . height ) ;
894+
895+ return { safeArea : safeArea , fullscreen : fullscreen , inWindow : inWindow }
883896 }
884897
885898 export class UILayoutViewController extends UIViewController {
0 commit comments