0

I'm dealing with what I am nearly certain to be a SwiftUI/Catalyst bug and am looking for a solution to get around it.

In the following code, about 30% of the time (5/15 in my tests), once the controls are revealed, the Toggle elements do not respond to clicks (and thus do not turn on/off).

I'm testing on Xcode 12.3 on Big Sur 11.1, running this code in Catalyst. It does work as expected 100% of the time as far as I can tell on iOS 14.3.

struct ContentView: View {
    
    var body: some View {
        ScrollView {
            Row()
            Row()
        }
        .padding()
    }
}

struct Row : View {
    @State private var showControls = false
    @State private var toggleOn = false
    
    var body: some View {
        VStack {
            HStack {
                Text("Top section")
                Button("\(showControls ? "Hide" : "Show") controls") {
                    showControls.toggle()
                }
            }
            .frame(height: 100)
            if showControls {
                HStack {
                    Toggle("Toggle", isOn: $toggleOn)
                    Toggle("Toggle", isOn: $toggleOn)
                }
            }
        }
    }
}

The problem seems to come from having the Rows embedded in the ScrollView. The problem disappears completely if the controls start in their visible state (ie showControls = true), and only happens when they get revealed (ie showControls.toggle()) after the app starts.

I've also noticed that while Toggle and Slider fail about 30% of the time, a plain Button seems to be responsive 100% of the time.

The view debugger doesn't show anything 'in front' of the views that would be intercepting clicks.

I've tried changing to a List, which solves the problem, but yields other unfortunate side effects in behavior that I'd like to avoid in my real non-trivial app.

Can anyone else think of a reliable solution to avoiding this?

jnpdx
  • 45,847
  • 6
  • 64
  • 94
  • Having your same issue. Just have to wrap all clickable views inside of a button. Also have issues with scrolling. These only occur on MacOS when running BigSur (Doesn't happen on Catalina). https://stackoverflow.com/questions/65768659/list-freezes-after-pushing-from-a-navigation-link-nested-in-a-parent-list-macca – KissTheCoder Feb 23 '21 at 19:52
  • What do you mean wrap clickable views inside a button? Like wrapping `Toggle`s inside `Button`s? – jnpdx Feb 23 '21 at 20:23
  • Yes, instead of using OnTapGesure{} I just wrap the view in a button. I don't do it with toggle, since I don't have issues with clicking those. – KissTheCoder Mar 03 '21 at 02:09

0 Answers0