Files
buzz/mobile/lib/shared/widgets/avatar_shape.dart
klopez4212 8cc7e94392 Refine mobile Messages sections, Duo navigation, and chat typography (#9885)
## Summary

- Organize mobile Messages into configurable flat sections. See All
keeps the list and its search position when opening a conversation, and
supports side-by-side browsing on an unfolded Duo.
- Use the same 16-point Messages gutter in booklet and open Duo layouts.
The regular iPhone uses 20 points. Align navigation actions and use
native inline titles on See All.
- Update mobile typography and spacing across chat rows, message
bubbles, drafts, and the composer. Render code proportionally to the
17-point message body.

## Device review

Compare the leading edges of the section headings and channel icons in
Messages on the open Duo and in booklet mode. Open See All and check
that its rows follow the same column.

---------

Signed-off-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
2026-11-23 13:14:05 -08:00

112 lines
3.5 KiB
Dart

import 'package:flutter/widgets.dart';
/// The single source of avatar silhouettes.
///
/// Agents use desktop's squircle (`ROUNDED_SQUIRCLE_PATH` in
/// `desktop/src/shared/ui/AvatarClipPaths.tsx`) and people use circles.
/// Every avatar frame, clip, halo and placeholder takes its shape
/// from here, so the two never drift apart across surfaces or clients.
OutlinedBorder avatarShape({
required bool isAgent,
BorderSide side = BorderSide.none,
}) => isAgent ? _AgentSquircleBorder(side: side) : CircleBorder(side: side);
/// The avatar silhouette scaled to [rect], for canvas painting.
Path avatarPath(Rect rect, {required bool isAgent}) =>
avatarShape(isAgent: isAgent).getOuterPath(rect);
/// Clips [child] to the avatar silhouette for [isAgent].
class AvatarClip extends StatelessWidget {
/// Creates an avatar clip.
const AvatarClip({required this.isAgent, required this.child, super.key});
/// Whether [child] is an agent avatar.
final bool isAgent;
/// The avatar artwork.
final Widget child;
@override
Widget build(BuildContext context) => isAgent
? ClipPath(
clipper: ShapeBorderClipper(shape: avatarShape(isAgent: true)),
child: child,
)
// People keep the dedicated oval clip, the fast path in dense lists.
: ClipOval(child: child);
}
Path _agentSquirclePath(Rect rect) {
Offset at(double x, double y) =>
Offset(rect.left + rect.width * x, rect.top + rect.height * y);
final start = at(.5, 0);
final path = Path()..moveTo(start.dx, start.dy);
void curve(Offset a, Offset b, Offset c) =>
path.cubicTo(a.dx, a.dy, b.dx, b.dy, c.dx, c.dy);
curve(at(.93, 0), at(1, .07), at(1, .5));
curve(at(1, .93), at(.93, 1), at(.5, 1));
curve(at(.07, 1), at(0, .93), at(0, .5));
curve(at(0, .07), at(.07, 0), start);
return path..close();
}
/// Private so agent avatars can only get their shape from [avatarShape].
class _AgentSquircleBorder extends OutlinedBorder {
const _AgentSquircleBorder({super.side});
@override
_AgentSquircleBorder copyWith({BorderSide? side}) =>
_AgentSquircleBorder(side: side ?? this.side);
@override
EdgeInsetsGeometry get dimensions => EdgeInsets.all(side.strokeInset);
@override
Path getInnerPath(Rect rect, {TextDirection? textDirection}) =>
_agentSquirclePath(rect.deflate(side.strokeInset));
@override
Path getOuterPath(Rect rect, {TextDirection? textDirection}) =>
_agentSquirclePath(rect);
@override
void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) {
if (side.style == BorderStyle.none) return;
canvas.drawPath(
_agentSquirclePath(rect.inflate(side.strokeOffset / 2)),
side.toPaint(),
);
}
@override
ShapeBorder scale(double t) => _AgentSquircleBorder(side: side.scale(t));
@override
bool operator ==(Object other) =>
other is _AgentSquircleBorder && other.side == side;
@override
int get hashCode => side.hashCode;
}
/// Cuts a ring that follows the person or agent avatar silhouette.
class AvatarRingClipper extends CustomClipper<Path> {
const AvatarRingClipper({required this.isAgent, required this.strokeWidth});
final bool isAgent;
final double strokeWidth;
@override
Path getClip(Size size) {
final rect = Offset.zero & size;
return Path.combine(
PathOperation.difference,
avatarPath(rect, isAgent: isAgent),
avatarPath(rect.deflate(strokeWidth), isAgent: isAgent),
);
}
@override
bool shouldReclip(AvatarRingClipper oldClipper) =>
oldClipper.isAgent != isAgent || oldClipper.strokeWidth != strokeWidth;
}