Skip to content

Commit

Permalink
Rename Grow -> Fill
Browse files Browse the repository at this point in the history
  • Loading branch information
psharanda committed Feb 15, 2024
1 parent 5dba1d0 commit 2027173
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 71 deletions.
46 changes: 23 additions & 23 deletions FixFlexSamples/FixFlexSamples/Stories/FixFlexStories.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ class FixFlexStories: DynamicComponentStories {
parent.widthAnchor.constraint(equalToConstant: 200).isActive = true
parent.heightAnchor.constraint(equalToConstant: 100).isActive = true

parent.fx.hstack(Grow(),
parent.fx.hstack(Fill(),
Fix(child, 100),
Grow())
Fill())

parent.fx.vstack(Grow(),
parent.fx.vstack(Fill(),
Fix(child, 50),
Grow())
Fill())

return parent
}
Expand All @@ -91,13 +91,13 @@ class FixFlexStories: DynamicComponentStories {
parent.widthAnchor.constraint(equalToConstant: 200).isActive = true
parent.heightAnchor.constraint(equalToConstant: 200).isActive = true

parent.fx.hstack(Grow(),
parent.fx.hstack(Fill(),
Flex(label),
Grow())
Fill())

parent.fx.vstack(Grow(),
parent.fx.vstack(Fill(),
Flex(label),
Grow())
Fill())

return parent
}
Expand Down Expand Up @@ -126,11 +126,11 @@ class FixFlexStories: DynamicComponentStories {

parent.fx.hstack(Flex([topLabel, bottomLabel]))

parent.fx.vstack(Grow(),
parent.fx.vstack(Fill(),
Flex(topLabel),
Fix(5),
Flex(bottomLabel),
Grow())
Fill())

return parent
}
Expand Down Expand Up @@ -182,9 +182,9 @@ class FixFlexStories: DynamicComponentStories {
Flex(subtitleLabel),
Fix(15))

parent.fx.vstack(Grow(),
parent.fx.vstack(Fill(),
Fix(chevron, 30),
Grow())
Fill())

return parent
}
Expand Down Expand Up @@ -294,11 +294,11 @@ class FixFlexStories: DynamicComponentStories {
Fix(5))

parent.fx.hstack(Fix(5),
Grow(label1, weight: 2),
Fill(label1, weight: 2),
Fix(5),
Grow(label2),
Fill(label2),
Fix(5),
Grow(label3),
Fill(label3),
Fix(5))

