Files
buzz/mobile/test/features/channels/message_carousel_preview_cases.dart
klopez4212 44b3c4823f Add swipeable photo stacks and native iOS gallery preview (#9259)
## Summary

Replace bubble photo carousels with swipeable, overlapping photo stacks,
with distinct sent/received layouts and a stationary photo count.
Opening and closing the gallery preserves the selected photo. Photo
frames follow the active theme.

Add an opt-in iOS 18+ native zoom gallery
(`BUZZ_NATIVE_PHOTO_ZOOM=true`) with paging, continuous dot scrubbing,
preview-backed loading, Reply/More actions, and Liquid Glass controls on
iOS 26+. The existing gallery remains the fallback. UIKit’s late corner
settling and brief return-transition input lockout remain known preview
limitations.

### Related issue

None found.

### Testing

Validation: full mobile pre-push checks/tests passed on `2b5bac3075`;
light/dark sent/received widget renders verified. Earlier native
simulator checks covered paging, scrubbing, downward close, and Reply.

Snapshots below are actual Flutter widget renders with sample photos
(not device screenshots).

| Before: carousel | After: sent | After: received |
| --- | --- | --- |
| ![Original photo
carousel](https://github.com/user-attachments/assets/9fb13b0a-d2b9-4429-9bb1-396deeb126da)
| ![Sent photo
stack](https://github.com/user-attachments/assets/ab6a3094-5460-45fb-8020-68c454d6474f)
| ![Received photo
stack](https://github.com/user-attachments/assets/0ec2e803-a5b5-4812-8159-2e0585eea199)
|



| Dark mode: sent | Dark mode: received |
| --- | --- |
| ![Dark sent photo
stack](https://github.com/user-attachments/assets/3d4f993a-4e59-4da8-a30b-c6a0c19ad7eb)
| ![Dark received photo
stack](https://github.com/user-attachments/assets/e552070a-e516-434c-ae76-0f8811184d2e)
|

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
2026-11-09 16:52:02 -08:00

239 lines
8.1 KiB
Dart

part of 'message_content_test.dart';
void carouselPreviewTests() {
testWidgets(
'iOS prepares five thumbnails before scrolling with two preload requests',
(tester) async {
final started = <String>[];
final responses = <String, Completer<http.Response>>{};
final urls = List.generate(
10,
(i) => 'https://example.com/preload-$i.png',
);
final messenger = tester.binding.defaultBinaryMessenger;
const connectivity = MethodChannel(
'dev.fluttercommunity.plus/connectivity_status',
);
messenger.setMockMethodCallHandler(connectivity, (_) async => null);
addTearDown(() => messenger.setMockMethodCallHandler(connectivity, null));
final channels = <MethodChannel>[];
messenger.setMockMethodCallHandler(SystemChannels.platform_views, (
call,
) async {
if (call.method == 'create') {
final id = (call.arguments as Map)['id'];
final channel = MethodChannel('buzz/ios_media_carousel/$id');
channels.add(channel);
messenger.setMockMethodCallHandler(channel, (_) async => null);
}
return null;
});
final aborted = <String>{};
final client = MockClient.streaming((request, _) async {
final url = request.url.toString();
started.add(url);
final response = responses[url] = Completer<http.Response>();
if (request case http.Abortable(:final abortTrigger?)) {
unawaited(
abortTrigger.then((_) {
// The provider also fires the trigger after a finished load.
if (response.isCompleted) return;
aborted.add(url);
response.completeError(http.RequestAbortedException(request.url));
}),
);
}
final body = await response.future;
return http.StreamedResponse(
Stream.value(body.bodyBytes),
body.statusCode,
);
});
Future<void> waitForCount(int count) async {
for (
var attempt = 0;
attempt < 100 && started.length < count;
attempt++
) {
await tester.pump();
await tester.runAsync(
() => Future<void>.delayed(const Duration(milliseconds: 10)),
);
}
expect(started.length, count);
}
final png = base64Decode(
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aL1sAAAAASUVORK5CYII=',
);
void release(String url) {
final response = responses[url]!;
if (!response.isCompleted) {
response.complete(http.Response.bytes(png, 200));
}
}
addTearDown(() async {
for (final response in responses.values) {
if (!response.isCompleted) response.complete(http.Response('', 404));
}
messenger.setMockMethodCallHandler(SystemChannels.platform_views, null);
for (final channel in channels) {
messenger.setMockMethodCallHandler(channel, null);
}
client.close();
});
await tester.pumpWidget(
_testable(
MessageContent(
content: urls.map((url) => '![image]($url)').join('\n'),
),
overrides: [
mediaGetAuthServiceProvider.overrideWithValue(
MediaGetAuthService(baseUrl: 'https://example.com', nsec: null),
),
mediaHttpClientProvider.overrideWithValue(client),
],
),
);
await tester.pump();
{
await waitForCount(2);
expect(started, hasLength(2));
for (var i = 0; i < 3; i++) {
release(started[i]);
await waitForCount(i + 3);
expect(started, hasLength(i + 3));
}
release(started[3]);
release(started[4]);
}
await tester.pumpAndSettle();
expect(started.toSet(), urls.take(5).toSet());
Future<void> page(int index) async {
await messenger.handlePlatformMessage(
channels.single.name,
channels.single.codec.encodeMethodCall(MethodCall('page', index)),
(_) {},
);
await tester.pump();
await tester.pump();
}
// Jumping to the end prefetches around the new page.
await page(9);
await waitForCount(7);
expect(started.skip(5), [urls[9], urls[8]]);
Future<void> native(String method, Object argument) async {
await tester.runAsync(
() => messenger.handlePlatformMessage(
channels.single.name,
channels.single.codec.encodeMethodCall(
MethodCall(method, argument),
),
(_) {},
),
);
await tester.pump();
}
// A native cell that cancels and comes back while the prefetch is still
// loading joins that download instead of starting another.
await native('subscribeImage', {'id': 'a', 'index': 9});
await native('cancelImage', 'a');
await native('subscribeImage', {'id': 'b', 'index': 9});
for (var attempt = 0; attempt < 10; attempt++) {
await tester.pump();
await tester.runAsync(
() => Future<void>.delayed(const Duration(milliseconds: 10)),
);
}
expect(started, hasLength(7));
expect(aborted, isEmpty);
await native('cancelImage', 'b');
// Leaving before they finish abandons both downloads and frees the
// workers for the new window.
await page(0);
for (var attempt = 0; attempt < 100 && aborted.length < 2; attempt++) {
await tester.pump();
await tester.runAsync(
() => Future<void>.delayed(const Duration(milliseconds: 10)),
);
}
expect(aborted, {urls[9], urls[8]});
await waitForCount(9);
expect(started.skip(7), [urls[0], urls[1]]);
await tester.pumpWidget(const SizedBox());
expect(tester.takeException(), isNull);
},
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
);
testWidgets('outgoing gallery starts at the right and mirrors its spacing', (
tester,
) async {
final messenger = tester.binding.defaultBinaryMessenger;
final channels = <MethodChannel>[];
final configs = <Map<Object?, Object?>>[];
messenger.setMockMethodCallHandler(SystemChannels.platform_views, (
call,
) async {
if (call.method == 'create') {
final id = (call.arguments as Map)['id'];
final channel = MethodChannel('buzz/ios_media_carousel/$id');
channels.add(channel);
messenger.setMockMethodCallHandler(channel, (call) async {
if (call.method == 'configure') {
configs.add(Map<Object?, Object?>.from(call.arguments as Map));
}
return null;
});
}
return null;
});
addTearDown(() {
messenger.setMockMethodCallHandler(SystemChannels.platform_views, null);
for (final channel in channels) {
messenger.setMockMethodCallHandler(channel, null);
}
});
final counts = <Rect>[];
final widths = <double>[];
for (final own in [false, true]) {
await tester.pumpWidget(
_testable(
Padding(
padding: const EdgeInsets.symmetric(horizontal: 50),
child: MessageContent(
key: ValueKey(own),
ownMessage: own,
bubble: false,
mediaCarouselTrailingOverflow: Grid.gutter,
content:
'![one](https://example.com/mirror-one.png)\n![two](https://example.com/mirror-two.png)',
),
),
),
);
await tester.pumpAndSettle();
counts.add(
tester.getRect(
find.byKey(const ValueKey('message-media-carousel-count')),
),
);
widths.add(
tester
.getSize(find.byKey(const ValueKey('message-media-carousel')))
.width,
);
expect(configs.last['rtl'], own);
}
expect(widths[0], widths[1]);
expect(counts[0].left, closeTo(800 - counts[1].right, 0.1));
await tester.pumpWidget(const SizedBox());
expect(tester.takeException(), isNull);
}, variant: TargetPlatformVariant.only(TargetPlatform.iOS));
}