Conversation
A host with no browser between the remote and the app decides for itself what an unhandled press does: on tvOS a Menu press nothing handled returns to the Home screen. It needs to know which presses the app consumed, and until now only a handler calling `preventDefault()` itself could say so. `Config.preventDefaultOnHandledKeys`, off by default, makes the focus manager call it on every key event the app consumed: a handler returned true, or the focus manager dropped the press itself, a throttled press or a suppressed repeat. `KeyEventLike` gains an optional `preventDefault`. Also a compatibility fix: 1.6.3 reads the second `useFocusManager` argument as the event target, where earlier releases ignored it. An app still passing the removed hold options there threw on `target.addEventListener`. An argument that cannot listen is ignored again, in favour of `document`. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
On a host with no browser between the remote and the app, the host decides what an unhandled press does: on Apple TV a Menu press nothing handled returns to the Home screen, which review expects at the root screen and nowhere else. The host learns which presses the app consumed from
preventDefault(), and until now only a handler calling it itself could say so, in every Back handler of every app. Phase 4 of the NativeScript integration runs the public demo app unchanged on the Apple TV, so the answer had to come from the framework.What changed
Config.preventDefaultOnHandledKeys, off by default. With it on, the focus manager callspreventDefault()on every key event the app consumed: a handler returnedtrue, or the focus manager dropped the press itself, a press the global throttle dropped or a repeatuseHoldsuppressed. Key-ups too. An event without apreventDefaultmethod is left alone;KeyEventLikedeclares it optional.useFocusManagerargument that cannot listen is ignored. 1.6.3 reads that argument as the event target (feat(focus): let useFocusManager listen on a given event target #63); before it, the argument was ignored. The demo app still passes the removed hold options there and threw ontarget.addEventListeneragainst 1.6.3. It falls back todocumentagain.handleKeyEventsreturns whether the event was consumed, and a press the global throttle drops counts as consumed, as one an element'sthrottleInputdrops already did.useFocusManager.md; the flag in the config list ofrender.md.Off by default because in a browser it changes what a handled key does: a handled arrow no longer scrolls the page, say.
Tests
tests/focusManagerPreventDefault.test.tsx: called for a consumed press, not for an unhandled one, not with the flag off, for a consumed release, and for a press the global throttle dropped.tests/focusManagerTarget.test.tsx: listens ondocumentwhen the second argument cannot listen.pnpm test: 332 passing.pnpm lint: no errors.pnpm buildclean.The flag is what the NativeScript host sets in its boot file; the demo app on the Apple TV leaves to the Home screen from its start page and nowhere else through it.
🤖 Generated with Claude Code