@@ -3,39 +3,39 @@ import { numberToFixedString } from "../../common/numToAutoFixed";
33
44export const swiftuiSize = (
55 node : SceneNode ,
6- optimizeLayout : boolean = false ,
7- ) : { width : string ; height : string } => {
8- const size = nodeSize ( node , optimizeLayout ) ;
6+ optimize : boolean = false ,
7+ ) : { width : string ; height : string ; constraints : string [ ] } => {
8+ const size = nodeSize ( node , optimize ) ;
99
10- // if width is set as maxWidth, height must also be set as maxHeight (not height)
11- const shouldExtend = size . height === "fill" || size . width === "fill" ;
10+ const constraintProps : string [ ] = [ ] ;
11+ let width = "" ;
12+ let height = "" ;
1213
13- // this cast will always be true, since nodeWidthHeight was called with false to relative.
14- let propWidth = "" ;
14+ // Handle width and height
1515 if ( typeof size . width === "number" ) {
16- const w = numberToFixedString ( size . width ) ;
17-
18- if ( shouldExtend ) {
19- propWidth = `minWidth: ${ w } , maxWidth: ${ w } ` ;
20- } else {
21- propWidth = `width: ${ w } ` ;
22- }
23- } else if ( size . width === "fill" ) {
24- propWidth = `maxWidth: .infinity` ;
16+ width = `width: ${ numberToFixedString ( size . width ) } ` ;
2517 }
26-
27- let propHeight = "" ;
2818 if ( typeof size . height === "number" ) {
29- const h = numberToFixedString ( size . height ) ;
19+ height = `height: ${ numberToFixedString ( size . height ) } ` ;
20+ }
3021
31- if ( shouldExtend ) {
32- propHeight = `minHeight: ${ h } , maxHeight: ${ h } ` ;
33- } else {
34- propHeight = `height: ${ h } ` ;
35- }
36- } else if ( size . height === "fill" ) {
37- propHeight = `maxHeight: .infinity` ;
22+ // Handle min/max constraints
23+ if ( node . minWidth !== undefined && node . minWidth !== null ) {
24+ constraintProps . push ( `minWidth: ${ numberToFixedString ( node . minWidth ) } ` ) ;
25+ }
26+ if ( node . maxWidth !== undefined && node . maxWidth !== null ) {
27+ constraintProps . push ( `maxWidth: ${ numberToFixedString ( node . maxWidth ) } ` ) ;
28+ }
29+ if ( node . minHeight !== undefined && node . minHeight !== null ) {
30+ constraintProps . push ( `minHeight: ${ numberToFixedString ( node . minHeight ) } ` ) ;
31+ }
32+ if ( node . maxHeight !== undefined && node . maxHeight !== null ) {
33+ constraintProps . push ( `maxHeight: ${ numberToFixedString ( node . maxHeight ) } ` ) ;
3834 }
3935
40- return { width : propWidth , height : propHeight } ;
36+ return {
37+ width,
38+ height,
39+ constraints : constraintProps ,
40+ } ;
4141} ;
0 commit comments