diff --git a/BlueprintUI/Sources/BlueprintView/ElementPreview.swift b/BlueprintUI/Sources/BlueprintView/ElementPreview.swift index 9c6129520..46802d153 100644 --- a/BlueprintUI/Sources/BlueprintView/ElementPreview.swift +++ b/BlueprintUI/Sources/BlueprintView/ElementPreview.swift @@ -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) ) } diff --git a/CHANGELOG.md b/CHANGELOG.md index ed93471c4..010b4a4c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- The behavior of `name` of `ElementPreview` has been change, affecting the SwiftUI `previewName`. Instead of including device or size information (i.e. `sizeThatFits - \(name)`), it now either defaults to the Xcode default if given an empty string, and shows _only_ the `name` if `name` is non-empty. - Updated minimum deployment target from iOS 14 to iOS 15. ### Deprecated diff --git a/SampleApp/Sources/XcodePreviewDemo.swift b/SampleApp/Sources/XcodePreviewDemo.swift index a9d6e91cf..3adb0f180 100644 --- a/SampleApp/Sources/XcodePreviewDemo.swift +++ b/SampleApp/Sources/XcodePreviewDemo.swift @@ -32,6 +32,9 @@ struct TestingView_Preview: PreviewProvider { ElementPreview(with: .thatFits(padding: 5)) { TestElement() } + ElementPreview(named: "with a name", with: .thatFits(padding: 5)) { + TestElement() + } } }