mirror of
https://github.com/yattee/yattee.git
synced 2026-10-23 05:02:53 +00:00
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.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user