Skip to content

Instantly share code, notes, and snippets.

@bannzai
Created October 24, 2025 00:35
Show Gist options
  • Select an option

  • Save bannzai/74a93c291d53bbd67c02cd5da3310572 to your computer and use it in GitHub Desktop.

Select an option

Save bannzai/74a93c291d53bbd67c02cd5da3310572 to your computer and use it in GitHub Desktop.
struct SnapshotUITest<T: PreviewProvider>: View {
var navigationBarIsHidden = false
var body: some View {
VStack(alignment: .leading, spacing: 16) {
Text(verbatim: "\(T.self)")
.font(.title3)
VStack(alignment: .leading) {
ForEach(T._allPreviews.indices, id: \.self) { index in
let preview = T._allPreviews[index]
NavigationLink {
if navigationBarIsHidden {
preview.content
.navigationBarBackButtonHidden()
} else {
preview.content
}
} label: {
Text(verbatim: "\(T.self)_\(index)")
.accessibilityLabel(Text(verbatim: "\(T.self)_\(index)"))
.font(.body)
.foregroundStyle(Color.accentColor)
}
.buttonStyle(.plain)
}
Divider()
}
.frame(maxWidth: .infinity)
}
.padding()
}
}
@bannzai
Copy link
Author

bannzai commented Oct 24, 2025

使用例

struct SnapshotUITestPage: View {
  var body: some View {
    NavigationView {
      ScrollView {
        VStack(alignment: .leading) {
          SnapshotUITest<RetryPage_Previews>(navigationBarIsHidden: true)
          SnapshotUITest<PromotionStartPage_Previews>()
        }
        .navigationLinkIndicatorVisibility(.visible)
      }
      .listStyle(.plain)
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment