Skip to content

Commit a1ef23c

Browse files
klopez4212Terp
andauthored
feat(mobile): unify the Android conversation composer (#10015)
## Summary Bring the Android chat composer into a single capsule. The plus opens attachments, emoji slides left as Send scales into place, and voice-note recording shows a bare X to discard. The empty composer returns to the iOS preview’s 36 dp side margins when the keyboard closes. Related to #10013 and the earlier Android preview in #9943. ## Snapshots Resting composer on Pixel 10 ![Resting Android composer](https://github.com/user-attachments/assets/dcb83ad5-51b0-4ce5-be1a-e2f1e406b28c) Android widget snapshots with fictional member and channel data | Type `@` to mention someone | Type `#` to reference a channel | | --- | --- | | ![Member suggestion card above the composer](https://github.com/user-attachments/assets/74b78fd6-75e3-4d12-8f3a-52807f779065) | ![Channel suggestion card above the composer](https://github.com/user-attachments/assets/53c31e2d-d592-4db1-a964-8e7e95a79380) | ## Testing - On Pixel 10, typed both triggers and visually confirmed the corresponding suggestion cards above the keyboard. - Checked attachment-menu entry and the active and inactive composer margins on the device. - All 238 composer tests passed, including mention and channel selection, sending and discarding voice notes, and compact layout restoration. Eight additional focused tests passed. Flutter analysis passed. - Full mobile pre-push checks passed, including formatting, analysis, the Flutter suite, and secp256k1 package tests. ## Android preview decisions - The plus, emoji, and discard controls retain their 32 dp touch areas for the device trial. - Format is available when text is selected. Selection-only formatting is intentional for this preview. --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
1 parent f948e4b commit a1ef23c

18 files changed

Lines changed: 519 additions & 273 deletions

‎mobile/lib/features/channels/compose_bar/attachments.dart‎

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ bool _queueComposerImages(
8888

8989
enum _AttachmentSurface { closed, menu, camera, photos }
9090

91+
void _openComposerMedia(
92+
_AttachmentSurface surface,
93+
ValueNotifier<_InputTool?> inputTool,
94+
ValueNotifier<bool> isComposerExpanded,
95+
FocusNode focusNode,
96+
ValueNotifier<_AttachmentSurface> attachmentSurface,
97+
) {
98+
if (_usesMobileComposer &&
99+
(surface == _AttachmentSurface.camera ||
100+
defaultTargetPlatform == TargetPlatform.android)) {
101+
inputTool.value = _InputTool.attachments;
102+
}
103+
if (defaultTargetPlatform == TargetPlatform.android) {
104+
isComposerExpanded.value = false;
105+
}
106+
focusNode.unfocus();
107+
attachmentSurface.value = surface;
108+
}
109+
91110
void _toggleComposerAttachments(
92111
ValueNotifier<_AttachmentSurface> surface,
93112
ValueNotifier<_InputTool?> tool,
@@ -98,13 +117,15 @@ void _toggleComposerAttachments(
98117
_AttachmentSurface.camera ||
99118
_AttachmentSurface.photos => _AttachmentSurface.menu,
100119
};
101-
if (defaultTargetPlatform == TargetPlatform.iOS) {
120+
if (_usesMobileComposer) {
102121
tool.value = surface.value == _AttachmentSurface.closed
103122
? null
104123
: _InputTool.attachments;
105124
}
106125
}
107126

127+
bool get _usesMobileComposer => _hasCombinedMediaPicker;
128+
108129
bool get _hasCombinedMediaPicker =>
109130
defaultTargetPlatform == TargetPlatform.iOS ||
110131
defaultTargetPlatform == TargetPlatform.android;
@@ -199,7 +220,8 @@ class _AttachmentSurfacePanel extends HookWidget {
199220
surface == _AttachmentSurface.camera ||
200221
surface == _AttachmentSurface.photos;
201222
final morphController = useAnimationController(
202-
initialValue: isExpanded ? 1 : 0,
223+
initialValue:
224+
isExpanded && defaultTargetPlatform != TargetPlatform.android ? 1 : 0,
203225
duration: reducedMotion
204226
? Duration.zero
205227
: const Duration(milliseconds: 320),
@@ -283,7 +305,8 @@ class _AttachmentSurfacePanel extends HookWidget {
283305
? const Cubic(0.22, 1, 0.36, 1).transform(rawProgress)
284306
: Curves.easeInOutCubic.transform(rawProgress);
285307

286-
if (defaultTargetPlatform == TargetPlatform.iOS) {
308+
if (defaultTargetPlatform == TargetPlatform.iOS ||
309+
_ComposerGlassScope.of(context)) {
287310
if (surface != _AttachmentSurface.menu) {
288311
return SizedBox.expand(child: expandedContent);
289312
}
@@ -532,7 +555,32 @@ class _AttachmentTrigger extends StatelessWidget {
532555

533556
@override
534557
Widget build(BuildContext context) {
535-
if (defaultTargetPlatform == TargetPlatform.iOS) {
558+
if (defaultTargetPlatform == TargetPlatform.android) {
559+
return SizedBox.square(
560+
dimension: size,
561+
child: IconButton(
562+
tooltip: switch (surface) {
563+
_AttachmentSurface.closed =>
564+
formattingOpen ? 'Close formatting' : 'Add attachment',
565+
_AttachmentSurface.menu => 'Close attachments',
566+
_AttachmentSurface.camera ||
567+
_AttachmentSurface.photos => 'Back to attachment options',
568+
},
569+
style: _composerIconStyle,
570+
icon: Icon(switch (surface) {
571+
_AttachmentSurface.closed =>
572+
formattingOpen ? BuzzIcons.x : BuzzIcons.plus,
573+
_AttachmentSurface.menu => BuzzIcons.x,
574+
_AttachmentSurface.photos ||
575+
_AttachmentSurface.camera => BuzzIcons.chevronLeft,
576+
}, size: 24),
577+
onPressed: enabled
578+
? () => _runComposerAction(() => onTap(context))
579+
: null,
580+
),
581+
);
582+
}
583+
if (_usesMobileComposer) {
536584
return IosGlassNavigationButton(
537585
icon: switch (surface) {
538586
_AttachmentSurface.closed =>

‎mobile/lib/features/channels/compose_bar/compose_bar_widget.dart‎

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ class ComposeBar extends HookConsumerWidget {
207207
androidImeFallbackTimer: androidImeFallbackTimer,
208208
androidImeTransitionStarted: androidImeTransitionStarted,
209209
collapseComposer: collapseComposer,
210+
attachmentSurface: attachmentSurface,
211+
expanded: isComposerExpanded,
210212
keepKeyboardSpace: () =>
211213
inputTool.value != null || isEmojiPickerOpen.value,
212214
);
@@ -416,7 +418,6 @@ class ComposeBar extends HookConsumerWidget {
416418
final mentionRows = mentionChooser.rows;
417419
final suggestions = mentionRows.rows;
418420

419-
// Filter channels against the query.
420421
final channels = channelsAsync.asData?.value ?? <Channel>[];
421422
final channelSuggestions = filterChannels(channels, channelQuery.value);
422423

@@ -499,13 +500,12 @@ class ComposeBar extends HookConsumerWidget {
499500
}
500501

501502
bool canSend() =>
502-
!(draftMembers != null && preparingAttachments.value > 0) &&
503+
preparingAttachments.value == 0 &&
503504
!interactionLocked &&
504505
(controller.text.trim().isNotEmpty || hasAttachments) &&
505506
!isSending.value &&
506507
uploadingCount.value == 0;
507508

508-
// Send the message.
509509
Future<void> send() async {
510510
if (!canSend()) return;
511511
// A draft saved by an earlier Buzz yields to member names first.
@@ -870,14 +870,6 @@ class ComposeBar extends HookConsumerWidget {
870870
void toggleAttachments() =>
871871
_toggleComposerAttachments(attachmentSurface, inputTool);
872872

873-
void openCamera() {
874-
if (defaultTargetPlatform == TargetPlatform.iOS) {
875-
inputTool.value = _InputTool.attachments;
876-
}
877-
focusNode.unfocus();
878-
attachmentSurface.value = _AttachmentSurface.camera;
879-
}
880-
881873
final motionDuration = _composerMotionDuration(
882874
reducedMotion,
883875
attachmentSurface.value,
@@ -981,17 +973,21 @@ class ComposeBar extends HookConsumerWidget {
981973
onChannelSelect: insertChannel,
982974
onMentionSelect: insertMention,
983975
);
976+
void openMedia(_AttachmentSurface surface) => _openComposerMedia(
977+
surface,
978+
inputTool,
979+
isComposerExpanded,
980+
focusNode,
981+
attachmentSurface,
982+
);
984983
_AttachmentSurfacePanel buildOverlayPanel(_AttachmentSurface surface) {
985984
return _composerAttachmentPanel(
986985
preparePhotos: prepare,
987986
surface: surface,
988987
suggestionPanel: suggestionPanel,
989988
onBack: () => attachmentSurface.value = _AttachmentSurface.menu,
990-
onCamera: openCamera,
991-
onPhotos: () {
992-
focusNode.unfocus();
993-
attachmentSurface.value = _AttachmentSurface.photos;
994-
},
989+
onCamera: () => openMedia(_AttachmentSurface.camera),
990+
onPhotos: () => openMedia(_AttachmentSurface.photos),
995991
onVideo: () => chooseAttachment(() {
996992
final service = ref.read(mediaUploadServiceProvider);
997993
return pickThenQueue(
@@ -1001,6 +997,7 @@ class ComposeBar extends HookConsumerWidget {
1001997
}),
1002998
onVoiceNote: () {
1003999
inputTool.value = null;
1000+
attachmentSurface.value = _AttachmentSurface.closed;
10041001
voiceNote.start();
10051002
},
10061003
onFiles: () => chooseAttachment(() {
@@ -1084,20 +1081,23 @@ class ComposeBar extends HookConsumerWidget {
10841081
return _ComposerDockFrame(
10851082
expansionAnimation: composerExpansionController,
10861083
hasDraft: draftText.isNotEmpty,
1084+
mediaPickerOpen:
1085+
(defaultTargetPlatform == TargetPlatform.android &&
1086+
(attachmentSurface.value == _AttachmentSurface.camera ||
1087+
attachmentSurface.value == _AttachmentSurface.photos)),
10871088
forceFullWidth: _voiceNoteFullWidth(voiceNote, attachments.value),
10881089
child: _ComposerInputTray(
10891090
tool: inputTool,
10901091
attachments: buildOverlayPanel,
10911092
attachmentSurface: attachmentSurface,
10921093
focusNode: focusNode,
10931094
enabled:
1094-
defaultTargetPlatform == TargetPlatform.iOS &&
1095-
!interactionLocked &&
1096-
!voiceNote.isRecording,
1095+
_usesMobileComposer && !interactionLocked && !voiceNote.isRecording,
10971096
suggestions:
1098-
(chooserOpen && emojiSuggestions.isNotEmpty) ||
1099-
mentionChooser.query != null ||
1100-
channelQuery.value != null
1097+
defaultTargetPlatform == TargetPlatform.iOS &&
1098+
((chooserOpen && emojiSuggestions.isNotEmpty) ||
1099+
mentionChooser.query != null ||
1100+
channelQuery.value != null)
11011101
? suggestionPanel
11021102
: null,
11031103
onDismissSuggestions: () {
@@ -1124,6 +1124,8 @@ class ComposeBar extends HookConsumerWidget {
11241124
controller: suggestionOverlayController,
11251125
suppressed:
11261126
defaultTargetPlatform == TargetPlatform.iOS ||
1127+
(defaultTargetPlatform == TargetPlatform.android &&
1128+
attachmentSurface.value != _AttachmentSurface.closed) ||
11271129
(inputTool.value != null &&
11281130
inputTool.value != _InputTool.keyboard),
11291131
attachmentSurface: attachmentSurface,
@@ -1142,7 +1144,7 @@ class ComposeBar extends HookConsumerWidget {
11421144
: null,
11431145
textStyle: textStyle ?? chatBodyTextStyle,
11441146
voiceNoteRecorder: voiceNote.recorder,
1145-
keyboardToolbar: defaultTargetPlatform == TargetPlatform.iOS,
1147+
keyboardToolbar: _usesMobileComposer,
11461148
onTextTap: () {
11471149
inputTool.value = null;
11481150
attachmentSurface.value = _AttachmentSurface.closed;
@@ -1182,7 +1184,7 @@ class ComposeBar extends HookConsumerWidget {
11821184
showFormatting.value = true;
11831185
},
11841186
hasPendingUploads: uploadingCount.value > 0,
1185-
canSend: draftText.trim().isNotEmpty || hasAttachments,
1187+
canSend: canSend(),
11861188
isSending:
11871189
isSending.value || (draftMembers != null && sending),
11881190
readOnly: readOnly,

‎mobile/lib/features/channels/compose_bar/dock.dart‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,42 @@ class _ComposerDockFrame extends HookWidget {
77
final Animation<double> expansionAnimation;
88
final bool forceFullWidth;
99
final bool hasDraft;
10+
final bool mediaPickerOpen;
1011
final Widget child;
1112

1213
const _ComposerDockFrame({
1314
required this.expansionAnimation,
1415
required this.forceFullWidth,
1516
required this.hasDraft,
17+
required this.mediaPickerOpen,
1618
required this.child,
1719
});
1820

1921
@override
2022
Widget build(BuildContext context) {
2123
final reducedMotion = MediaQuery.disableAnimationsOf(context);
22-
final recordingTransition = useAnimationController(
24+
final expandDock = forceFullWidth || mediaPickerOpen;
25+
final widthTransition = useAnimationController(
2326
duration: reducedMotion
2427
? Duration.zero
2528
: const Duration(milliseconds: 200),
2629
reverseDuration: reducedMotion
2730
? Duration.zero
2831
: const Duration(milliseconds: 140),
29-
initialValue: forceFullWidth ? 1 : 0,
32+
initialValue: expandDock ? 1 : 0,
3033
);
3134
useEffect(() {
32-
if (forceFullWidth) {
33-
recordingTransition.value = math.max(
34-
recordingTransition.value,
35+
if (expandDock) {
36+
widthTransition.value = math.max(
37+
widthTransition.value,
3538
expansionAnimation.value.clamp(0.0, 1.0),
3639
);
37-
recordingTransition.forward();
40+
widthTransition.forward();
3841
} else {
39-
recordingTransition.reverse();
42+
widthTransition.reverse();
4043
}
4144
return null;
42-
}, [forceFullWidth, reducedMotion]);
45+
}, [expandDock, reducedMotion]);
4346
const compactVerticalOffset = Grid.twelve + Grid.quarter;
4447
final visibleBottomGutter = math.max(
4548
Grid.twelve,
@@ -98,13 +101,13 @@ class _ComposerDockFrame extends HookWidget {
98101
child: AnimatedBuilder(
99102
animation: Listenable.merge([
100103
expansionAnimation,
101-
recordingTransition,
104+
widthTransition,
102105
]),
103106
child: child,
104107
builder: (context, child) {
105108
final widthProgress = math.max(
106109
expansionAnimation.value.clamp(0.0, 1.0),
107-
recordingTransition.value,
110+
widthTransition.value,
108111
);
109112
final expansionProgress = expansionAnimation.value.clamp(
110113
0.0,
@@ -122,7 +125,9 @@ class _ComposerDockFrame extends HookWidget {
122125
padding: EdgeInsets.symmetric(
123126
horizontal: forceFullWidth
124127
? recordingGutterDelta * compactPositionProgress
125-
: 0,
128+
: hasDraft
129+
? 0
130+
: closedComposerExtraInset * (1 - widthProgress),
126131
),
127132
child: FractionallySizedBox(
128133
key: const ValueKey('composer-width-transition'),

‎mobile/lib/features/channels/compose_bar/helpers.dart‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,26 @@ void _useComposerKeyboardMetrics({
136136
required ObjectRef<Timer?> androidImeFallbackTimer,
137137
required ValueNotifier<bool> androidImeTransitionStarted,
138138
required VoidCallback collapseComposer,
139+
required ValueNotifier<_AttachmentSurface> attachmentSurface,
140+
required ValueNotifier<bool> expanded,
139141
bool Function()? keepKeyboardSpace,
140142
}) {
143+
final dismissedBehindMenu = useRef(false);
144+
useEffect(() {
145+
void finishDismissal() {
146+
if (!dismissedBehindMenu.value ||
147+
attachmentSurface.value != _AttachmentSurface.closed) {
148+
return;
149+
}
150+
dismissedBehindMenu.value = false;
151+
if (View.of(context).viewInsets.bottom != 0) return;
152+
expanded.value = false;
153+
focusNode.unfocus();
154+
}
155+
156+
attachmentSurface.addListener(finishDismissal);
157+
return () => attachmentSurface.removeListener(finishDismissal);
158+
}, [attachmentSurface, focusNode]);
141159
final appView = View.of(context);
142160
useEffect(() {
143161
final observer = _ComposerKeyboardMetricsObserver(
@@ -151,6 +169,9 @@ void _useComposerKeyboardMetrics({
151169
if (defaultTargetPlatform == TargetPlatform.android) {
152170
androidImeTransitionStarted.value = false;
153171
}
172+
dismissedBehindMenu.value =
173+
defaultTargetPlatform == TargetPlatform.android &&
174+
attachmentSurface.value == _AttachmentSurface.menu;
154175
if (keepKeyboardSpace?.call() ?? false) return;
155176
voiceNote.onKeyboardHidden();
156177
collapseComposer();
@@ -261,6 +282,7 @@ void _chooseComposerAttachment(
261282
ValueNotifier<_InputTool?>? inputTool,
262283
String? errorMessage,
263284
}) {
285+
if (defaultTargetPlatform == TargetPlatform.android) inputTool?.value = null;
264286
attachmentSurface.value = _AttachmentSurface.closed;
265287
unawaited(() async {
266288
try {

0 commit comments

Comments
 (0)