Skip to content

Commit

Permalink
Switch to #Preview macro
Browse files Browse the repository at this point in the history
  • Loading branch information
zmian committed Feb 1, 2024
1 parent 1dcc8ed commit ebeb97a
Show file tree
Hide file tree
Showing 17 changed files with 159 additions and 193 deletions.
10 changes: 4 additions & 6 deletions Example/Views/ActivitySheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
10 changes: 4 additions & 6 deletions Example/Views/ButtonsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,9 @@ extension ButtonsView {
}
}

// MARK: - Previews
// MARK: - Preview

struct ButtonsView_Previews: PreviewProvider {
static var previews: some View {
ButtonsView()
.embedInNavigation()
}
#Preview {
ButtonsView()
.embedInNavigation()
}
8 changes: 3 additions & 5 deletions Example/Views/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ struct RootView: View {
}
}

// MARK: - Previews
// MARK: - Preview

struct RootView_Previews: PreviewProvider {
static var previews: some View {
RootView()
}
#Preview {
RootView()
}
10 changes: 4 additions & 6 deletions Example/Views/XLabeledContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
10 changes: 4 additions & 6 deletions Sources/Xcore/SwiftUI/Components/CapsuleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,11 @@ extension CapsuleView<Never> {

#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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
54 changes: 26 additions & 28 deletions Sources/Xcore/SwiftUI/Components/PageView/StoryView/StoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
42 changes: 20 additions & 22 deletions Sources/Xcore/SwiftUI/Components/Popup/Content/PopupAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,32 @@ public struct PopupAlert<Content>: 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)
}
10 changes: 4 additions & 6 deletions Sources/Xcore/SwiftUI/Components/Popup/PopupPreviews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit ebeb97a

Please sign in to comment.