Skip to content

Commit

Permalink
Allow for customization of the preview name
Browse files Browse the repository at this point in the history
  • Loading branch information
nsillik committed Feb 7, 2024
1 parent 0fbe962 commit de5d23a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
14 changes: 4 additions & 10 deletions BlueprintUI/Sources/BlueprintView/ElementPreview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,34 +191,28 @@ extension ElementPreview {
for element: Element
) -> AnyView {

let formattedName: String = {
if name.isEmpty == false {
return "" + name
} else {
return ""
}
}()
let formattedName: String? = name.isEmpty ? nil : name

switch self {
case .device(let device):
return AnyView(
constrained(element: element)
.previewDevice(.init(rawValue: device.rawValue))
.previewDisplayName(device.rawValue + formattedName)
.previewDisplayName(formattedName)
)

case .fixed(let width, let height):
return AnyView(
constrained(element: element)
.previewLayout(.fixed(width: width, height: height))
.previewDisplayName("Fixed Size: (\(width), \(height))" + formattedName)
.previewDisplayName(formattedName)
)

case .thatFits(let padding):
return AnyView(
constrained(element: element)
.previewLayout(.sizeThatFits)
.previewDisplayName("Size That Fits" + formattedName)
.previewDisplayName(formattedName)
.padding(.all, padding)
)
}
Expand Down
3 changes: 3 additions & 0 deletions SampleApp/Sources/XcodePreviewDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ struct TestingView_Preview: PreviewProvider {
ElementPreview(with: .thatFits(padding: 5)) {
TestElement()
}
ElementPreview(named: "with a name", with: .thatFits(padding: 5)) {
TestElement()
}
}
}

Expand Down

0 comments on commit de5d23a

Please sign in to comment.