Skip to content

Bring an Android bottom sheet back up when it's shown again mid-hide - #219

Merged
simonhamp merged 1 commit into
mainfrom
fix/android-sheet-reshow
Nov 19, 2026
Merged

simonhamp merged 1 commit into
mainfrom
fix/android-sheet-reshow

Conversation

@simonhamp

Copy link
Copy Markdown
Member

On Android, a bottom sheet that PHP shows again while it's still sliding away doesn't come back. It stays off screen, but its dialog window stays on top of the app: the keyboard stays up for the field inside it, and the next tap anywhere lands on the invisible scrim and does nothing. PHP thinks the sheet is open.

We hit it in the devnull app while working on NativePHP/dev-null-app#183. Its composer sheet closes when you post, and if the post fails straight away (no connection), it opens the sheet again with your draft. If the failure comes back inside the hide animation, about one try in three, the composer was gone and the screen stopped responding to the next tap.

Cause

BottomSheetRenderer runs sheetState.hide() in LaunchedEffect(visible). When visible turns true again before the hide is done, Compose cancels that effect, and the hide stops wherever it got to. The new effect only sets shown = true. The sheet stays composed, so ModalBottomSheet never runs its first-composition show() again, and nothing else moves it back up.

#205 doesn't cover this. Its finally { shown = false } does run on the cancel, but the new effect sets shown = true in the same frame, so the sheet never leaves composition.

Fix

  • A hiding flag is set while the hide runs.
  • When the effect for visible = true finds a hide was cut short, it calls sheetState.show().
  • The hide's finally only lets the sheet go when its own effect is still active (isActive). A drag or M3's own show() interrupting hide() doesn't cancel the effect, so in those cases the sheet still leaves, as fix(android): keep a closing sheet from reopening #205 intended. Being shown again does cancel the effect, and then the sheet stays for the new effect to bring back up.

Testing

  • New Robolectric test BottomSheetCloseTest.aSheetShownAgainWhileSlidingAwayComesBackUp: hides an open sheet, steps the clock 150 ms into the slide, shows it again, and checks it ends where it opened. On main it fails with the sheet's top at 514 instead of 48. With this change the whole tests/android module passes (67 tests), run against mobile-air main with JDK 23.
  • Pest: 503 passed. BottomSheetRendererTest gains a source check for the reshow, and the existing fix(android): keep a closing sheet from reopening #205 check now allows for the isActive guard.
  • Device: an earlier session ran the same change in the devnull app on an Android 35 emulator, with the local API cut off so the post failed at once. Before, the composer vanished with the error toast up. After, a reopen that landed mid-hide slid the sheet back up with the draft.

What to watch for

  • The reshow only happens when the hide was cancelled by a new visible. If a sheet's visible flips false and true several times quickly, each new effect either shows it or hides it from wherever it is, so it should settle on the last value. The test covers one flip.
  • iOS isn't touched.

🤖 Generated with Claude Code

If PHP shows a sheet again before its hide animation has finished, the
LaunchedEffect(visible) running hide() is cancelled and the new one only
sets `shown = true`. The sheet stays composed at whatever offset the hide
reached, and ModalBottomSheet only plays show() when it first composes,
so nothing brings it back. It stays off screen with its dialog window
still on top: the keyboard stays up for the hidden field and the next
tap anywhere is swallowed by the invisible scrim.

The hide now marks itself as in progress. An effect that cancels it
calls sheetState.show(), and the hide's finally only lets the sheet go
when its own effect is still active, so a drag or M3's show()
interrupting hide() still takes the sheet away as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonhamp
simonhamp marked this pull request as ready for review November 19, 2026 21:42
@simonhamp
simonhamp merged commit aece191 into main Nov 19, 2026
4 checks passed
@simonhamp
simonhamp deleted the fix/android-sheet-reshow branch November 19, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant