I have following code for making a basic swipe Action.
import SwiftUI
struct Drag: ViewModifier{
@State var offset: CGFloat = 0
func body(content: Content) -> some View {
content
.offset(x: offset)
.gesture(DragGesture().onChanged({val in
offset = val.translation.width
})
.onEnded({val in
if offset < -160 || offset > -100{
withAnimation{
offset = 0
}
}else{
withAnimation{
offset = -100
}
}
}))
.background(
ZStack{
HStack(spacing: 0){
Spacer()
Color.red.frame(width: offset.magnitude)
.overlay(
HStack{
Image(systemName: "house")
.foregroundColor(.white)
.offset(x: 40)
Spacer()
}
)
}
}
)
.clipShape(Rectangle()) // <---- problem here
}
}
struct ContentView: View {
var body: some View {
VStack{
ForEach(0..<5){i in
Text("test")
.padding()
.frame(width: UIScreen.main.bounds.width * 0.9)
.background(Color.gray)
.modifier(Drag())
}
}
.cornerRadius(10) // <---- problem here
}
}
I found a weird crash when testing on real Device (iPhone XS, iOS 16).
Video: https://imgur.com/a/n308FA1
crash: https://imgur.com/a/GANg0HN
Following does help: When commenting the .clipShape() or .cornerRadius() modifier out, then the crash didn't occur. Why does this combination of these two modifiers make this crash?