Skip to content

Commit 00b1ec6

Browse files
square-tombstudio
andcommitted
fix(mobile): tighten avatar shape guard and iOS agent fallback
The iOS Add members fallback tile drew agents as a 30% rounded rect while their loaded avatar was a squircle. It now draws the same squircle. The geometry test now rejects the old rounded rect, and the source guard also flags the old 30%/60% agent radius idiom. Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz> Signed-off-by: Tom Brow <[email protected]>
1 parent f5188ee commit 00b1ec6

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎mobile/ios/Runner/NativeAddMembersSheet.swift‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ final class NativeAddMembersViewController: UITableViewController, UISearchResul
281281
let size = CGSize(width: 40, height: 40)
282282
return UIGraphicsImageRenderer(size: size).image { _ in
283283
(Self.color(user["avatarBackground"]) ?? .tertiarySystemFill).setFill()
284-
UIBezierPath(roundedRect: CGRect(origin: .zero, size: size),
285-
cornerRadius: user["agent"] as? Bool == true ? 12 : 20).fill()
284+
let rect = CGRect(origin: .zero, size: size)
285+
(user["agent"] as? Bool == true ? Self.agentSquircle(rect) : UIBezierPath(ovalIn: rect)).fill()
286286
let text = (user["initial"] as? String ?? "?") as NSString
287287
let attributes: [NSAttributedString.Key: Any] = [
288288
.font: UIFont.systemFont(ofSize: 18, weight: .medium),
@@ -293,6 +293,21 @@ final class NativeAddMembersViewController: UITableViewController, UISearchResul
293293
}.withRenderingMode(.alwaysOriginal)
294294
}
295295

296+
/// Mirrors avatar_shape.dart and desktop's avatar-squircle.svg.
297+
private static func agentSquircle(_ rect: CGRect) -> UIBezierPath {
298+
func at(_ x: CGFloat, _ y: CGFloat) -> CGPoint {
299+
CGPoint(x: rect.minX + rect.width * x, y: rect.minY + rect.height * y)
300+
}
301+
let path = UIBezierPath()
302+
path.move(to: at(0.5, 0))
303+
path.addCurve(to: at(1, 0.5), controlPoint1: at(0.93, 0), controlPoint2: at(1, 0.07))
304+
path.addCurve(to: at(0.5, 1), controlPoint1: at(1, 0.93), controlPoint2: at(0.93, 1))
305+
path.addCurve(to: at(0, 0.5), controlPoint1: at(0.07, 1), controlPoint2: at(0, 0.93))
306+
path.addCurve(to: at(0.5, 0), controlPoint1: at(0, 0.07), controlPoint2: at(0.07, 0))
307+
path.close()
308+
return path
309+
}
310+
296311
private static func color(_ value: Any?) -> UIColor? {
297312
guard let number = value as? NSNumber else { return nil }
298313
let argb = number.uint32Value

‎mobile/test/shared/widgets/avatar_shape_test.dart‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ void main() {
2020
(const Offset(92, 8), false),
2121
(const Offset(92, 92), false),
2222
(const Offset(8, 92), false),
23+
// Inside the old 30% rounded rect, outside the squircle.
24+
(const Offset(1.9, 22), false),
25+
(const Offset(98.1, 78), false),
2326
]) {
2427
expect(path.contains(point), inside, reason: '$point');
2528
}
@@ -33,7 +36,9 @@ void main() {
3336
test('avatar shapes come only from avatarShape', () {
3437
// Agent avatars drifted into circles and 30% rounded rects because each
3538
// surface picked its own shape. Shape decisions keyed on agent identity,
36-
// and person shapes on agent-only surfaces, must use avatar_shape.dart.
39+
// the old agent radius idiom, and person shapes on agent-only surfaces
40+
// must use avatar_shape.dart. Best effort: it matches the patterns that
41+
// produced past drift, not every possible spelling.
3742
final inlineAgentShape = RegExp(
3843
r'\b(isAgent|isBot|agent)\b\s*\?\s*(const\s+)?'
3944
r'(BoxShape|BorderRadius|Radius|CircleBorder|RoundedRectangleBorder|'
@@ -43,6 +48,10 @@ void main() {
4348
r'if\s*\(\s*!?\s*(isAgent|isBot|agent)\s*\)\s*return\s+'
4449
r'(ClipOval|ClipRRect|CircleAvatar)\b',
4550
);
51+
// The old hand-rolled agent radius: 30% of a size, or 60% of a radius.
52+
final agentRadius = RegExp(
53+
r'Radius\.circular\(\s*[\w.()+\s]*\*\s*0\.[36]\s*,?\s*\)',
54+
);
4655
final personShape = RegExp(r'\b(ClipOval|CircleAvatar|BoxShape\.circle)\b');
4756
final violations = <String>[];
4857
for (final file in Directory('lib').listSync(recursive: true)) {
@@ -53,6 +62,7 @@ void main() {
5362
for (final match in [
5463
...inlineAgentShape.allMatches(source),
5564
...inlineAgentClip.allMatches(source),
65+
...agentRadius.allMatches(source),
5666
if (path.startsWith('lib/features/agents/'))
5767
...personShape.allMatches(source),
5868
]) {

0 commit comments

Comments
 (0)