Skip to content

Commit 2dbd778

Browse files
chrisbobbesm-sayedi
authored andcommitted
action_sheet [nfc]: Make BottomSheetHeaderPlainText more flexible; rename
Before, this widget supported just one plain-styled multiline UI string: https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=3481-26993&m=dev In addition to that feature, it now also supports: - Richer text for that string, such as TextWithLink, which we'll use for read-receipts: https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=11367-20898&m=dev - A "title" line above that string, which is bigger and bolder; we'll also use that for read-receipts. - The header may appear with - a title and subtitle (as in the normal read-receipts case), or - just a title (as in read-receipts when loading or when nobody has read the message), or - just a message, as in the current caller in the view-reactions sheet - (The title may be richly styled too; we can use this when showing the channel name in the channel action sheet header, #1533, which calls for showing the channel privacy icon.)
1 parent 852f834 commit 2dbd778

File tree

2 files changed

+63
-15
lines changed

2 files changed

+63
-15
lines changed

lib/widgets/action_sheet.dart

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,31 +102,79 @@ void _showActionSheet(
102102
});
103103
}
104104

105-
/// A header for a bottom sheet with a multiline UI string.
105+
typedef WidgetBuilderFromTextStyle = Widget Function(TextStyle);
106+
107+
/// A header for a bottom sheet with an optional title and multiline message.
108+
///
109+
/// A title, message, or both must be provided.
110+
///
111+
/// Provide a title by passing [title] or [buildTitle] (not both).
112+
/// Provide a message by passing [message] or [buildMessage] (not both).
113+
/// The "build" params support richer content, such as [TextWithLink],
114+
/// and the callback is passed a [TextStyle] which is the base style.
106115
///
107116
/// Assumes 8px padding below the top of the bottom sheet.
108117
///
109-
/// Figma:
118+
/// Figma; just message no title:
110119
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=3481-26993&m=dev
111-
class BottomSheetHeaderPlainText extends StatelessWidget {
112-
const BottomSheetHeaderPlainText({super.key, required this.text});
113-
114-
final String text;
120+
///
121+
/// Figma; title and message:
122+
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=6326-96125&m=dev
123+
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=11367-20898&m=dev
124+
/// The latter example (read receipts) has more horizontal and bottom padding;
125+
/// that looks like an accident that we don't need to follow.
126+
/// It also colors the message text more opaquely…that difference might be
127+
/// intentional, but Vlad's time is limited and I prefer consistency.
128+
class BottomSheetHeader extends StatelessWidget {
129+
const BottomSheetHeader({
130+
super.key,
131+
this.title,
132+
this.buildTitle,
133+
this.message,
134+
this.buildMessage,
135+
}) : assert(message == null || buildMessage == null),
136+
assert(title == null || buildTitle == null),
137+
assert((message != null || buildMessage != null)
138+
|| (title != null || buildTitle != null));
139+
140+
final String? title;
141+
final Widget Function(TextStyle)? buildTitle;
142+
final String? message;
143+
final Widget Function(TextStyle)? buildMessage;
115144

116145
@override
117146
Widget build(BuildContext context) {
118147
final designVariables = DesignVariables.of(context);
119148

149+
final baseTitleStyle = TextStyle(
150+
fontSize: 20,
151+
height: 20 / 20,
152+
color: designVariables.title,
153+
).merge(weightVariableTextStyle(context, wght: 600));
154+
155+
final effectiveTitle = switch ((buildTitle, title)) {
156+
(final build?, null) => build(baseTitleStyle),
157+
(null, final data?) => Text(style: baseTitleStyle, data),
158+
_ => null,
159+
};
160+
161+
final baseSubtitleStyle = TextStyle(
162+
color: designVariables.labelTime,
163+
fontSize: 17,
164+
height: 22 / 17);
165+
166+
final effectiveMessage = switch ((buildMessage, message)) {
167+
(final build?, null) => build(baseSubtitleStyle),
168+
(null, final data?) => Text(style: baseSubtitleStyle, data),
169+
_ => null,
170+
};
171+
120172
return Padding(
121173
padding: EdgeInsets.fromLTRB(16, 8, 16, 4),
122-
child: SizedBox(
123-
width: double.infinity,
124-
child: Text(
125-
style: TextStyle(
126-
color: designVariables.labelTime,
127-
fontSize: 17,
128-
height: 22 / 17),
129-
text)));
174+
child: Column(
175+
crossAxisAlignment: CrossAxisAlignment.stretch,
176+
spacing: 8,
177+
children: [?effectiveTitle, ?effectiveMessage]));
130178
}
131179
}
132180

lib/widgets/emoji_reaction.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ class ViewReactionsHeader extends StatelessWidget {
822822
if (reactions == null || reactions.aggregated.isEmpty) {
823823
return Padding(
824824
padding: const EdgeInsets.only(top: 8),
825-
child: BottomSheetHeaderPlainText(text: zulipLocalizations.seeWhoReactedSheetNoReactions),
825+
child: BottomSheetHeader(message: zulipLocalizations.seeWhoReactedSheetNoReactions),
826826
);
827827
}
828828

0 commit comments

Comments
 (0)