From 827d10eda721475eb340e946194d45f324c9988a Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 18 Oct 2026 23:30:22 +0200 Subject: [PATCH] Focus the delayed tvOS Cancel when it appears By the time the button shows, focus has already been lost, and the focus engine is not guaranteed to pick up an element inserted later. --- Yattee/Views/Components/LoadStateView.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Yattee/Views/Components/LoadStateView.swift b/Yattee/Views/Components/LoadStateView.swift index a7723ee9..834f71fb 100644 --- a/Yattee/Views/Components/LoadStateView.swift +++ b/Yattee/Views/Components/LoadStateView.swift @@ -61,16 +61,22 @@ struct TVStalledLoadCancelButton: View { let action: () -> Void @State private var isShown = false + @FocusState private var isFocused: Bool var body: some View { Group { if isShown { Button(String(localized: "common.cancel"), action: action) + .focused($isFocused) } } .task { guard (try? await Task.sleep(for: delay)) != nil else { return } isShown = true + // Focus was already lost by the time the button appears, and the + // focus engine is not guaranteed to pick up a late arrival. + guard (try? await Task.sleep(for: .milliseconds(100))) != nil else { return } + isFocused = true } } }