Skip to content

Commit 9a89178

Browse files
committed
update placeholder getter
1 parent 5013d7b commit 9a89178

7 files changed

Lines changed: 285 additions & 157 deletions

File tree

migrations/redesign/message_composer.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,10 @@ StreamComponentFactory(
202202

203203
## Message Input Placeholder API
204204

205-
The input placeholder text (the dimmed text shown inside the input field when it is empty) is now driven by a sealed-class hierarchy that adapts to the current input state. The previous `HintType` enum and `HintGetter` typedef have been removed, and the customization hook on `StreamMessageInput` is now called `placeholderBuilder`.
205+
The input placeholder text (the dimmed text shown inside the input field when it is empty) is now driven by a sealed-class hierarchy that adapts to the current input state. The previous `HintType` enum and `HintGetter` typedef have been removed, and the customization hook on `StreamMessageComposer` is now called `placeholderBuilder`.
206206

207207
The new placeholder types live in `lib/src/message_input/message_input_placeholder.dart` and are re-exported from `package:stream_chat_flutter/stream_chat_flutter.dart`.
208208

209-
> **Layered model.** The placeholder *resolution* (state machine that turns controller state into a string) lives on `StreamMessageInput`, the higher-level full-featured widget. The lower-level `StreamChatMessageComposer` design-system component stays a pure UI primitive and accepts a plain `String placeholder` — see [StreamChatMessageComposer (new)](#streamchatmessagecomposer-new). If you build directly on `StreamChatMessageComposer`, call `MessageInputPlaceholder.resolve(controller)` and your own builder yourself, then pass the resulting string in.
210-
211209
### What was removed
212210

213211
| Removed | Replacement |
@@ -216,8 +214,8 @@ The new placeholder types live in `lib/src/message_input/message_input_placehold
216214
| `typedef HintGetter = String? Function(BuildContext, HintType, Command?)` | `typedef MessageInputPlaceholderBuilder = String? Function(BuildContext, MessageInputPlaceholder)` |
217215
| `HintType resolveMessageInputHintType(controller)` | `MessageInputPlaceholder.resolve(controller)` factory |
218216
| `Command? resolveActiveMessageInputCommand(context, controller)` | Removed. Use `controller.message.command` (a `String?`) directly. The SDK no longer looks up the full `Command` object from the channel config when resolving the placeholder. |
219-
| `String? defaultMessageInputHintGetter(...)` | Removed from the public API. The default behaviour is now baked into `StreamMessageInput.placeholderBuilder`'s default value. To customize, supply your own builder with an exhaustive `switch` over [`MessageInputPlaceholder`](#sealed-class-state-shape). |
220-
| `StreamMessageInput.hintGetter` | `StreamMessageInput.placeholderBuilder` |
217+
| `String? defaultMessageInputHintGetter(...)` | Removed from the public API. The default behaviour is now baked into `StreamMessageComposer.placeholderBuilder`'s default value. To customize, supply your own builder with an exhaustive `switch` over [`MessageInputPlaceholder`](#sealed-class-state-shape). |
218+
| `StreamMessageInput.hintGetter` | `StreamMessageComposer.placeholderBuilder` |
221219

222220
### Behavior change: precedence
223221

@@ -257,15 +255,15 @@ Each case carries the contextual data relevant to that input state. Pattern-matc
257255
| Case | Field | Type | Description |
258256
|------|-------|------|-------------|
259257
| `WriteMessagePlaceholder` | `isEditing` | `bool` | `true` when the input is editing an existing message instead of composing a new one. Useful for swapping the placeholder while editing. |
260-
| `SlowModePlaceholder` | `cooldownTimeOut` | `int` | Remaining slow-mode cooldown in seconds. Mirrors `StreamMessageInputController.cooldownTimeOut`. |
258+
| `SlowModePlaceholder` | `cooldownTimeOut` | `int` | Remaining slow-mode cooldown in seconds. Mirrors `StreamMessageComposerController.cooldownTimeOut`. |
261259
| `SlowModePlaceholder` | `cooldown` | `Duration` | Convenience getter wrapping `cooldownTimeOut` for formatting timer strings. |
262260
| `CommandPlaceholder` | `command` | `String` | Active command name (e.g. `'giphy'`, `'mute'`, `'ban'`, or any backend-defined command). |
263261
| `AttachmentsPlaceholder` | `attachments` | `List<Attachment>` | Pending attachments held by the input. OG link previews are still included — filter via `Attachment.ogScrapeUrl` if you only want user-added ones. |
264262

265263
Example using the new fields (note that the sealed type forces an exhaustive switch — every case must be handled):
266264

267265
```dart
268-
StreamMessageInput(
266+
StreamMessageComposer(
269267
placeholderBuilder: (context, placeholder) {
270268
final translations = context.translations;
271269
return switch (placeholder) {
@@ -310,7 +308,7 @@ StreamMessageInput(
310308
**After:**
311309

312310
```dart
313-
StreamMessageInput(
311+
StreamMessageComposer(
314312
placeholderBuilder: (context, placeholder) {
315313
return switch (placeholder) {
316314
SlowModePlaceholder() => 'Slow mode is on',
@@ -327,7 +325,7 @@ StreamMessageInput(
327325
For backend-defined custom commands, pattern-match the relevant `CommandPlaceholder.command` values and use the SDK's localized labels for everything else:
328326

329327
```dart
330-
StreamMessageInput(
328+
StreamMessageComposer(
331329
placeholderBuilder: (context, placeholder) {
332330
final translations = context.translations;
333331
return switch (placeholder) {
@@ -431,6 +429,6 @@ The following public widgets are provided as building blocks for custom attachme
431429
- [ ] Replace `quotedMessageBuilder` / `quotedMessageAttachmentThumbnailBuilders` with `messageComposerInputHeader` or `messageComposerAttachment` overrides in `StreamComponentFactory`
432430
- [ ] If adopting `StreamMessageComposer` directly, wire up your own send/attachment logic via `onSendPressed` and `onAttachmentButtonPressed`
433431
- [ ] Move any composer UI customizations to `StreamComponentFactory`
434-
- [ ] Rename `StreamMessageInput.hintGetter` to `placeholderBuilder` and rewrite the callback to switch over `MessageInputPlaceholder` cases (`SlowModePlaceholder`, `CommandPlaceholder`, `AttachmentsPlaceholder`, `WriteMessagePlaceholder`) instead of the removed `HintType` enum. If you build directly on `StreamChatMessageComposer`, compute the placeholder string yourself via `MessageInputPlaceholder.resolve(controller)` and pass it via the `placeholder: String` parameter.
432+
- [ ] Rename `StreamMessageInput.hintGetter` to `StreamMessageComposer.placeholderBuilder` and rewrite the callback to switch over `MessageInputPlaceholder` cases (`SlowModePlaceholder`, `CommandPlaceholder`, `AttachmentsPlaceholder`, `WriteMessagePlaceholder`) instead of the removed `HintType` enum.
435433
- [ ] Review the new placeholder precedence (`slowMode > command > attachments > writeMessage`) and override `placeholderBuilder` if you need to preserve the old order
436434
- [ ] Add command-specific placeholders for any backend-defined commands you ship by pattern-matching on `CommandPlaceholder.command` in your `placeholderBuilder`

packages/stream_chat_flutter/lib/src/autocomplete/stream_autocomplete.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,6 @@ class _StreamAutocompleteField extends StatelessWidget {
544544
Widget build(BuildContext context) {
545545
return core.StreamMessageComposerInputField(
546546
controller: messageEditingController.textFieldController,
547-
placeholder: '',
548547
focusNode: focusNode,
549548
);
550549
}

0 commit comments

Comments
 (0)