Skip to content

fix: render the trailing switch on iOS list items - #68

Open
SRWieZ wants to merge 1 commit into
NativePHP:mainfrom
SRWieZ:fix/ios-list-item-trailing-switch
Open

fix: render the trailing switch on iOS list items#68
SRWieZ wants to merge 1 commit into
NativePHP:mainfrom
SRWieZ:fix/ios-list-item-trailing-switch

Conversation

@SRWieZ

@SRWieZ SRWieZ commented Aug 24, 2026

Copy link
Copy Markdown
Member

The bug

Give a list item a trailing switch:

<native:list-item headline="Keep screen awake"
    :trailingSwitch="$keepAwake" on-trailing-change="setKeepAwake" />

On Android you get a Material Switch. On iOS you get nothing — the row renders with an empty trailing slot, no error anywhere.

Why

In NativeUIListItemRenderer.swift, the trailing switch case was a stub:

case "switch":
    EmptyView() // Switch requires state management - handled at a higher level

There is no "higher level" — nothing else ever renders it.

The fix

Render a real SwiftUI Toggle, following the exact pattern NativeUIToggleRenderer already uses:

  • Local @State, so the thumb animates instantly on tap.
  • Echo prevention: a server re-render that just echoes the value we sent doesn't snap the thumb back, but a genuine programmatic change still updates it.
  • Tinted with the theme's primary color, like every other switch.
  • Reports the new value (a bool) through the row's on_trailing_change callback — the same payload Android has always sent, so one PHP handler works on both platforms.
  • A disabled row, or one without a callback, shows a non-interactive switch.

No Android changes, no PHP changes, no API changes — trailingSwitch() simply starts working on iOS.

`trailingSwitch()` set trailing_type=switch, but the iOS renderer's
switch case was an EmptyView stub ("handled at a higher level" — no
such level exists), so the row silently rendered nothing. Android has
always drawn a Material Switch here.

Render a real SwiftUI Toggle with local state and the same
echo-prevention sync as NativeUIToggleRenderer, reporting through the
row's on_trailing_change callback with a bool payload — exactly what
Android sends.
@SRWieZ SRWieZ changed the title iOS: render the trailing switch on list items fix: render the trailing switch on iOS list items Aug 24, 2026
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