Skip to content

Commit 33a996d

Browse files
committed
fix previews
Seems to crash the previews macro if we do not provide a rootViewController, despite being optional
1 parent 379d7c2 commit 33a996d

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-20
lines changed

WooCommerce/Classes/ViewRelated/Orders/Payment Methods/PaymentMethodsView.swift

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -251,27 +251,47 @@ extension PaymentMethodsView {
251251
}
252252

253253
// MARK: Previews
254-
struct PaymentMethodsView_Preview: PreviewProvider {
255-
static var previews: some View {
256-
NavigationView {
257-
PaymentMethodsView(viewModel: .init(total: "15.99", formattedTotal: "$15.99", flow: .orderPayment, channel: .storeManagement))
258-
.navigationBarTitleDisplayMode(.inline)
259-
}
260-
.environment(\.colorScheme, .light)
261-
.previewDisplayName("Light")
254+
#Preview("Light") {
255+
@Previewable @State var rootViewController = UIViewController()
256+
NavigationView {
257+
PaymentMethodsView(
258+
rootViewController: rootViewController,
259+
viewModel: PaymentMethodsViewModel(total: "15.99",
260+
formattedTotal: "$15.99",
261+
flow: .orderPayment,
262+
channel: .storeManagement)
263+
)
264+
.navigationBarTitleDisplayMode(.inline)
265+
}
266+
.environment(\.colorScheme, .light)
267+
}
262268

263-
NavigationView {
264-
PaymentMethodsView(viewModel: .init(total: "15.99", formattedTotal: "$15.99", flow: .orderPayment, channel: .storeManagement))
265-
.navigationBarTitleDisplayMode(.inline)
266-
}
267-
.environment(\.colorScheme, .dark)
268-
.previewDisplayName("Dark")
269+
#Preview("Dark") {
270+
@Previewable @State var rootViewController = UIViewController()
271+
NavigationView {
272+
PaymentMethodsView(
273+
rootViewController: rootViewController,
274+
viewModel: PaymentMethodsViewModel(total: "15.99",
275+
formattedTotal: "$15.99",
276+
flow: .orderPayment,
277+
channel: .storeManagement)
278+
)
279+
.navigationBarTitleDisplayMode(.inline)
280+
}
281+
.environment(\.colorScheme, .dark)
282+
}
269283

270-
NavigationView {
271-
PaymentMethodsView(viewModel: .init(total: "15.99", formattedTotal: "$15.99", flow: .orderPayment, channel: .storeManagement))
272-
.navigationBarTitleDisplayMode(.inline)
273-
}
274-
.environment(\.sizeCategory, .accessibilityExtraExtraLarge)
275-
.previewDisplayName("Accessibility")
284+
#Preview("Accessibility") {
285+
@Previewable @State var rootViewController = UIViewController()
286+
NavigationView {
287+
PaymentMethodsView(
288+
rootViewController: rootViewController,
289+
viewModel: PaymentMethodsViewModel(total: "15.99",
290+
formattedTotal: "$15.99",
291+
flow: .orderPayment,
292+
channel: .storeManagement)
293+
)
294+
.navigationBarTitleDisplayMode(.inline)
276295
}
296+
.environment(\.sizeCategory, .accessibilityExtraExtraLarge)
277297
}

0 commit comments

Comments
 (0)