[tvOS] Detect Siri Remote swipes from absolute pad position - #21
Merged
Merged
Conversation
The fork's relative-space detection (UIKit indirect touches over 40 points) has several issues: it fires on drags across the ring buttons, generates phantom swipes from clicks, and counts slow drifts as swipes. Native tvOS only treats pad centre movement as a swipe, and never treats clicks as swipes. Switch to a per-container SiriRemoteTouchOracle that polls the GameController micro gamepad for absolute pad position (-1..1) while an indirect contact is active. A per-contact state machine fires a swipe once per contact when the dominant axis displacement reaches 0.30 within 250 ms, with the dominant axis at least twice the other. Contacts starting at radius 0.75 or more (ring zone) are ignored. Resting fingers (under 0.02 movement for 150 ms) reset the origin. A click or button press within 150 ms before or during the contact cancels the swipe. The dispatch holds for 80 ms to allow a late click to suppress it. Without a controller (simulator, first frames), fallback to the previous relative-space detection with the new duration, dead-zone and press gates. The COMPOSE_TVOS_SWIPE_DEBUG=1 environment variable prints all decisions.
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.
Problem
The current implementation converts UIKit indirect touches spanning more than 40 points (measured in centre-anchored relative space) into synthetic directional key events. This approach has multiple failure modes:
Native tvOS has different semantics: only movement originating on the centre pad counts as a swipe, and button clicks are never also swipes.
Change
A new per-container
SiriRemoteTouchOraclepolls the GameController micro gamepad for absolute pad position (ranging -1 to 1, with y positive toward the top) while an indirect contact is active. UIKit reports touch position sparsely, so polling at display rate captures finger movement that would otherwise be missed.Per-contact state machine in
ComposeSceneMediator:The
COMPOSE_TVOS_SWIPE_DEBUG=1environment variable enables detailed decision logging for troubleshooting.Calibration
Measured on an Apple TV 4K with second-generation Siri Remote:
Key constants: CENTER_PAD_RADIUS 0.75, SWIPE_DISTANCE 0.30, SWIPE_MAX_DURATION 250 ms, axis dominance 2x, dispatch hold 80 ms, press window 150 ms, rest reset threshold 0.02 over 150 ms.
Verification
Compiled for
tvosArm64andtvosSimulatorArm64. Tested on device across multiple runs with debug logging:The final build with the 80 ms dispatch hold is pending a confirmatory device pass. This PR is written assuming that pass succeeds.
Notes