mirror of
https://github.com/block/buzz.git
synced 2026-11-24 18:21:59 +00:00
## Summary On unfolded Duo landscape, channel/DM actions and Solo details now open in a UIKit sheet above the app’s native controls, while retaining Buzz’s Flutter tiles, member rows, and grouped cards. Content drags take priority over sheet dragging; the native top bar still supports dismissal. The presentation-only engine starts only when an eligible sheet is presented, without account, camera, audio, or storage plugins. It is destroyed on dismissal; other iPhones pay no second-engine launch cost. The main app retains live permissions and actions, and the native sheet dismisses before opening follow-up screens. Cover-display and portrait postures retain the existing bottom sheet. Pending avatar requests are abandoned on dismissal, including after the display wait expires; the display timeout alone lets the download finish and cache. Confirmed lifecycle actions retire the invisible owner route before waiting for the relay. ### Related issue Follow-up to #8568. No duplicate sheet PR found. ### Testing - `just mobile-install mobile-check mobile-test`: clean analysis; 4,900 Flutter tests passed (71 skipped), plus gateway/package checks. - Mobile file-size and diff checks passed. - Earlier signed device preview built, installed, and launched; owner confirmed its scrolling. The later lazy-start and lifecycle fixes have not been rechecked on the device. - Unsigned iOS release build passed for `4ed94c6eb4` (Xcode 116.7s). - Journeys cover bridge permissions, copy/close callbacks, the content renderer, full profile-to-DM return, and reopening the list during a held archive. Avatar tests cover immediate cancellation, display timeout followed by cancellation, and timeout followed by completion and cache reuse; regression probes fail with the fixes disabled. UIKit drag handling still lacks automated interaction coverage. ### Snapshots Actual Flutter sheet contents at 540×580 points with sample data. These show the content layout; they do not show UIKit’s surrounding sheet or its animation. | Surface | Light | Dark | | --- | --- | --- | | Solo details |  |  | | Channel actions |  |  | --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
208 lines
5.9 KiB
Dart
208 lines
5.9 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
import 'dart:ui' as ui;
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/foundation.dart' show ValueListenable;
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import '../animated_avatar.dart';
|
|
import '../emoji/emoji_avatar.dart';
|
|
import '../emoji/native_emoji_glyph.dart';
|
|
import '../relay/relay.dart';
|
|
import 'avatar_shape.dart';
|
|
|
|
part 'avatar_image_native.dart';
|
|
|
|
/// An avatar that supports both remote URLs and inline image data.
|
|
///
|
|
/// Flutter's [NetworkImage] only loads network URLs, while desktop browsers also
|
|
/// accept `data:image/*` sources directly. Agent emoji avatars are inline SVGs,
|
|
/// so mobile must decode those before rendering them.
|
|
class AvatarImage extends StatelessWidget {
|
|
final String? imageUrl;
|
|
final double radius;
|
|
final Color? backgroundColor;
|
|
final Widget fallback;
|
|
final bool isAgent;
|
|
|
|
const AvatarImage({
|
|
super.key,
|
|
required this.imageUrl,
|
|
required this.radius,
|
|
required this.fallback,
|
|
this.backgroundColor,
|
|
this.isAgent = false,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final animatedAvatar = parseAnimatedAvatarUrl(imageUrl);
|
|
final color = animatedAvatar == null ? backgroundColor : Colors.transparent;
|
|
final content = SizedBox.square(
|
|
dimension: radius * 2,
|
|
child: AvatarImageContent(
|
|
imageUrl: animatedAvatar?.posterUrl ?? imageUrl,
|
|
fallback: fallback,
|
|
preferThumbnail: true,
|
|
),
|
|
);
|
|
final clipped = AvatarClip(
|
|
isAgent: isAgent,
|
|
child: isAgent && usesInsetAgentArtwork(imageUrl)
|
|
? Transform.scale(scale: animatedAvatarArtworkScale, child: content)
|
|
: content,
|
|
);
|
|
// CircleAvatar keeps its theme default when people have no background.
|
|
if (!isAgent) {
|
|
return CircleAvatar(
|
|
radius: radius,
|
|
backgroundColor: color,
|
|
child: clipped,
|
|
);
|
|
}
|
|
return DecoratedBox(
|
|
decoration: ShapeDecoration(
|
|
color: color,
|
|
shape: avatarShape(isAgent: true),
|
|
),
|
|
child: clipped,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Image content for avatar surfaces whose shape is supplied by their parent.
|
|
class AvatarImageContent extends ConsumerStatefulWidget {
|
|
final String? imageUrl;
|
|
final Widget fallback;
|
|
final BoxFit fit;
|
|
|
|
/// Load the relay's small JPEG thumbnail for a small relay-hosted image
|
|
/// (see [MediaImage.preferThumbnail]). People and agent avatars set this,
|
|
/// matching desktop. Leave it off for images that may be transparent: the
|
|
/// thumbnail renders transparent areas black.
|
|
final bool preferThumbnail;
|
|
|
|
const AvatarImageContent({
|
|
super.key,
|
|
required this.imageUrl,
|
|
required this.fallback,
|
|
this.fit = BoxFit.cover,
|
|
this.preferThumbnail = false,
|
|
});
|
|
|
|
@override
|
|
ConsumerState<AvatarImageContent> createState() => _AvatarImageContentState();
|
|
}
|
|
|
|
class _AvatarImageContentState extends ConsumerState<AvatarImageContent> {
|
|
late _AvatarSource? _source = _AvatarSource.parse(widget.imageUrl);
|
|
|
|
@override
|
|
void didUpdateWidget(AvatarImageContent oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (widget.imageUrl != oldWidget.imageUrl) {
|
|
_source = _AvatarSource.parse(widget.imageUrl);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final centeredFallback = Center(child: widget.fallback);
|
|
|
|
return switch (_source) {
|
|
_EmojiAvatarSource(:final emoji, :final color) => ColoredBox(
|
|
color: color,
|
|
child: LayoutBuilder(
|
|
builder: (_, constraints) {
|
|
final glyphSize = constraints.biggest.shortestSide * 258 / 512;
|
|
return Center(
|
|
child: NativeEmojiGlyph(
|
|
emoji: emoji,
|
|
size: glyphSize,
|
|
opticalBoxSize: glyphSize,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
_SvgAvatarSource(:final svg) => SvgPicture.string(
|
|
svg,
|
|
fit: widget.fit,
|
|
placeholderBuilder: (_) => centeredFallback,
|
|
errorBuilder: (_, _, _) => centeredFallback,
|
|
),
|
|
_RasterDataAvatarSource(:final bytes) => _rasterImage(
|
|
bytes: bytes,
|
|
fallback: centeredFallback,
|
|
),
|
|
_NetworkAvatarSource(:final url) => MediaImage(
|
|
url: url,
|
|
fit: widget.fit,
|
|
preferThumbnail: widget.preferThumbnail,
|
|
errorBuilder: (_, _, _) => centeredFallback,
|
|
),
|
|
null => centeredFallback,
|
|
};
|
|
}
|
|
|
|
Widget _rasterImage({required Uint8List bytes, required Widget fallback}) {
|
|
return Image.memory(
|
|
bytes,
|
|
fit: widget.fit,
|
|
errorBuilder: (_, _, _) => fallback,
|
|
);
|
|
}
|
|
}
|
|
|
|
sealed class _AvatarSource {
|
|
const _AvatarSource();
|
|
|
|
static _AvatarSource? parse(String? value) {
|
|
final url = value?.trim();
|
|
if (url == null || url.isEmpty) return null;
|
|
if (!url.startsWith('data:image/')) return _NetworkAvatarSource(url);
|
|
|
|
try {
|
|
final data = UriData.parse(url);
|
|
if (data.mimeType == 'image/svg+xml') {
|
|
final Uint8List bytes = data.contentAsBytes();
|
|
final svg = utf8.decode(bytes);
|
|
final emojiAvatar = parseEmojiAvatarSvg(svg);
|
|
return emojiAvatar == null
|
|
? _SvgAvatarSource(svg)
|
|
: _EmojiAvatarSource(
|
|
emojiAvatar.emoji,
|
|
Color(emojiAvatar.colorValue),
|
|
);
|
|
}
|
|
return _RasterDataAvatarSource(data.contentAsBytes());
|
|
} on FormatException {
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
class _EmojiAvatarSource extends _AvatarSource {
|
|
final String emoji;
|
|
final Color color;
|
|
const _EmojiAvatarSource(this.emoji, this.color);
|
|
}
|
|
|
|
class _SvgAvatarSource extends _AvatarSource {
|
|
final String svg;
|
|
const _SvgAvatarSource(this.svg);
|
|
}
|
|
|
|
class _RasterDataAvatarSource extends _AvatarSource {
|
|
final Uint8List bytes;
|
|
const _RasterDataAvatarSource(this.bytes);
|
|
}
|
|
|
|
class _NetworkAvatarSource extends _AvatarSource {
|
|
final String url;
|
|
const _NetworkAvatarSource(this.url);
|
|
}
|