8

I just updated to Big Sur and now I'm experiencing serious troubles in my Catalyst app. I created a new project with similiar code to test it. The behaviour is a little bit different, but in both cases there is one point, where clicking stops working or at least it's not reliable anymore.

Take this example code:

struct ContentView: View {
        
    private var tabs = ["tab1", "tab2", "tab3"]
    @State private var selectedTab = 0
    
    var body: some View {
        VStack {
            
            self.fakeTabs()
            
            self.tabView()
            
        }
    }
    
    private func fakeTabs() -> some View {
        HStack(spacing: 0) {
            
            // ========================================================
            // Tabs
            // ========================================================
            ForEach(self.tabs, id: \.self) { tab in
                ZStack {
                    // background
                    Rectangle()
                        .fill(self.isSelected(tab: tab) ? Color.blue : Color.green)
                        .border(Color.black, width: 1)
                        .contentShape(Rectangle())
                    // icon
                    HStack(spacing: 15.0) {
                        Image(systemName: "folder")
                            .foregroundColor(.white)
                            .frame(width: 20, height: 20)
                        Text(tab)
                            .font(.caption)
                    }
                }
                .onTapGesture {
                    self.selectedTab = self.tabs.firstIndex(where: { $0 == tab }) ?? 0
                }
            }
        }
        .frame(height: 30)
    }
    
    private func tabView() -> some View {
        TabView(selection: self.$selectedTab) {
            
            ForEach(self.tabs.indices) { index in
                
                let tab = self.tabs[index]
                
                Text("Tab selected: \(tab)")
                    .tabItem { Text(tab) }
                    .tag(index)
                
            }
        }
    }
    
    private func isSelected(tab: String) -> Bool {
        if let index = self.tabs.firstIndex(where: { $0 == tab }) {
            if index == self.selectedTab {
                return true
            }
        }
        return false
    }
}

If you start clicking at the tab bar in the bottom, it works. If you then continue clicking on the tabs at the top, it works too. But after clicking on the fake tabs at the top, you cannot click on the TabBar at the bottom anymore.

Does somone else experience this problem? Is it a Big Sur bug?

EDIT

It works perfect in the Simulator on iPadOS.

Lupurus
  • 2,819
  • 2
  • 24
  • 48
  • 1
    I'm experiencing exactly the same thing. FWIW, it seems like it works with `Button`s, but not `onTapGesture`. Have you found any solutions? – jnpdx Nov 20 '20 at 00:21

2 Answers2

4

This is definitely a major issue. Also reported here https://developer.apple.com/forums/thread/667004

I wish Apple would acknowledge it.

Bret
  • 774
  • 1
  • 8
  • 16
3

I am facing quite similar problems. I also have a HStack as a main view. In each row there are buttons and textfields. When adding / removing columns buttons stop working and focused textfields can't be changed with clicks anymore (right-clicks still working). Also observed non-working buttons in ZStacks. Still figuring out the problem-scenario to reproduce it reliably. Could be something with the HStack, as we both use them.

  • 1
    I'm honest, I stopped investigating and wasting time for that. Catalyst and SwiftUI is horrible and buggy. I copied my code and made a native Mac app with AppKit. So much better and took me only one day thanks to SwiftUI. – Lupurus Nov 17 '20 at 16:09
  • I'm like you guys. Catalyst SwiftUI on Big Surf is garbage, if you put "Optimize interface on Mac" works a little bit better put still quite buggy. I do agree with lupurus, go back to Catalina or make it native to Mac. – Ernesto Perez Nov 19 '20 at 20:18