@@ -56,6 +56,37 @@ const warnUnavailableSpace = (node: SafeNode) => {
5656 ) ;
5757} ;
5858
59+ const breakableViewChild = ( children , height , path = '' , currentChildren ) => {
60+ for ( let i = 0 ; i < children . length ; i += 1 ) {
61+ if ( children [ i ] . type !== 'VIEW' ) continue ;
62+
63+ if (
64+ shouldNodeBreak (
65+ children [ i ] ,
66+ children . slice ( i + 1 , height ) ,
67+ height ,
68+ currentChildren ,
69+ )
70+ ) {
71+ return {
72+ child : children [ i ] ,
73+ path : `${ path } /${ i } ` ,
74+ } ;
75+ }
76+
77+ if ( children [ i ] . children && children [ i ] . children . length > 0 ) {
78+ const breakable = breakableViewChild (
79+ children [ i ] . children ,
80+ height ,
81+ `${ path } /${ i } ` ,
82+ currentChildren ,
83+ ) ;
84+ if ( breakable ) return breakable ;
85+ }
86+ }
87+ return null ;
88+ } ;
89+
5990const splitNodes = ( height : number , contentArea : number , nodes : SafeNode [ ] ) => {
6091 const currentChildren : SafeNode [ ] = [ ] ;
6192 const nextChildren : SafeNode [ ] = [ ] ;
@@ -74,6 +105,12 @@ const splitNodes = (height: number, contentArea: number, nodes: SafeNode[]) => {
74105 height ,
75106 currentChildren ,
76107 ) ;
108+
109+ const firstBreakableViewChild =
110+ child . children &&
111+ child . children . length > 0 &&
112+ breakableViewChild ( child . children , height , '' , currentChildren ) ;
113+
77114 const prevChild = nodes . length > 0 && i > 0 ? nodes [ i - 1 ] : undefined ;
78115 const shouldSplit = height + SAFETY_THRESHOLD < nodeTop + nodeHeight ;
79116 const canWrap = canNodeWrap ( child , prevChild , currentChildren ) ;
@@ -97,6 +134,7 @@ const splitNodes = (height: number, contentArea: number, nodes: SafeNode[]) => {
97134 currentChildren . push ( child ) ;
98135 nextChildren . push ( ...futureNodes ) ;
99136 warnUnavailableSpace ( child ) ;
137+ break ;
100138 } else {
101139 // We don't want to break non wrapable nodes, so we just let them be.
102140 const box = Object . assign ( { } , child . box , {
@@ -110,8 +148,8 @@ const splitNodes = (height: number, contentArea: number, nodes: SafeNode[]) => {
110148
111149 currentChildren . push ( ...futureFixedNodes ) ;
112150 nextChildren . push ( next , ...futureNodes ) ;
151+ break ;
113152 }
114- break ;
115153 }
116154
117155 if ( shouldBreak ) {
@@ -127,7 +165,7 @@ const splitNodes = (height: number, contentArea: number, nodes: SafeNode[]) => {
127165 break ;
128166 }
129167
130- if ( shouldSplit ) {
168+ if ( shouldSplit || firstBreakableViewChild ) {
131169 const [ currentChild , nextChild ] = split ( child , height , contentArea ) ;
132170
133171 // All children are moved to the next page, it doesn't make sense to show the parent on the current page
@@ -137,10 +175,10 @@ const splitNodes = (height: number, contentArea: number, nodes: SafeNode[]) => {
137175 // currentChildren.push(child, ...futureFixedNodes);
138176 // nextChildren.push(...futureNodes);
139177 // } else {
140- const box = Object . assign ( { } , child . box , {
141- top : child . box . top - height ,
178+ const box = Object . assign ( { } , nextChild . box , {
179+ top : nextChild . box . top - height ,
142180 } ) ;
143- const next = Object . assign ( { } , child , { box } ) ;
181+ const next = Object . assign ( { } , nextChild , { box } ) ;
144182
145183 currentChildren . push ( ...futureFixedNodes ) ;
146184 nextChildren . push ( next , ...futureNodes ) ;
0 commit comments