Files
buzz/mobile/test/shared/widgets/native_avatar_image_test.dart
klopez4212 6cf4582002 Use native iOS navigation bars with large titles and avatars (#8052)
## Summary

Use UIKit navigation bars across iOS pages, with large titles that
collapse into the toolbar on scroll and a light native blur. Home uses
the active community name as its title and shows community and profile
avatars with centered emoji and stable loading, without flashing back to
icons. Channel headers retain the member count, tap-to-settings title,
and Huddle action. Their ultra-thin native material has a soft lower
edge and stays visible at the timeline bottom. The hidden title-layout
scroll view has its automatic edge effects disabled so it cannot add a
second backdrop.

| Expanded Home | Scrolled Home | Settings |
| --- | --- | --- |
| <img
src="https://raw.githubusercontent.com/block/buzz/47a77d3ff1d30fc74f7488c1a4427e41bbb85c4e/pr-8052--home.png"
alt="home" width="240"> | <img
src="https://raw.githubusercontent.com/block/buzz/47a77d3ff1d30fc74f7488c1a4427e41bbb85c4e/pr-8052--scrolled.png"
alt="scrolled" width="240"> | <img
src="https://raw.githubusercontent.com/block/buzz/47a77d3ff1d30fc74f7488c1a4427e41bbb85c4e/pr-8052--settings.png"
alt="settings" width="240"> |

Channel title, member count, and Huddle control:

<img
src="https://raw.githubusercontent.com/block/buzz/47a77d3ff1d30fc74f7488c1a4427e41bbb85c4e/pr-8052--channel.png"
alt="Channel navigation" width="280">

### Related issue

No matching open issue found.

### Testing

- Added causal regressions for Profile/Edit Photo native titles,
metrics-only collapse changes, and native-header suppression throughout
channel/thread reaction and action backdrops. Each regression fails when
its corresponding fix is removed.

- Mobile formatting and analysis passed. Full mobile test rerun passed:
2,622 tests, 4 skipped, plus 3 push-disabled build tests.
- Native iPhone Air regression passed: repeated title expansion/collapse
and scroll material behavior.
- Navigation and blur were accepted on the connected iPhone using the
existing profile. Simulator snapshots use real community data. The
subsequent review fixes have widget coverage; fresh physical-device
verification of Profile states, Dynamic Type changes, and message
backdrops is pending.
- Full repository `just ci` was blocked by local disk exhaustion while
compiling Rust dependencies.

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
2026-10-03 18:10:03 +01:00

153 lines
5.2 KiB
Dart

import 'dart:ui' as ui;
import 'dart:convert';
import 'package:buzz/shared/emoji/emoji_avatar.dart';
import 'package:buzz/shared/widgets/avatar_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('bounds remote avatar decoding before painting the native PNG', (
tester,
) async {
await tester.runAsync(() async {
final recorder = ui.PictureRecorder();
Canvas(recorder).drawColor(Colors.blue, BlendMode.src);
final picture = recorder.endRecording();
final image = await picture.toImage(1440, 720);
final bytes = (await image.toByteData(
format: ui.ImageByteFormat.png,
))!.buffer.asUint8List();
image.dispose();
picture.dispose();
final provider = _RecordingImage(bytes);
final png = await nativeAvatarImage(
url: 'https://example.com/avatar.png',
initial: 'A',
background: Colors.white,
foreground: Colors.black,
networkImage: (_) => provider,
);
expect(png, isNotNull);
expect(provider.decodedWidth, lessThanOrEqualTo(72));
expect(provider.decodedHeight, lessThanOrEqualTo(72));
expect(provider.decodedWidth, greaterThan(0));
});
});
for (final size in [const Size(1440, 720), const Size(720, 1440)]) {
testWidgets('bounds inline raster decode at $size before native painting', (
tester,
) async {
await tester.runAsync(() async {
final recorder = ui.PictureRecorder();
Canvas(recorder).drawColor(Colors.blue, BlendMode.src);
final picture = recorder.endRecording();
final image = await picture.toImage(
size.width.toInt(),
size.height.toInt(),
);
final bytes = (await image.toByteData(
format: ui.ImageByteFormat.png,
))!.buffer.asUint8List();
image.dispose();
picture.dispose();
final decodedSizes = <Size>[];
final previous = ui.Image.onCreate;
ui.Image.onCreate = (image) {
decodedSizes.add(
Size(image.width.toDouble(), image.height.toDouble()),
);
previous?.call(image);
};
try {
final png = await nativeAvatarImage(
url: 'data:image/png;base64,${base64Encode(bytes)}',
initial: 'A',
background: Colors.white,
foreground: Colors.black,
networkImage: (_) => throw StateError('Unexpected network image'),
);
expect(png, isNotNull);
// The first image is the codec frame, before the final 72px canvas.
expect(decodedSizes.length, greaterThanOrEqualTo(2));
expect(decodedSizes.first.width, lessThanOrEqualTo(72));
expect(decodedSizes.first.height, lessThanOrEqualTo(72));
expect(decodedSizes.first.aspectRatio, size.aspectRatio);
expect(decodedSizes.first.longestSide, 72);
} finally {
ui.Image.onCreate = previous;
}
});
});
}
for (final emoji in ['🥳', '🦝', '👩🏽‍💻']) {
testWidgets('centers painted bounds of $emoji in the native avatar', (
tester,
) async {
await tester.runAsync(() async {
final png = await nativeAvatarImage(
url: emojiAvatarDataUrl(emoji, 0xFF000000),
initial: 'K',
background: Colors.black,
foreground: Colors.white,
networkImage: (_) => throw StateError('Unexpected network image'),
);
expect(png, isNotNull);
final codec = await ui.instantiateImageCodec(png!);
final frame = await codec.getNextFrame();
final pixels = (await frame.image.toByteData())!;
var minX = 72;
var minY = 72;
var maxX = -1;
var maxY = -1;
for (var y = 0; y < 72; y++) {
for (var x = 0; x < 72; x++) {
final index = (y * 72 + x) * 4;
if (pixels.getUint8(index) +
pixels.getUint8(index + 1) +
pixels.getUint8(index + 2) <
48) {
continue;
}
if (x < minX) minX = x;
if (x > maxX) maxX = x;
if (y < minY) minY = y;
if (y > maxY) maxY = y;
}
}
frame.image.dispose();
codec.dispose();
expect(maxX, greaterThan(minX));
expect((minX + maxX + 1) / 2, closeTo(36, 0.5));
expect((minY + maxY + 1) / 2, closeTo(36, 0.5));
});
});
}
}
class _RecordingImage extends MemoryImage {
_RecordingImage(super.bytes);
final decodedSizes = <Size>[];
double get decodedWidth => decodedSizes.single.width;
double get decodedHeight => decodedSizes.single.height;
@override
ImageStreamCompleter loadImage(
MemoryImage key,
ImageDecoderCallback decode,
) => MultiFrameImageStreamCompleter(codec: _decode(decode), scale: 1);
Future<ui.Codec> _decode(ImageDecoderCallback decode) async {
final buffer = await ui.ImmutableBuffer.fromUint8List(bytes);
final codec = await decode(buffer);
final frame = await codec.getNextFrame();
decodedSizes.add(
Size(frame.image.width.toDouble(), frame.image.height.toDouble()),
);
frame.image.dispose();
return codec;
}
}