Skip to content

Commit

Permalink
Add frame modifier for size modification (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
takumatt authored Apr 8, 2024
1 parent 5bae50c commit 3042c19
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
12 changes: 4 additions & 8 deletions Development/Demo/Components/Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ enum Mocks {
AnyDisplayNode { _, _ in
LayoutSpec {
shape
.height(16)
.width(120)
.frame(width: 120, height: 16)
.padding(2)
}
}
Expand All @@ -85,8 +84,7 @@ enum Mocks {
AnyDisplayNode { _, _ in
LayoutSpec {
shape
.height(6)
.width(20)
.frame(width: 20, height: 6)
.padding(2)
}
}
Expand All @@ -107,8 +105,7 @@ enum Mocks {
AnyDisplayNode { _, _ in
LayoutSpec {
shape
.width(28)
.height(28)
.frame(width: 28, height: 28)
.padding(2)
}
}
Expand All @@ -132,8 +129,7 @@ enum Mocks {
LayoutSpec {
VStackLayout(spacing: 2) {
shapes
.width(120)
.height(16)
.frame(width: 120, height: 16)
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions Sources/LayoutSpecBuilders/Modifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,33 @@ extension _ASLayoutElementType {
public func spacingBefore(_ spacing: CGFloat) -> ModifiedContent<Self, SpacingModifier> {
modifier(SpacingModifier(after: nil, before: spacing))
}

public func frame(width: CGFloat? = nil, height: CGFloat? = nil) -> ModifiedContent<Self, SizeModifier> {
let width: ASDimension? = if let width { .init(unit: .points, value: width) } else { nil }
let height: ASDimension? = if let height { .init(unit: .points, value: height) } else { nil }
return modifier(SizeModifier(
width: width,
height: height
))
}

public func frame(minWidth: CGFloat? = nil, minHeight: CGFloat? = nil) -> ModifiedContent<Self, MinSizeModifier> {
let minWidth: ASDimension? = if let minWidth { .init(unit: .points, value: minWidth) } else { nil }
let minHeight: ASDimension? = if let minHeight { .init(unit: .points, value: minHeight) } else { nil }
return modifier(MinSizeModifier(
minWidth: minWidth,
minHeight: minHeight
))
}

public func frame(maxWidth: CGFloat? = nil, maxHeight: CGFloat? = nil) -> ModifiedContent<Self, MaxSizeModifier> {
let maxWidth: ASDimension? = if let maxWidth { .init(unit: .points, value: maxWidth) } else { nil }
let maxHeight: ASDimension? = if let maxHeight { .init(unit: .points, value: maxHeight) } else { nil }
return modifier(MaxSizeModifier(
maxWidth: maxWidth,
maxHeight: maxHeight
))
}

}

Expand Down

0 comments on commit 3042c19

Please sign in to comment.