BarredEwe / Prefire

🔥 A library based on SwiftUI Preview, for easy generation: Playbook view, Snapshot and Accessibility tests
Apache License 2.0
290 stars 18 forks source link

Globally define preview appearance #71

Open markst opened 2 months ago

markst commented 2 months ago

Context 🕵️‍♀️

Most of our previews look fine in preview without any additional attributes:

#Preview {
  ShowMetaStack(
    showModel: ShowModel.featureMockData,
    nowNextModel: .success(.init()),
    actionsRowModel: .withReminderMockData,
    playButtonAction: {
    },
    actions: .init(
      shareAction: nil,
      watchlistAction: nil,
      reminderAction: nil
    )
  )
  .preferredColorScheme(.dark)
}

What 🌱

Our generated snapshots appear with white background and default device resolution:

test_ShowMetaStack_0_Preview ShowMetaStack_0

Proposal 🎉

Without needing to apply preview layout and background colours too all our previews:

  .previewLayout(.sizeThatFits)
  .background(.red)

I wonder if can add to the config in order to apply global attributes to all our previews which generate snapshots

markst commented 2 months ago

Ah actually might add that the new syntax is:

#Preview(traits: .sizeThatFitsLayout) {
  VStack {
    ActionButtonsRow(

Does actually pump out assets right size: