Skip to content

Commit 3042c19

Browse files
authored
Add frame modifier for size modification (#116)
1 parent 5bae50c commit 3042c19

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

Development/Demo/Components/Mocks.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ enum Mocks {
6565
AnyDisplayNode { _, _ in
6666
LayoutSpec {
6767
shape
68-
.height(16)
69-
.width(120)
68+
.frame(width: 120, height: 16)
7069
.padding(2)
7170
}
7271
}
@@ -85,8 +84,7 @@ enum Mocks {
8584
AnyDisplayNode { _, _ in
8685
LayoutSpec {
8786
shape
88-
.height(6)
89-
.width(20)
87+
.frame(width: 20, height: 6)
9088
.padding(2)
9189
}
9290
}
@@ -107,8 +105,7 @@ enum Mocks {
107105
AnyDisplayNode { _, _ in
108106
LayoutSpec {
109107
shape
110-
.width(28)
111-
.height(28)
108+
.frame(width: 28, height: 28)
112109
.padding(2)
113110
}
114111
}
@@ -132,8 +129,7 @@ enum Mocks {
132129
LayoutSpec {
133130
VStackLayout(spacing: 2) {
134131
shapes
135-
.width(120)
136-
.height(16)
132+
.frame(width: 120, height: 16)
137133
}
138134
}
139135
}

Sources/LayoutSpecBuilders/Modifiers.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,33 @@ extension _ASLayoutElementType {
426426
public func spacingBefore(_ spacing: CGFloat) -> ModifiedContent<Self, SpacingModifier> {
427427
modifier(SpacingModifier(after: nil, before: spacing))
428428
}
429+
430+
public func frame(width: CGFloat? = nil, height: CGFloat? = nil) -> ModifiedContent<Self, SizeModifier> {
431+
let width: ASDimension? = if let width { .init(unit: .points, value: width) } else { nil }
432+
let height: ASDimension? = if let height { .init(unit: .points, value: height) } else { nil }
433+
return modifier(SizeModifier(
434+
width: width,
435+
height: height
436+
))
437+
}
438+
439+
public func frame(minWidth: CGFloat? = nil, minHeight: CGFloat? = nil) -> ModifiedContent<Self, MinSizeModifier> {
440+
let minWidth: ASDimension? = if let minWidth { .init(unit: .points, value: minWidth) } else { nil }
441+
let minHeight: ASDimension? = if let minHeight { .init(unit: .points, value: minHeight) } else { nil }
442+
return modifier(MinSizeModifier(
443+
minWidth: minWidth,
444+
minHeight: minHeight
445+
))
446+
}
447+
448+
public func frame(maxWidth: CGFloat? = nil, maxHeight: CGFloat? = nil) -> ModifiedContent<Self, MaxSizeModifier> {
449+
let maxWidth: ASDimension? = if let maxWidth { .init(unit: .points, value: maxWidth) } else { nil }
450+
let maxHeight: ASDimension? = if let maxHeight { .init(unit: .points, value: maxHeight) } else { nil }
451+
return modifier(MaxSizeModifier(
452+
maxWidth: maxWidth,
453+
maxHeight: maxHeight
454+
))
455+
}
429456

430457
}
431458

0 commit comments

Comments
 (0)