Skip to content

Commit 71182ec

Browse files
committed
Add list preview to flip view to illustrate bug
1 parent a61fdf6 commit 71182ec

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

Sources/SwiftUIKit/Flip/FlipView.swift

+43-19
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,48 @@ private extension View {
162162
}
163163
}
164164

165-
#Preview {
165+
@MainActor
166+
@ViewBuilder
167+
func previewContent(isFlipped: Binding<Bool>) -> some View {
168+
Text("Is Flipped: \(isFlipped.wrappedValue)")
169+
170+
FlipView(
171+
front: Color.green.overlay(Text("Front")),
172+
back: Color.red.overlay(Text("Back")),
173+
isFlipped: isFlipped,
174+
flipDuration: 0.5,
175+
tapDirection: .right,
176+
swipeDirections: [.left, .right, .up, .down]
177+
)
178+
.cornerRadius(10)
179+
.shadow(radius: 0, x: 0, y: 2)
180+
181+
Button("Flip") {
182+
withAnimation {
183+
isFlipped.wrappedValue.toggle()
184+
}
185+
}
186+
}
187+
188+
#Preview("Stack") {
189+
190+
struct Preview: View {
191+
192+
@State
193+
private var isFlipped = false
194+
195+
var body: some View {
196+
VStack {
197+
previewContent(isFlipped: $isFlipped)
198+
}
199+
.padding()
200+
}
201+
}
202+
203+
return Preview()
204+
}
205+
206+
#Preview("List (BUG)") {
166207

167208
struct Preview: View {
168209

@@ -171,24 +212,7 @@ private extension View {
171212

172213
var body: some View {
173214
List {
174-
Text("Is Flipped: \(isFlipped)")
175-
176-
FlipView(
177-
front: Color.green.overlay(Text("Front")),
178-
back: Color.red.overlay(Text("Back")),
179-
isFlipped: $isFlipped,
180-
flipDuration: 0.5,
181-
tapDirection: .right,
182-
swipeDirections: [.left, .right, .up, .down]
183-
)
184-
.cornerRadius(10)
185-
.shadow(radius: 0, x: 0, y: 2)
186-
187-
Button("Flip") {
188-
withAnimation {
189-
isFlipped.toggle()
190-
}
191-
}
215+
previewContent(isFlipped: $isFlipped)
192216
}
193217
.padding()
194218
}

0 commit comments

Comments
 (0)