Files
buzz/mobile/lib/features/channels/compose_bar/input_tray.dart
klopez4212 d647c9fd98 Refine iOS composer and transcribe recordings into drafts (#9574)
Refine the iOS composer with 40-point glass controls, native attachment
menus, persistent emoji access, and selected-text formatting. The mic
now transcribes recordings on device into an editable, unsent draft;
Dictation has no five-minute recording cap or timer label, and its
waveform fills the space between the controls. Voice note remains
available in attachments with its five-minute cap. Unsupported devices
fail before recording, and audio is retained until the draft is durably
saved. Stopped dictation remains recoverable across editor teardown;
failed retention and cleanup can be retried. Recovered transcripts are
inserted only once across navigation or restart, preserving live exact
mention bindings.

Preserve selection handles over glass with animated avatars. Reduce the
conversation fade to 100 points above the keyboard and transition
continuously to 180 as the keyboard closes, without a first-frame jump
when opening; Home is unchanged.

Validation: 5,117 mobile tests and 27 crypto tests pass; analysis
passes. Prior native suite on iPhone 16/iOS 26.5: 119 pass, one
pre-existing expected failure, zero unexpected failures. Physical Air
preview approved; simulator selection/dragging and attachment flows
exercised. Fixed the native navigation test's timing race and a
community-cache cleanup test that checked a parent directory before its
asynchronous removal completed. Repository-wide `just ci` previously
stopped in unchanged `buzz-test-client` load-generator tests; new-head
hosted checks are pending.

Snapshots: production composer in an iPhone Air simulator fixture with
fictional conversation text; Photos snapshot retained from the
attachment preview.

| Composer | Attachments | Photos |
| --- | --- | --- |
| ![Keyboard-up
composer](https://github.com/user-attachments/assets/b7c8f0a4-25f8-4ca2-b8ae-11e18655e64a)
| ![Native attachment
menu](https://github.com/user-attachments/assets/5eaf5259-8e04-4da7-93f5-1b2eccab3c3c)
|
![Photos](https://github.com/user-attachments/assets/a6216b7d-5eaf-482c-b587-6052825b88fc)
|

---------

Signed-off-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
Signed-off-by: Tom Brow <tomb@squareup.com>
Signed-off-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
Co-authored-by: Tom Brow <tomb@block.xyz>
Co-authored-by: Tom Brow <tomb@squareup.com>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
Co-authored-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
2026-11-20 16:35:20 +00:00

294 lines
9.5 KiB
Dart

part of '../compose_bar.dart';
enum _InputTool { keyboard, attachments }
class _ComposerInputTray extends HookWidget {
const _ComposerInputTray({
required this.tool,
required this.focusNode,
required this.enabled,
required this.attachments,
required this.attachmentSurface,
required this.suggestions,
required this.onDismissSuggestions,
required this.child,
});
final ValueNotifier<_InputTool?> tool;
final FocusNode focusNode;
final bool enabled;
final VoidCallback onDismissSuggestions;
final Widget? suggestions;
final Widget child;
final Widget Function(_AttachmentSurface) attachments;
final ValueNotifier<_AttachmentSurface> attachmentSurface;
@override
Widget build(BuildContext context) {
final portal = useMemoized(OverlayPortalController.new);
useListenable(focusNode);
useListenable(tool);
final visible =
enabled &&
(tool.value == _InputTool.attachments || suggestions != null) &&
(ModalRoute.of(context)?.isCurrent ?? true);
final expanded =
tool.value == _InputTool.attachments || suggestions != null;
void type() {
tool.value = null;
attachmentSurface.value = _AttachmentSurface.closed;
onDismissSuggestions();
}
useEffect(() {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!context.mounted) return;
if (visible) {
portal.show();
} else {
portal.hide();
tool.value = null;
}
});
return null;
}, [visible]);
return OverlayPortal.overlayChildLayoutBuilder(
controller: portal,
overlayLocation: OverlayChildLocation.rootOverlay,
overlayChildBuilder: (context, info) {
final origin = MatrixUtils.transformPoint(
info.childPaintTransform,
Offset.zero,
);
final availableWidth = math.max(0.0, info.childSize.width);
final attachmentOpen = tool.value == _InputTool.attachments;
final content = attachmentOpen
? attachments(attachmentSurface.value)
: suggestions?.key == const ValueKey('no-suggestions')
? const Padding(
padding: EdgeInsets.all(24),
child: Text('No matching results'),
)
: suggestions ?? const SizedBox.shrink();
final width = math.min(
availableWidth,
attachmentOpen && attachmentSurface.value == _AttachmentSurface.menu
? 280.0
: expanded
? 440.0
: 560.0,
);
final maxHeight = math.max(
48.0,
origin.dy - 8 - MediaQuery.paddingOf(context).top,
);
return Positioned(
left: origin.dx,
bottom: info.overlaySize.height - origin.dy + 8,
width: availableWidth,
child: Align(
alignment: Alignment.bottomLeft,
heightFactor: 1,
child: TapRegion(
groupId: portal,
consumeOutsideTaps: expanded,
onTapOutside: expanded ? (_) => type() : null,
child: TextFieldTapRegion(
child: _ComposerGlassScope(
child: Material(
type: MaterialType.transparency,
child: _ComposerToolStripGlass(
canvasSize: Size(availableWidth, maxHeight),
phase: attachmentOpen
? attachmentSurface.value.name
: suggestions != null
? 'suggestions'
: 'strip',
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: maxHeight,
minWidth: width,
maxWidth: width,
),
child:
attachmentOpen &&
attachmentSurface.value !=
_AttachmentSurface.menu
? SizedBox(
height: math.min(320, maxHeight),
child: content,
)
: content,
),
),
),
),
),
),
),
);
},
// Composer controls belong to the tray, so a tap on them reaches its
// target instead of being consumed as a dismissal.
child: TapRegion(groupId: portal, child: child),
);
}
}
/// Suppresses nested cards when content is hosted in the shared glass surface.
class _ComposerGlassScope extends InheritedWidget {
const _ComposerGlassScope({required super.child});
static bool of(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<_ComposerGlassScope>() != null;
@override
bool updateShouldNotify(_ComposerGlassScope oldWidget) => false;
}
/// Native glass identities share a canvas large enough for both transition states.
class _ComposerToolStripGlass extends HookWidget {
const _ComposerToolStripGlass({
required this.child,
required this.canvasSize,
required this.phase,
});
final Widget child;
final Size canvasSize;
final String phase;
@override
Widget build(BuildContext context) {
final channel = useRef<MethodChannel?>(null);
final measured = useRef<Size?>(null);
final reducedMotion = MediaQuery.disableAnimationsOf(context);
final contentReveal = useAnimationController(
initialValue: 1,
duration: reducedMotion
? Duration.zero
: const Duration(milliseconds: 240),
);
final previousPhase = useRef(phase);
useEffect(() {
if (reducedMotion) {
contentReveal.value = 1;
} else if (previousPhase.value != phase) {
contentReveal.forward(from: 0);
}
previousPhase.value = phase;
return null;
}, [phase, reducedMotion]);
Future<void> update(Size size) async {
measured.value = size;
try {
await channel.value?.invokeMethod<void>('geometry', {
'width': size.width,
'height': size.height,
'phase': phase,
'reducedMotion': reducedMotion,
});
} on MissingPluginException {
// Platform view registration is absent in widget tests.
} on PlatformException {
// A disposed native view no longer needs geometry updates.
}
}
useEffect(() {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (context.mounted && measured.value != null) {
unawaited(update(measured.value!));
}
});
return null;
}, [phase, reducedMotion]);
return Stack(
clipBehavior: Clip.none,
alignment: Alignment.bottomLeft,
children: [
Positioned(
left: 0,
bottom: 0,
width: canvasSize.width,
height: canvasSize.height,
child: IgnorePointer(
child: ExcludeSemantics(
child: UiKitView(
key: ValueKey(context.theme.brightness),
viewType: 'buzz/composer_tool_strip_glass',
creationParams: {'brightness': context.theme.brightness.name},
creationParamsCodec: const StandardMessageCodec(),
onPlatformViewCreated: (id) {
channel.value = MethodChannel(
'buzz/composer_tool_strip_glass/$id',
);
if (measured.value != null) {
unawaited(update(measured.value!));
}
},
),
),
),
),
ClipRRect(
borderRadius: BorderRadius.circular(24),
child: AnimatedSize(
duration: reducedMotion
? Duration.zero
: const Duration(milliseconds: 180),
alignment: Alignment.bottomLeft,
curve: Curves.easeInOutCubic,
child: _GlassContentSize(
onSize: (size) {
measured.value = size;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (context.mounted) unawaited(update(measured.value!));
});
},
child: FadeTransition(
opacity: contentReveal.drive(
CurveTween(curve: const Interval(0.85, 1)),
),
child: AnimatedBuilder(
animation: contentReveal,
child: child,
builder: (_, child) => IgnorePointer(
ignoring: contentReveal.value < 0.85,
child: child,
),
),
),
),
),
),
],
);
}
}
class _GlassContentSize extends SingleChildRenderObjectWidget {
const _GlassContentSize({required this.onSize, required super.child});
final ValueChanged<Size> onSize;
@override
RenderObject createRenderObject(BuildContext context) =>
_GlassContentSizeRender(onSize);
@override
void updateRenderObject(
BuildContext context,
_GlassContentSizeRender renderObject,
) {
renderObject.onSize = onSize;
}
}
class _GlassContentSizeRender extends RenderProxyBox {
_GlassContentSizeRender(this.onSize);
ValueChanged<Size> onSize;
Size? reported;
@override
void performLayout() {
super.performLayout();
if (reported == size) return;
reported = size;
onSize(size);
}
}