@@ -83,19 +83,63 @@ public extension View {
8383// MARK: - Frame
8484
8585public struct _FrameModifier : RenderModifier {
86- let width : Double ?
87- let height : Double ?
86+ var width : Double ? = nil
87+ var height : Double ? = nil
88+ var minWidth : Double ? = nil
89+ var idealWidth : Double ? = nil
90+ var maxWidth : Double ? = nil
91+ var minHeight : Double ? = nil
92+ var idealHeight : Double ? = nil
93+ var maxHeight : Double ? = nil
94+ var alignment : Alignment = . center
95+
8896 public var _modifierNode : ModifierNode {
8997 var args : [ String : PropValue ] = [ : ]
9098 if let width { args [ " width " ] = . double( width) }
9199 if let height { args [ " height " ] = . double( height) }
100+ if let minWidth { args [ " minWidth " ] = . double( minWidth) }
101+ if let idealWidth { args [ " idealWidth " ] = . double( idealWidth) }
102+ // .infinity can't cross as a JSON number, so a fill flag carries it.
103+ if let maxWidth {
104+ if maxWidth == . infinity { args [ " fillWidth " ] = . bool( true ) }
105+ else { args [ " maxWidth " ] = . double( maxWidth) }
106+ }
107+ if let minHeight { args [ " minHeight " ] = . double( minHeight) }
108+ if let idealHeight { args [ " idealHeight " ] = . double( idealHeight) }
109+ if let maxHeight {
110+ if maxHeight == . infinity { args [ " fillHeight " ] = . bool( true ) }
111+ else { args [ " maxHeight " ] = . double( maxHeight) }
112+ }
113+ if alignment. horizontal != . center || alignment. vertical != . center {
114+ args [ " horizontal " ] = . string( alignment. horizontal. rawValue)
115+ args [ " vertical " ] = . string( alignment. vertical. rawValue)
116+ }
92117 return ModifierNode ( kind: " frame " , args: args)
93118 }
94119}
95120
96121public extension View {
97- func frame( width: Double ? = nil , height: Double ? = nil ) -> ModifiedContent < Self , _FrameModifier > {
98- modifier ( _FrameModifier ( width: width, height: height) )
122+ /// A fixed frame, optionally aligning the content within it.
123+ func frame( width: Double ? = nil , height: Double ? = nil , alignment: Alignment = . center) -> ModifiedContent < Self , _FrameModifier > {
124+ modifier ( _FrameModifier ( width: width, height: height, alignment: alignment) )
125+ }
126+
127+ /// A flexible frame with size bounds. `maxWidth`/`maxHeight` of `.infinity`
128+ /// expand to fill the available space.
129+ func frame(
130+ minWidth: Double ? = nil ,
131+ idealWidth: Double ? = nil ,
132+ maxWidth: Double ? = nil ,
133+ minHeight: Double ? = nil ,
134+ idealHeight: Double ? = nil ,
135+ maxHeight: Double ? = nil ,
136+ alignment: Alignment = . center
137+ ) -> ModifiedContent < Self , _FrameModifier > {
138+ modifier ( _FrameModifier (
139+ minWidth: minWidth, idealWidth: idealWidth, maxWidth: maxWidth,
140+ minHeight: minHeight, idealHeight: idealHeight, maxHeight: maxHeight,
141+ alignment: alignment
142+ ) )
99143 }
100144}
101145
0 commit comments