Skip to content

Fix Android toast ordering above overlays - #9

Merged
victorycodedev merged 3 commits into
mainfrom
fix/android-toasts-above-overlays
Nov 20, 2026
Merged

victorycodedev merged 3 commits into
mainfrom
fix/android-toasts-above-overlays

Conversation

@victorycodedev

Copy link
Copy Markdown
Owner

What changed?

  • Hosts Android toast positions in activity-scoped, non-focusable windows so toasts render above NativePHP modals, Material bottom sheets, alert dialogs, Compose popups, and detached LayoutKit tab bars.
  • Preserves top, center, and bottom positioning while dynamically restoring toast ordering when another activity-owned overlay opens.
  • Keeps bottom toasts above the software keyboard without taking input focus or blocking continued typing.
  • Restricts the Android 14+ touch region to visible toast cards, while retaining the documented Android 10–13 padding limitation.
  • Preserves toast animation and swipe state with an activity-scoped Compose recomposer.
  • Defers same-action modal/toast attachment and guards the first frame to prevent black navigation-bar flashes and window flicker.
  • Stabilizes Android dynamic presentation by keeping the native window at its final measured size and animating with rendering transforms and opacity.
  • Adds Android-only top spacing so the dynamic connector remains visible.
  • Cleans up toast windows and compositions when the activity is destroyed.
  • Incorporates and preserves the contributor history from Draw Android toasts above sheets and dialogs #5, with conflict resolutions adapted to current ToastKit and LayoutKit behavior.
  • Updates the changelog.

Why?

Android dialogs, modal bottom sheets, and detached Compose overlays use separate windows above the activity decor. ToastKit previously could render underneath them. The original approach in #5 addressed the ordering problem but could blink during reordering, briefly expose a black system-bar surface, block keyboard input around bottom toasts, and conflict with newer LayoutKit and dynamic-presentation behavior.

This change keeps ToastKit visible above activity-owned overlays while preserving focus, touch behavior, animations, keyboard input, and backward-compatible public APIs.

Closes #5.

How was it tested?

Automated:

  • composer test — 194 tests, 389 assertions passed
  • git diff --check
  • Android :app:compileDebugKotlin in the generated LayoutKit playground — passed

Manual Android testing on an emulator and physical Android device:

  • Toast above NativePHP modal, bottom sheet, and native alert dialog
  • Toast shown before and after overlays open
  • Swipe-to-dismiss while a dialog remains visible
  • Toast actions and underlying overlay controls
  • Bottom toast moving above the keyboard while input focus and typing continue
  • Dynamic presentation without repeated flashing, clipping, or layout instability
  • Dynamic connector visibility
  • LayoutKit floating and docked tab styles
  • Rotation while a toast is visible
  • Background/foreground restoration with normal timeout dismissal
  • No duplicate or orphaned toast windows after lifecycle changes

Platforms tested

  • PHP
  • JavaScript
  • Android
  • iOS
  • Not applicable / documentation only

Breaking changes?

None. The PHP/JavaScript APIs, events, positions, queue/stack behavior, actions, swipe dismissal, and iOS implementation are unchanged.

The visible Android improvement is that bottom toasts now move above the keyboard instead of being hidden behind it.

Checklist

  • Tests were added or updated where appropriate. Native host behavior was covered with the manual Android matrix; no PHP API changed.
  • Existing relevant tests pass.
  • Documentation was updated where necessary.
  • Public API and event/bridge compatibility were considered.
  • Android/iOS behavior parity was considered where relevant.
  • No unnecessary native dependencies were introduced.
  • No secrets, tokens, temporary logging, or debugging code were committed.
  • Native changes were tested in a generated NativePHP application where practical.

simonhamp and others added 3 commits October 25, 2026 03:45
Android hosted the toasts in ComposeViews inside the activity's decor view.
Material3's ModalBottomSheet and every Dialog are separate windows stacked
above the activity window, so a toast shown while one was open was drawn
underneath it.

Each position now gets its own TYPE_APPLICATION window, added through the
activity's WindowManager while that position has toasts and removed when it
is empty. Windows that share the activity's token are ordered by when they
were added, so while toasts are on screen the overlay checks each frame
whether another window of the activity was added after it, and re-adds
itself if so. The hosts compose against a recomposer the overlay owns, so a
toast keeps its animation and swipe state across a re-add.

The windows are FLAG_NOT_FOCUSABLE, so a text field in a sheet keeps focus
and the keyboard stays up. On API 34+ the touchable region is set to the
toast cards, so taps around them reach the screen. Before 34 there is no
public way to do that and the band's padding takes taps while a toast shows.

The overlay sits above the keyboard and is not given IME insets, so the
bottom band reads the keyboard height from the activity's other windows and
pads for it. Before, a bottom toast was hidden behind the keyboard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@victorycodedev
victorycodedev merged commit 73a0997 into main Nov 20, 2026
2 checks passed
@victorycodedev
victorycodedev deleted the fix/android-toasts-above-overlays branch November 20, 2026 15:00
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.

2 participants