return parent
Expand Down Expand Up @@ -380,9 +380,9 @@ class FixFlexStories: DynamicComponentStories {

parent.fx.vstack(Flex([label, leadingView, trailingView]))

parent.fx.hstack(Grow(),
parent.fx.hstack(Fill(),
Flex(label),
Grow())
Fill())

parent.fx.hstack(startAnchor: label.leadingAnchor,
endAnchor: label.trailingAnchor,
Expand Down Expand Up @@ -417,9 +417,9 @@ class FixFlexStories: DynamicComponentStories {

parent.fx.vstack(Flex([label, leadingView, trailingView]))

parent.fx.hstack(Grow(),
parent.fx.hstack(Fill(),
Flex(label),
Grow())
Fill())

parent.fx.hstack(startAnchor: label.leftAnchor,
endAnchor: label.rightAnchor,
Expand Down Expand Up @@ -451,13 +451,13 @@ class FixFlexStories: DynamicComponentStories {
parent.widthAnchor.constraint(equalToConstant: 200).isActive = true
parent.heightAnchor.constraint(equalToConstant: 200).isActive = true

parent.fx.vstack(Grow(),
parent.fx.vstack(Fill(),
Flex(label),
Grow())
Fill())

parent.fx.hstack(Grow(),
parent.fx.hstack(Fill(),
Flex(label),
Grow())
Fill())

parent.fx.vstack(startAnchor: label.topAnchor,
Fix(10),
Expand Down
62 changes: 31 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ parent.fx.vstack(Fix(15),
width="400"
/>

To center the chevron, we ensure the top spacing is equal to the bottom spacing using `Grow`:
To center the chevron, we ensure the top spacing is equal to the bottom spacing using `Fill`:

```swift
parent.fx.vstack(Grow(),
parent.fx.vstack(Fill(),
Fix(chevron, 30),
Grow())
Fill())
```

That's it! The best part is how easy it is to modify FixFlex layout code, inserting extra padding or views effortlessly, without the need to rewire constraints.
Expand Down Expand Up @@ -150,16 +150,16 @@ func Flex(_ view: _View, min: CGFloat? = nil, max: CGFloat? = nil, huggingPriori
func Flex(_ views: [_View], min: CGFloat? = nil, max: CGFloat? = nil, huggingPriority: _LayoutPriority? = nil, compressionResistancePriority: _LayoutPriority? = nil) -> SizingIntent
```

### Grow
### Fill

`Grow` allows a view/spacer to proportionally occupy the available free space based on its weight. It's particularly useful for achieving equal spacing, centering elements, or for designing symmetrical layouts like tables or grids.
`Fill` allows a view/spacer to proportionally occupy the available free space based on its weight. It's particularly useful for achieving equal spacing, centering elements, or for designing symmetrical layouts like tables or grids.

```swift
func Grow(weight: CGFloat = 1.0) -> SizingIntent
func Fill(weight: CGFloat = 1.0) -> SizingIntent

func Grow(_ view: _View, weight: CGFloat = 1.0) -> SizingIntent
func Fill(_ view: _View, weight: CGFloat = 1.0) -> SizingIntent

func Grow(_ views: [_View], weight: CGFloat = 1.0) -> SizingIntent
func Fill(_ views: [_View], weight: CGFloat = 1.0) -> SizingIntent
```

### Match
Expand Down Expand Up @@ -257,13 +257,13 @@ parent.addSubview(child)
parent.widthAnchor.constraint(equalToConstant: 200).isActive = true
parent.heightAnchor.constraint(equalToConstant: 100).isActive = true

parent.fx.hstack(Grow(),
parent.fx.hstack(Fill(),
Fix(child, 100),
Grow())
Fill())

parent.fx.vstack(Grow(),
parent.fx.vstack(Fill(),
Fix(child, 50),
Grow())
Fill())
```


Expand All @@ -290,13 +290,13 @@ parent.addSubview(label)
parent.widthAnchor.constraint(equalToConstant: 200).isActive = true
parent.heightAnchor.constraint(equalToConstant: 200).isActive = true

parent.fx.hstack(Grow(),
parent.fx.hstack(Fill(),
Flex(label),
Grow())
Fill())

parent.fx.vstack(Grow(),
parent.fx.vstack(Fill(),
Flex(label),
Grow())
Fill())
```


Expand Down Expand Up @@ -332,11 +332,11 @@ parent.heightAnchor.constraint(equalToConstant: 200).isActive = true

parent.fx.hstack(Flex([topLabel, bottomLabel]))

parent.fx.vstack(Grow(),
parent.fx.vstack(Fill(),
Flex(topLabel),
Fix(5),
Flex(bottomLabel),
Grow())
Fill())
```


Expand Down Expand Up @@ -395,9 +395,9 @@ parent.fx.vstack(Fix(15),
Flex(subtitleLabel),
Fix(15))

parent.fx.vstack(Grow(),
parent.fx.vstack(Fill(),
Fix(chevron, 30),
Grow())
Fill())
```


Expand Down Expand Up @@ -528,11 +528,11 @@ parent.fx.vstack(Fix(5),
Fix(5))

parent.fx.hstack(Fix(5),
Grow(label1, weight: 2),
Fill(label1, weight: 2),
Fix(5),
Grow(label2),
Fill(label2),
Fix(5),
Grow(label3),
Fill(label3),
Fix(5))
```

Expand Down Expand Up @@ -628,9 +628,9 @@ parent.widthAnchor.constraint(equalToConstant: 200).isActive = true

parent.fx.vstack(Flex([label, leadingView, trailingView]))

parent.fx.hstack(Grow(),
parent.fx.hstack(Fill(),
Flex(label),
Grow())
Fill())

parent.fx.hstack(startAnchor: label.leadingAnchor,
endAnchor: label.trailingAnchor,
Expand Down Expand Up @@ -672,9 +672,9 @@ parent.widthAnchor.constraint(equalToConstant: 200).isActive = true

parent.fx.vstack(Flex([label, leadingView, trailingView]))

parent.fx.hstack(Grow(),
parent.fx.hstack(Fill(),
Flex(label),
Grow())
Fill())

parent.fx.hstack(startAnchor: label.leftAnchor,
endAnchor: label.rightAnchor,
Expand Down Expand Up @@ -713,13 +713,13 @@ parent.addSubview(label)
parent.widthAnchor.constraint(equalToConstant: 200).isActive = true
parent.heightAnchor.constraint(equalToConstant: 200).isActive = true

parent.fx.vstack(Grow(),
parent.fx.vstack(Fill(),
Flex(label),
Grow())
Fill())

parent.fx.hstack(Grow(),
parent.fx.hstack(Fill(),
Flex(label),
Grow())
Fill())

parent.fx.vstack(startAnchor: label.topAnchor,
Fix(10),
Expand Down
16 changes: 8 additions & 8 deletions Readme/src/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ parent.fx.vstack(Fix(15),
width="400"
/>

To center the chevron, we ensure the top spacing is equal to the bottom spacing using `Grow`:
To center the chevron, we ensure the top spacing is equal to the bottom spacing using `Fill`:

```swift
parent.fx.vstack(Grow(),
parent.fx.vstack(Fill(),
Fix(chevron, 30),
Grow())
Fill())
```

That's it! The best part is how easy it is to modify FixFlex layout code, inserting extra padding or views effortlessly, without the need to rewire constraints.
Expand Down Expand Up @@ -150,16 +150,16 @@ func Flex(_ view: _View, min: CGFloat? = nil, max: CGFloat? = nil, huggingPriori
func Flex(_ views: [_View], min: CGFloat? = nil, max: CGFloat? = nil, huggingPriority: _LayoutPriority? = nil, compressionResistancePriority: _LayoutPriority? = nil) -> SizingIntent
```

### Grow
### Fill

`Grow` allows a view/spacer to proportionally occupy the available free space based on its weight. It's particularly useful for achieving equal spacing, centering elements, or for designing symmetrical layouts like tables or grids.
`Fill` allows a view/spacer to proportionally occupy the available free space based on its weight. It's particularly useful for achieving equal spacing, centering elements, or for designing symmetrical layouts like tables or grids.

```swift
func Grow(weight: CGFloat = 1.0) -> SizingIntent
func Fill(weight: CGFloat = 1.0) -> SizingIntent

func Grow(_ view: _View, weight: CGFloat = 1.0) -> SizingIntent
func Fill(_ view: _View, weight: CGFloat = 1.0) -> SizingIntent

func Grow(_ views: [_View], weight: CGFloat = 1.0) -> SizingIntent
func Fill(_ views: [_View], weight: CGFloat = 1.0) -> SizingIntent
```

### Match
Expand Down
18 changes: 9 additions & 9 deletions Sources/FixFlex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct SizingIntent {
case fix(value: CGFloat)
case flex(min: CGFloat?, max: CGFloat?, huggingPriority: _LayoutPriority?, compressionResistancePriority: _LayoutPriority?)
case match(dimension: NSLayoutDimension, multiplier: CGFloat?, offset: CGFloat?)
case grow(weight: CGFloat)
case fill(weight: CGFloat)
}

let sizing: Sizing
Expand Down Expand Up @@ -86,18 +86,18 @@ public func Match(_ views: [_View], dimension: NSLayoutDimension, multiplier: CG
return SizingIntent(views: views, sizing: .match(dimension: dimension, multiplier: multiplier, offset: offset))
}

/// Grow shorthands
/// Fill shorthands

public func Grow(weight: CGFloat = 1.0) -> SizingIntent {
return SizingIntent(views: nil, sizing: .grow(weight: weight))
public func Fill(weight: CGFloat = 1.0) -> SizingIntent {
return SizingIntent(views: nil, sizing: .fill(weight: weight))
}

public func Grow(_ view: _View, weight: CGFloat = 1.0) -> SizingIntent {
return Grow([view], weight: weight)
public func Fill(_ view: _View, weight: CGFloat = 1.0) -> SizingIntent {
return Fill([view], weight: weight)
}

public func Grow(_ views: [_View], weight: CGFloat = 1.0) -> SizingIntent {
return SizingIntent(views: views, sizing: .grow(weight: weight))
public func Fill(_ views: [_View], weight: CGFloat = 1.0) -> SizingIntent {
return SizingIntent(views: views, sizing: .fill(weight: weight))
}

/// Axis anchors abstraction
Expand Down Expand Up @@ -242,7 +242,7 @@ public extension FixFlexing {
}
case let .match(dimension, multiplier, offset):
handleSizingConstraint(aa.dimensionAnchor.constraint(equalTo: dimension, multiplier: multiplier ?? 1, constant: offset ?? 0))
case let .grow(weight):
case let .fill(weight):
if let weightsInfo {
handleSizingConstraint(aa.dimensionAnchor.constraint(equalTo: weightsInfo.dimensionAnchor,
multiplier: weight / weightsInfo.weight))
Expand Down

0 comments on commit 2027173

Please sign in to comment.