mirror of
https://github.com/block/buzz.git
synced 2026-11-03 07:51:22 +00:00
Fill mobile loading views across the screen and use known image, video, voice-note, and file shapes in message placeholders. Freeze each loading cycle’s layout so arriving metadata cannot reshuffle the shimmer just before content appears; preserve cached Home and forum content during reconnects. Validation: mobile analysis and full test suite passed (2,752 passed, 4 skipped), plus 3 unconfigured-push tests and file-size checks. Installed and launched the loading changes on Pixel 10 before the latest main merge. Full `just ci` was stopped during desktop checks due to low disk space. --------- Signed-off-by: kenny lopez <klopez4212@gmail.com>
26 lines
1.0 KiB
Dart
26 lines
1.0 KiB
Dart
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
/// Maximum inline media height shared by images and their placeholders.
|
|
const messageMediaMaxImageHeight = 240.0;
|
|
|
|
/// Width reserved by inline message media at this viewport size.
|
|
double messageMediaMaxWidth(BuildContext context) =>
|
|
math.min(MediaQuery.sizeOf(context).width * 0.72, 320.0);
|
|
|
|
/// Metadata-based image bounds shared by decoded previews and skeletons.
|
|
Size messageImagePreviewSize(BuildContext context, double? aspectRatio) {
|
|
final width = messageMediaMaxWidth(context);
|
|
if (aspectRatio == null || !aspectRatio.isFinite || aspectRatio <= 0) {
|
|
return Size(width, messageMediaMaxImageHeight);
|
|
}
|
|
final ratio = aspectRatio.clamp(0.2, 4.0).toDouble();
|
|
final height = math.min(width / ratio, messageMediaMaxImageHeight);
|
|
return Size(height * ratio, height);
|
|
}
|
|
|
|
/// Inline video ratio shared by decoded previews and skeletons.
|
|
double messageVideoAspectRatio(double? aspectRatio) =>
|
|
(aspectRatio ?? 16 / 9).clamp(0.75, 1.91).toDouble();
|