From ebeb97a46ce154d153b74e379ff428a7519ced35 Mon Sep 17 00:00:00 2001 From: Zeeshan Mian Date: Thu, 1 Feb 2024 18:39:53 +1100 Subject: [PATCH] Switch to `#Preview` macro --- Example/Views/ActivitySheetView.swift | 10 ++-- Example/Views/ButtonsView.swift | 10 ++-- Example/Views/RootView.swift | 8 ++- Example/Views/XLabeledContentView.swift | 10 ++-- .../SwiftUI/Components/CapsuleView.swift | 10 ++-- .../TextField/DynamicTextFieldPreviews.swift | 8 ++- .../StoryView/StoryProgressIndicator.swift | 22 ++++---- .../PageView/StoryView/StoryView.swift | 54 +++++++++---------- .../Popup/Content/PopupAlert+Standard.swift | 42 +++++++-------- .../Components/Popup/Content/PopupAlert.swift | 42 +++++++-------- .../Components/Popup/PopupPreviews.swift | 10 ++-- .../HorizontalBarProgressViewStyle.swift | 42 +++++++-------- .../Xcore/SwiftUI/Components/Shapes/Arc.swift | 30 +++++------ .../Components/Shapes/Parallelogram.swift | 20 +++---- .../Shapes/RoundedRectangleCorner.swift | 20 ++++--- .../SwiftUI/Components/Shapes/Triangle.swift | 12 ++--- .../Components/Sheets/CustomBottomSheet.swift | 2 +- 17 files changed, 159 insertions(+), 193 deletions(-) diff --git a/Example/Views/ActivitySheetView.swift b/Example/Views/ActivitySheetView.swift index 4fec9db6c..08bc776e9 100644 --- a/Example/Views/ActivitySheetView.swift +++ b/Example/Views/ActivitySheetView.swift @@ -45,11 +45,9 @@ struct ActivitySheetView: View { } } -// MARK: - Previews +// MARK: - Preview -struct ActivitySheetView_Previews: PreviewProvider { - static var previews: some View { - ActivitySheetView() - .embedInNavigation() - } +#Preview { + ActivitySheetView() + .embedInNavigation() } diff --git a/Example/Views/ButtonsView.swift b/Example/Views/ButtonsView.swift index 54616f752..aa0fa8531 100644 --- a/Example/Views/ButtonsView.swift +++ b/Example/Views/ButtonsView.swift @@ -193,11 +193,9 @@ extension ButtonsView { } } -// MARK: - Previews +// MARK: - Preview -struct ButtonsView_Previews: PreviewProvider { - static var previews: some View { - ButtonsView() - .embedInNavigation() - } +#Preview { + ButtonsView() + .embedInNavigation() } diff --git a/Example/Views/RootView.swift b/Example/Views/RootView.swift index 1bdd3c27c..085ab6d46 100644 --- a/Example/Views/RootView.swift +++ b/Example/Views/RootView.swift @@ -39,10 +39,8 @@ struct RootView: View { } } -// MARK: - Previews +// MARK: - Preview -struct RootView_Previews: PreviewProvider { - static var previews: some View { - RootView() - } +#Preview { + RootView() } diff --git a/Example/Views/XLabeledContentView.swift b/Example/Views/XLabeledContentView.swift index aa55d595a..ecf8faaac 100644 --- a/Example/Views/XLabeledContentView.swift +++ b/Example/Views/XLabeledContentView.swift @@ -105,11 +105,9 @@ struct XLabeledContentView: View { } } -// MARK: - Previews +// MARK: - Preview -struct XLabeledContentView_Previews: PreviewProvider { - static var previews: some View { - XLabeledContentView() - .embedInNavigation() - } +#Preview { + XLabeledContentView() + .embedInNavigation() } diff --git a/Sources/Xcore/SwiftUI/Components/CapsuleView.swift b/Sources/Xcore/SwiftUI/Components/CapsuleView.swift index b35390cd5..e1b64263e 100644 --- a/Sources/Xcore/SwiftUI/Components/CapsuleView.swift +++ b/Sources/Xcore/SwiftUI/Components/CapsuleView.swift @@ -114,13 +114,11 @@ extension CapsuleView { #if DEBUG -// MARK: - Preview Provider +// MARK: - Preview -struct CapsuleView_Previews: PreviewProvider { - static var previews: some View { - Samples.capsuleViewPreviews - .colorScheme(.light) - } +#Preview { + Samples.capsuleViewPreviews + .colorScheme(.light) } extension Samples { diff --git a/Sources/Xcore/SwiftUI/Components/DynamicTextField/TextField/DynamicTextFieldPreviews.swift b/Sources/Xcore/SwiftUI/Components/DynamicTextField/TextField/DynamicTextFieldPreviews.swift index 4d7b95a3d..29d6c0f4f 100644 --- a/Sources/Xcore/SwiftUI/Components/DynamicTextField/TextField/DynamicTextFieldPreviews.swift +++ b/Sources/Xcore/SwiftUI/Components/DynamicTextField/TextField/DynamicTextFieldPreviews.swift @@ -161,12 +161,10 @@ private struct DataFormatTypesFieldPreview: View { } } -// MARK: - Preview Provider +// MARK: - Preview -struct DynamicTextField_Previews: PreviewProvider { - static var previews: some View { - Samples.dynamicTextFieldPreviews - } +#Preview { + Samples.dynamicTextFieldPreviews } extension Samples { diff --git a/Sources/Xcore/SwiftUI/Components/PageView/StoryView/StoryProgressIndicator.swift b/Sources/Xcore/SwiftUI/Components/PageView/StoryView/StoryProgressIndicator.swift index cbf37d0fe..52de23942 100644 --- a/Sources/Xcore/SwiftUI/Components/PageView/StoryView/StoryProgressIndicator.swift +++ b/Sources/Xcore/SwiftUI/Components/PageView/StoryView/StoryProgressIndicator.swift @@ -23,18 +23,16 @@ public struct StoryProgressIndicator: View { } } -// MARK: - Previews +// MARK: - Preview -struct StoryProgressIndicator_Previews: PreviewProvider { - static var previews: some View { - Group { - StoryProgressIndicator(progress: 0) - StoryProgressIndicator(progress: 1.0) - StoryProgressIndicator(progress: 0.8) - .storyProgressIndicatorColor(.purple) - } - .padding(20) - .background(.black) - .previewLayout(.sizeThatFits) +#Preview { + Group { + StoryProgressIndicator(progress: 0) + StoryProgressIndicator(progress: 1.0) + StoryProgressIndicator(progress: 0.8) + .storyProgressIndicatorColor(.purple) } + .padding(20) + .background(.black) + .previewLayout(.sizeThatFits) } diff --git a/Sources/Xcore/SwiftUI/Components/PageView/StoryView/StoryView.swift b/Sources/Xcore/SwiftUI/Components/PageView/StoryView/StoryView.swift index ecbbe1aec..178325886 100644 --- a/Sources/Xcore/SwiftUI/Components/PageView/StoryView/StoryView.swift +++ b/Sources/Xcore/SwiftUI/Components/PageView/StoryView/StoryView.swift @@ -169,36 +169,34 @@ extension StoryView { } } -// MARK: - Previews +// MARK: - Preview -struct StoryView_Previews: PreviewProvider { - static var previews: some View { - struct Colorful: Identifiable { - let id: Int - let color: Color - } +#Preview { + struct Colorful: Identifiable { + let id: Int + let color: Color + } - let pages = [ - Colorful(id: 1, color: .green), - Colorful(id: 2, color: .blue), - Colorful(id: 3, color: .purple) - ] - - return StoryView(cycle: .once, pages: pages) { page in - VStack { - Text("Page") - Text("#") - .baselineOffset(70) - .font(.system(size: 100)) + - Text("\(page.id)") - .font(.system(size: 200)) - } - .frame(maxWidth: .infinity, maxHeight: .infinity) - } background: { page in - page.color - } - .onCycleComplete { count in - print(count) + let pages = [ + Colorful(id: 1, color: .green), + Colorful(id: 2, color: .blue), + Colorful(id: 3, color: .purple) + ] + + return StoryView(cycle: .once, pages: pages) { page in + VStack { + Text("Page") + Text("#") + .baselineOffset(70) + .font(.system(size: 100)) + + Text("\(page.id)") + .font(.system(size: 200)) } + .frame(maxWidth: .infinity, maxHeight: .infinity) + } background: { page in + page.color + } + .onCycleComplete { count in + print(count) } } diff --git a/Sources/Xcore/SwiftUI/Components/Popup/Content/PopupAlert+Standard.swift b/Sources/Xcore/SwiftUI/Components/Popup/Content/PopupAlert+Standard.swift index 7ea563336..274c746c9 100644 --- a/Sources/Xcore/SwiftUI/Components/Popup/Content/PopupAlert+Standard.swift +++ b/Sources/Xcore/SwiftUI/Components/Popup/Content/PopupAlert+Standard.swift @@ -85,34 +85,32 @@ extension StandardPopupAlert where Header == Never { } } -// MARK: - Previews +// MARK: - Preview -struct StandardPopupAlert_Previews: PreviewProvider { - private static let L = Samples.Strings.deleteMessageAlert +#Preview { + Group { + let L = Samples.Strings.deleteMessageAlert - static var previews: some View { - Group { - StandardPopupAlert(L.title, message: L.message) { - HStack { - Button("Cancel") { - print("Cancel Tapped") - } - .buttonStyle(.outline) + StandardPopupAlert(L.title, message: L.message) { + HStack { + Button("Cancel") { + print("Cancel Tapped") + } + .buttonStyle(.outline) - Button("Delete") { - print("Delete Tapped") - } - .buttonStyle(.fill) + Button("Delete") { + print("Delete Tapped") } + .buttonStyle(.fill) } + } - StandardPopupAlert(L.title, message: L.message) { - EmptyView() - } + StandardPopupAlert(L.title, message: L.message) { + EmptyView() } - .padding(.defaultSpacing) - .frame(max: .infinity) - .background(.secondary.opacity(0.15)) - .previewLayout(.sizeThatFits) } + .padding(.defaultSpacing) + .frame(max: .infinity) + .background(.secondary.opacity(0.15)) + .previewLayout(.sizeThatFits) } diff --git a/Sources/Xcore/SwiftUI/Components/Popup/Content/PopupAlert.swift b/Sources/Xcore/SwiftUI/Components/Popup/Content/PopupAlert.swift index db2802708..d14949180 100644 --- a/Sources/Xcore/SwiftUI/Components/Popup/Content/PopupAlert.swift +++ b/Sources/Xcore/SwiftUI/Components/Popup/Content/PopupAlert.swift @@ -47,34 +47,32 @@ public struct PopupAlert: View where Content: View { } } -// MARK: - Previews +// MARK: - Preview -struct PopupAlert_Previews: PreviewProvider { - private static let L = Samples.Strings.deleteMessageAlert +#Preview { + Group { + let L = Samples.Strings.deleteMessageAlert - static var previews: some View { - Group { - PopupAlert { - HStack { - Button("Cancel") { - print("Cancel Tapped") - } - .buttonStyle(.outline) + PopupAlert { + HStack { + Button("Cancel") { + print("Cancel Tapped") + } + .buttonStyle(.outline) - Button("Delete") { - print("Delete Tapped") - } - .buttonStyle(.fill) + Button("Delete") { + print("Delete Tapped") } + .buttonStyle(.fill) } + } - PopupAlert { - Text(L.title) - Text(L.message) - } + PopupAlert { + Text(L.title) + Text(L.message) } - .padding(.defaultSpacing) - .background(.secondary.opacity(0.15)) - .previewLayout(.sizeThatFits) } + .padding(.defaultSpacing) + .background(.secondary.opacity(0.15)) + .previewLayout(.sizeThatFits) } diff --git a/Sources/Xcore/SwiftUI/Components/Popup/PopupPreviews.swift b/Sources/Xcore/SwiftUI/Components/Popup/PopupPreviews.swift index d5e35d5f5..db879c863 100644 --- a/Sources/Xcore/SwiftUI/Components/Popup/PopupPreviews.swift +++ b/Sources/Xcore/SwiftUI/Components/Popup/PopupPreviews.swift @@ -109,13 +109,11 @@ private struct PopupPreviews: View { } } -// MARK: - Preview Provider +// MARK: - Preview -struct Popup_Previews: PreviewProvider { - static var previews: some View { - PopupPreviews() - .embedInNavigation() - } +#Preview { + PopupPreviews() + .embedInNavigation() } extension Samples { diff --git a/Sources/Xcore/SwiftUI/Components/ProgressViewStyle/HorizontalBarProgressViewStyle.swift b/Sources/Xcore/SwiftUI/Components/ProgressViewStyle/HorizontalBarProgressViewStyle.swift index d0fd7c3b6..751b8e3ae 100644 --- a/Sources/Xcore/SwiftUI/Components/ProgressViewStyle/HorizontalBarProgressViewStyle.swift +++ b/Sources/Xcore/SwiftUI/Components/ProgressViewStyle/HorizontalBarProgressViewStyle.swift @@ -38,35 +38,33 @@ public struct HorizontalBarProgressViewStyle: ProgressViewStyle { } } -// MARK: - Previews +// MARK: - Preview -struct HorizontalBarProgressViewStyle_Previews: PreviewProvider { - static var previews: some View { - Group { - ProgressView() - .colorScheme(.dark) +#Preview { + Group { + ProgressView() + .colorScheme(.dark) - ProgressView(value: 0.5) - .tint(.green) + ProgressView(value: 0.5) + .tint(.green) - ProgressView(value: 0.8) - .progressViewStyle(.horizontalBar) + ProgressView(value: 0.8) + .progressViewStyle(.horizontalBar) - ProgressView(value: 0.0) - .progressViewStyle(.horizontalBar) + ProgressView(value: 0.0) + .progressViewStyle(.horizontalBar) - ProgressView(value: 1.0) - .progressViewStyle(.horizontalBar) - .tint(.yellow) + ProgressView(value: 1.0) + .progressViewStyle(.horizontalBar) + .tint(.yellow) - ProgressView(value: 0.8) - .progressViewStyle(.horizontalBar) - .tint(.green) - } - .padding(20) - .background(.black) - .previewLayout(.sizeThatFits) + ProgressView(value: 0.8) + .progressViewStyle(.horizontalBar) + .tint(.green) } + .padding(20) + .background(.black) + .previewLayout(.sizeThatFits) } // MARK: - Dot Syntax Support diff --git a/Sources/Xcore/SwiftUI/Components/Shapes/Arc.swift b/Sources/Xcore/SwiftUI/Components/Shapes/Arc.swift index 32a5639ff..de62f3016 100644 --- a/Sources/Xcore/SwiftUI/Components/Shapes/Arc.swift +++ b/Sources/Xcore/SwiftUI/Components/Shapes/Arc.swift @@ -59,20 +59,18 @@ public struct Arc: InsettableShape, Sendable { // MARK: - Preview -struct Arc_Previews: PreviewProvider { - static var previews: some View { - Arc(startAngle: .degrees(0), endAngle: .degrees(180), clockwise: true) - .strokeBorder( - AngularGradient( - gradient: Gradient(colors: [.white, .orange]), - center: .center, - startAngle: .degrees(180), - endAngle: .degrees(360) - ), - lineWidth: 50 - ) - .background(Color.black.opacity(0.5)) - .aspectRatio(CGSize(width: 1, height: 0.5), contentMode: .fit) - .previewLayout(.sizeThatFits) - } +#Preview { + Arc(startAngle: .degrees(0), endAngle: .degrees(180), clockwise: true) + .strokeBorder( + AngularGradient( + gradient: Gradient(colors: [.white, .orange]), + center: .center, + startAngle: .degrees(180), + endAngle: .degrees(360) + ), + lineWidth: 50 + ) + .background(Color.black.opacity(0.5)) + .aspectRatio(CGSize(width: 1, height: 0.5), contentMode: .fit) + .previewLayout(.sizeThatFits) } diff --git a/Sources/Xcore/SwiftUI/Components/Shapes/Parallelogram.swift b/Sources/Xcore/SwiftUI/Components/Shapes/Parallelogram.swift index e6326b2a2..6580c527b 100644 --- a/Sources/Xcore/SwiftUI/Components/Shapes/Parallelogram.swift +++ b/Sources/Xcore/SwiftUI/Components/Shapes/Parallelogram.swift @@ -40,18 +40,14 @@ public struct Parallelogram: Shape, Sendable { } } -// MARK: - Preview +#Preview { + ZStack { + Parallelogram(depth: 150) + .stroke(Color.black, lineWidth: 13) -struct Parallelogram_Previews: PreviewProvider { - static var previews: some View { - ZStack { - Parallelogram(depth: 150) - .stroke(Color.black, lineWidth: 13) - - Parallelogram(depth: 150, isFlipped: true) - .stroke(Color.red, lineWidth: 13) - } - .frame(300) - .padding() + Parallelogram(depth: 150, isFlipped: true) + .stroke(Color.red, lineWidth: 13) } + .frame(300) + .padding() } diff --git a/Sources/Xcore/SwiftUI/Components/Shapes/RoundedRectangleCorner.swift b/Sources/Xcore/SwiftUI/Components/Shapes/RoundedRectangleCorner.swift index 421eca706..3f4bc163a 100644 --- a/Sources/Xcore/SwiftUI/Components/Shapes/RoundedRectangleCorner.swift +++ b/Sources/Xcore/SwiftUI/Components/Shapes/RoundedRectangleCorner.swift @@ -33,16 +33,14 @@ public struct RoundedRectangleCorner: Shape, Sendable { // MARK: - Preview -struct RoundedRectangleCorner_Previews: PreviewProvider { - static var previews: some View { - VStack { - RoundedRectangleCorner(radius: 75, corners: [.topLeft, .bottomRight]) - .fill(.blue) - RoundedRectangleCorner(radius: 75, corners: .top) - .fill(.orange) - RoundedRectangleCorner(radius: 75, corners: .bottom) - .fill(.green) - } - .frame(150) +#Preview { + VStack { + RoundedRectangleCorner(radius: 75, corners: [.topLeft, .bottomRight]) + .fill(.blue) + RoundedRectangleCorner(radius: 75, corners: .top) + .fill(.orange) + RoundedRectangleCorner(radius: 75, corners: .bottom) + .fill(.green) } + .frame(150) } diff --git a/Sources/Xcore/SwiftUI/Components/Shapes/Triangle.swift b/Sources/Xcore/SwiftUI/Components/Shapes/Triangle.swift index 6852a8b98..526521d7d 100644 --- a/Sources/Xcore/SwiftUI/Components/Shapes/Triangle.swift +++ b/Sources/Xcore/SwiftUI/Components/Shapes/Triangle.swift @@ -26,11 +26,9 @@ public struct Triangle: Shape, Sendable { // MARK: - Preview -struct Triangle_Previews: PreviewProvider { - static var previews: some View { - Triangle() - .stroke(lineWidth: 13) - .frame(300) - .padding() - } +#Preview { + Triangle() + .stroke(lineWidth: 13) + .frame(300) + .padding() } diff --git a/Sources/Xcore/SwiftUI/Components/Sheets/CustomBottomSheet.swift b/Sources/Xcore/SwiftUI/Components/Sheets/CustomBottomSheet.swift index 2d5615153..12998edc6 100644 --- a/Sources/Xcore/SwiftUI/Components/Sheets/CustomBottomSheet.swift +++ b/Sources/Xcore/SwiftUI/Components/Sheets/CustomBottomSheet.swift @@ -84,7 +84,7 @@ private struct CustomBottomSheetButtonStyle: ButtonStyle { } } -// MARK: - Previews +// MARK: - Preview #Preview { CustomBottomSheet {