Merge branch 'develop' into fix/channel-mute

This commit is contained in:
Sahil Kumar
2023-05-02 20:46:03 +05:30
committed by GitHub
2 changed files with 72 additions and 10 deletions
+21 -1
View File
@@ -31,7 +31,27 @@
return true;
),
```
- Added `StreamMessageInput.hintGetter` to allow users to customize the hint text of the message
input. [#1401](https://github.com/GetStream/stream-chat-flutter/issues/1401)
```dart
StreamMessageInput(
hintGetter: (context, hintType) {
switch (hintType) {
case HintType.searchGif:
return 'Custom Search Giphy';
case HintType.addACommentOrSend:
return 'Custom Add a comment or send';
case HintType.slowModeOn:
return 'Custom Slow mode is on';
case HintType.writeAMessage:
return 'Custom Write a message';
}
},
),
```
🔄 Changed
- Deprecated `MessageTheme.linkBackgroundColor` in favor of `MessageTheme.urlAttachmentBackgroundColor`.
@@ -32,6 +32,26 @@ typedef OgPreviewFilter = bool Function(
String messageText,
);
/// Different types of hints that can be shown in [StreamMessageInput].
enum HintType {
/// Hint for [StreamMessageInput] when the command is enabled and the command
/// is 'giphy'.
searchGif,
/// Hint for [StreamMessageInput] when there are attachments.
addACommentOrSend,
/// Hint for [StreamMessageInput] when slow mode is enabled.
slowModeOn,
/// Hint for [StreamMessageInput] when other conditions are not met.
writeAMessage,
}
/// Function that returns the hint text for [StreamMessageInput] based on
/// [type].
typedef HintGetter = String? Function(BuildContext context, HintType type);
/// Inactive state:
///
/// ![screenshot](https://raw.githubusercontent.com/GetStream/stream-chat-flutter/master/packages/stream_chat_flutter/screenshots/message_input.png)
@@ -122,6 +142,7 @@ class StreamMessageInput extends StatefulWidget {
this.clearQuotedMessageKeyPredicate =
_defaultClearQuotedMessageKeyPredicate,
this.ogPreviewFilter = _defaultOgPreviewFilter,
this.hintGetter = _defaultHintGetter,
});
/// The predicate used to send a message on desktop/web
@@ -271,6 +292,25 @@ class StreamMessageInput extends StatefulWidget {
/// preview.
final OgPreviewFilter ogPreviewFilter;
/// Returns the hint text for the message input.
final HintGetter hintGetter;
static String? _defaultHintGetter(
BuildContext context,
HintType type,
) {
switch (type) {
case HintType.searchGif:
return context.translations.searchGifLabel;
case HintType.addACommentOrSend:
return context.translations.addACommentOrSendLabel;
case HintType.slowModeOn:
return context.translations.slowModeOnLabel;
case HintType.writeAMessage:
return context.translations.writeAMessageLabel;
}
}
static bool _defaultOgPreviewFilter(
Uri matchedUri,
String messageText,
@@ -982,18 +1022,20 @@ class StreamMessageInputState extends State<StreamMessageInput>
leading: true,
);
String _getHint(BuildContext context) {
String? _getHint(BuildContext context) {
HintType hintType;
if (_commandEnabled && _effectiveController.message.command == 'giphy') {
return context.translations.searchGifLabel;
}
if (_effectiveController.attachments.isNotEmpty) {
return context.translations.addACommentOrSendLabel;
}
if (_timeOut != 0) {
return context.translations.slowModeOnLabel;
hintType = HintType.searchGif;
} else if (_effectiveController.attachments.isNotEmpty) {
hintType = HintType.addACommentOrSend;
} else if (_timeOut != 0) {
hintType = HintType.slowModeOn;
} else {
hintType = HintType.writeAMessage;
}
return context.translations.writeAMessageLabel;
return widget.hintGetter.call(context, hintType);
}
String? _lastSearchedContainsUrlText;