I have a view, that covers the entire screen except safe areas and handles DragGesture to perform navigation/scrolling. I find that when I do a rapid swipe up from the bottom edge to do a task switch on an iPhone 11 Pro, this is detected as a DragGesture on my view. This is as such not a problem, but I never get the onEnded method called and is left in an undefined state when my app reenters later on.
I've put togther a very simple example that illustrates the problem:
struct ContentView: View
{
@State var pos : CGFloat = 0
var body: some View
{
VStack
{
Color.clear.frame(height:0)
Spacer()
Text("\(pos)")
Spacer()
}
.background(Color.gray)
.contentShape(Rectangle())
.gesture(DragGesture()
.onChanged { g in self.pos = g.translation.height }
.onEnded { g in self.pos = 0 }
)
}
}
Though the problem can orrur swiping up from any part of the bottom edge, it always triggers the problem if started at either the left of right corner of the screen.
Please note that the setting and clearing the pos value is a simple way of illustrating the problem. The real app code for onEnded is not that simple.
Is there any way to detect that the swipe has initiated a task switch so I can set my state accordingly (i.e. simulate a onEnded)? I there a way to avoid having the DragGesture triggering when the gesture realy is a system task switch?