Created
January 11, 2022 00:29
-
-
Save nickmain/5e2c6371dc2e2f7de525568a143776bc to your computer and use it in GitHub Desktop.
Forced focus targetting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Focus management | |
private var targetFocusEnv: UIFocusEnvironment? | |
override var preferredFocusEnvironments: [UIFocusEnvironment] { | |
if let target = targetFocusEnv { | |
return [target] | |
} else { | |
return [] | |
} | |
} | |
override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) { | |
// clear focus target | |
targetFocusEnv = nil | |
} | |
func tryToSendFocus(to environment: UIFocusEnvironment) { | |
runOnMain { | |
self.targetFocusEnv = environment | |
self.setNeedsFocusUpdate() | |
self.updateFocusIfNeeded() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment