I’m implementing a custom bottom sheet using SwiftUI (iOS 15). I’m having an issue where the list stops responding to gestures if I hide and reopen the list with the swipe button visible.
struct ListView: View {
var body: some View {
List {
Section {
Text("1").swipeActions { Button(action: {}) { Text("Do!") } }
}
}
}
}
struct ContentView: View {
@State var showList: Bool = false
var body: some View {
VStack {
Toggle("Show", isOn: $showList).toggleStyle(.button)
if self.showList {
ListView()
}
}
}
}
Couple things I tried:
option 1: The standard SwiftUI sheet works fine but I can’t use that because I need to control the height of the sheet.
var body: some View {
VStack {
Toggle("Show", isOn: $showList).toggleStyle(.button)
.sheet(isPresented: $showList, content: {
Toggle("Close", isOn: $showList).toggleStyle(.button)
ListView()
})
}
}
option 2: I can hack around the issue by placing a blank view on top but when I show the list again the swipe action is still engaged so that’s not ideal.
var body: some View {
VStack {
Toggle("Show", isOn: $showList).toggleStyle(.button)
ZStack {
ListView()
if !self.showList {
Text("")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(UIColor.systemBackground))
}
}
}
}
Any ideas what to do here?
Khris Rino is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.