Files
buzz/mobile/lib/features/channels/message_gallery.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

79 lines
2.3 KiB
Dart

import 'package:flutter/foundation.dart';
import 'message_media.dart';
import 'message_content/link_normalizer.dart';
import 'message_content/markdown_escapes.dart';
/// Image metadata shared by carousel rendering and loading projection.
@immutable
class MessageGalleryItem {
final String url;
final String semanticLabel;
final double? aspectRatio;
/// Declared media type, used to keep potentially animated images in Flutter.
final String? mimeType;
const MessageGalleryItem({
required this.url,
required this.semanticLabel,
required this.aspectRatio,
this.mimeType,
});
}
/// A trailing run of image embeds and its preceding message text.
@immutable
class TrailingImageGallery {
final String content;
final List<MessageGalleryItem> items;
const TrailingImageGallery({required this.content, required this.items});
}
/// Groups trailing image lines using the production carousel policy.
TrailingImageGallery? extractTrailingImageGallery(
String content,
Map<String, ImetaEntry> imetaByUrl,
) {
final lines = content.split('\n');
var cursor = lines.length - 1;
while (cursor >= 0 && lines[cursor].trim().isEmpty) {
cursor -= 1;
}
final items = <MessageGalleryItem>[];
final imagePattern = RegExp(r'^!\[([^\]]*)\]\((https?://[^)\s]+)\)$');
while (cursor >= 0) {
final match = imagePattern.firstMatch(lines[cursor].trim());
if (match == null) break;
// CommonMark unescapes link destinations, as it does labels below.
final url = unshieldMarkdownEscapes(shieldMarkdownEscapes(match.group(2)!));
final imeta = imetaByUrl[url];
final mediaKind = classifyMediaUrl(url, imeta: imeta);
if (mediaKind != MessageMediaKind.image) {
break;
}
final markdownLabel = decodeMarkdownLabelSyntax(
unshieldMarkdownEscapes(shieldMarkdownEscapes(match.group(1)!)),
).trim();
items.add(
MessageGalleryItem(
url: url,
semanticLabel:
imeta?.alt ??
(markdownLabel.isNotEmpty ? markdownLabel : 'Message image'),
aspectRatio: imeta?.aspectRatio,
mimeType: imeta?.mimeType,
),
);
cursor -= 1;
}
if (items.length < 2) return null;
return TrailingImageGallery(
content: lines.take(cursor + 1).join('\n').trimRight(),
items: items.reversed.toList(),
);
}