SwiftUI tvOS Buttons wrapped inside focusable HStack do not respond action

943 Views Asked by At

I found similar problems on SO about the focus engine with SwiftUI on tvOS. I think I managed to solve the focusable issue by wrapping the two Buttons here inside HStack with focusable.

                        HStack(spacing: 40) {
                            Spacer()

                            CustomButton(
                                title: Strings.Onboarding.Continue.title,
                                action: {
                                    handler(selectedProducts.map(\.id))
                                },
                                fixedWidth: ProductView.defaultItemSize.width
                            )
                            .disabled(selectedProducts.count < 3)

                            if selectedProducts.count < 3 {
                                CustomButton(
                                    title: Strings.Onboarding.Skip.title,
                                    action: {
                                        handler([])
                                    },
                                    fixedWidth: ProductView.defaultItemSize.width
                                )
                            }

                            Spacer()
                        }
                        .focusable()

enter image description here

But now the Buttons do not respond to the actions. This is so confusing. Has anyone solved a similar problem before?

0

There are 0 best solutions below