Skip to main content
Firstlight

Firstlight / Docs

Recipes for the screens a forms app needs, setup for your coding agent, Laravel on native screens, and accessibility.

View source
Chat Composer

Chat Composer

Chat Composer is the bar people write messages in: an attach button, a text field that grows with its text, and a send button, with a tray of picked photos and files above. Put it in a <native:bottom-bar> under a Chat, so it stays above the keyboard.

Complete example

See Chat for the screen class.

<native:bottom-bar>
    <firstlight:chat-composer
        native:model.debounce.300ms="draft"
        :attachments="$pending"
        placeholder="Message"
        attach="photos,camera,files"
        @send="send"
        @attach="addAttachment"
        @removeAttachment="removeAttachment"
        @typing="whisperTyping"
        label="Message to Sam"
    />
</native:bottom-bar>

Props

API Accepted type Purpose
value / native:model string The draft text. native:model takes .live (default), .blur, .lazy and .debounce.Nms.
label string Required. Accessible name of the field, such as "Message to Sam".
placeholder string Hint text in the empty field.
attachments list of MediaValue, at most 10 Files waiting to be sent, shown as a tray above the field.
attach any of photos, camera, files, comma-separated or a list Sources the attach button offers. Absent hides the button. With one source, the button opens it directly.
max-lines positive int Lines the field grows to before it scrolls. Defaults to 6.
disabled bool Disables typing, attach, remove and send.
a11y-hint string Additional VoiceOver and TalkBack guidance.
class string External EDGE layout.

disk, directory, @submit and @press are rejected: @attach receives the picked file's temporary path, and the screen decides where to store it.

Events

Event Receives When
@send nothing The person pressed Send. Send is enabled when the draft has non-whitespace text or the tray has an attachment, and not while disabled. The draft is flushed to native:model first, whatever the sync mode, so PHP reads the text being sent. Clear the draft and tray by publishing.
@attach temporary absolute path Once for each picked file, in pick order. Commit it with MediaStorage::commit() and add the MediaValue to attachments. Required when attach is set.
@removeAttachment tray index The person removed a tray item. The tile hides until the next publication.
@typing nothing At most once every 3 seconds while the person edits a non-empty draft. Use it to tell others someone is typing without sending every keystroke.
@change the draft text As native:model syncs it.

Photos are stored as JPEG. Picked files are copied to the app's temporary directory before @attach receives the path.

State timing

The draft is native focused text, as on Text Area: typing, selection and composition stay native while the field is focused, and a publication doesn't replace text the person typed after the last sync. A publication that clears the sent draft clears the field, even while it keeps focus. The tray is PHP's: removals hide a tile only until PHP publishes the tray again.

A screen using KeepsDrafts keeps the draft text, but not the tray.

Accessibility

The field uses label as its accessible name. Attach, Send and Remove for each tray item are labelled buttons with 44-point (iOS) and 48-dp (Android) touch targets. Send, Attach, Remove, Photo Library, Camera and Browse Files are package chrome; see Localize chrome.

Platform behaviour

iOS uses a vertical SwiftUI TextField, a menu of sources, PhotosPicker for up to 10 photos, the system camera and fileImporter for several files. Android uses a Material 3 OutlinedTextField, a bottom sheet of sources, the system photo picker for up to 10 photos, the system camera app and the system document picker for several files.

Host application setup

The Camera source needs the same camera usage description as Media; Firstlight's manifest supplies a generic one.

Compatibility

Chat Composer supports the versions listed in the current compatibility reference. The host application must compile both Firstlight-owned native renderers declared by the package manifest.

Screenshots

Platform Light Dark
iOS Chat Composer on iOS in light mode Chat Composer on iOS in dark mode
Android Chat Composer on Android in light mode Chat Composer on Android in dark mode

Served from firstlightui/nativephp on GitHub.