Repository navigation
Fix mobile controls hiding immediately when tapped after first play - #139
Merged
Merged
Conversation
rememberControlsVisibility recreated its visible State whenever firstPlay, paused or forceVisible changed, but the mobile tap handler keeps the State it saw on the first pointer event. After first play, that stale state always reported the controls as visible, so tapping hidden controls showed them on press and immediately hid them again on release. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
pointerInput(Unit) keeps the State and callbacks it captured when the gesture handler first launched. Wrap them in rememberUpdatedState so the handler always uses the latest values, even if callers pass a new State. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.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.
Summary
rememberControlsVisibilityusedremember(firstPlay, paused, forceVisible) { derivedStateOf { ... } }, so it built a newvisibleStateevery time one of those inputs changed.toggleControlsOnTapusespointerInput(Unit), so it keeps whicheverStateexisted at the first pointer event, typically the tap on play, beforefirstPlayflips. In that stale state "not played yet" means "visible", so it reportstrueforever, and every tap ends inhideControls().rememberUpdatedStateand keep a singlederivedStateOfin a plainremember { }, sovisibleis oneStatefor the life of the composable.toggleControlsOnTapnow wraps itsStateand callbacks inrememberUpdatedState, so itspointerInput(Unit)handler always uses the latest values even if a caller passes a newState. It's now a@Composablemodifier factory, which is fine because it's internal and has one call site.mainor in any release, so no changelog entry.Test plan
ControlsVisibilityTest(6 tests):Statestays the same across input changes, plus the ready delay, show/hide-delay,hide(), paused andforceVisiblebehaviourUIControllerTapTest: tap, play, auto-hide, tap shows the controls and they stay, tap again hides themToggleControlsOnTapTest(3 tests): the handler uses a swapped-inStateand swapped-in callbacks, plus the existing tap-to-show/tap-to-hide behaviour./gradlew :ui:testDebugUnitTest :ui-common:testDebugUnitTest :ui-tv:testDebugUnitTest./gradlew :ui:lintDebug: no new warningsGenerated with Devin