Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Refine gallery filmstrip previews and scrolling

ashil-pilot9071f56c0544
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_physics.dart b/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_physics.dart
index d10dbc1cc2..7681d8d292 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_physics.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_viewer_filmstrip_physics.dart
@@ -1,14 +1,15 @@
import "package:flutter/widgets.dart";
-/// The capped, long-coasting scroll behavior used by the file-viewer filmstrip.
+/// The capped, Android-style scroll behavior used by the file-viewer filmstrip.
const ScrollPhysics fileViewerFilmstripPhysics = _FilmstripScrollPhysics();
const _maxFlingVelocity = 800.0;
-// Evaluating a slightly faster platform simulation on a slower clock keeps the
+// Evaluating a slightly faster clamping simulation on a slower clock keeps the
// launch velocity unchanged while extending its distance and settling time.
const _ballisticTimeScale = 0.7;
-class _FilmstripScrollPhysics extends ScrollPhysics {
+// Use the same deceleration on every platform, including iOS.
+class _FilmstripScrollPhysics extends ClampingScrollPhysics {
const _FilmstripScrollPhysics({super.parent});
@override
@@ -20,8 +21,7 @@ class _FilmstripScrollPhysics extends ScrollPhysics {
@override
double carriedMomentum(double existingVelocity) {
- // Preserve repeated-fling acceleration on clamping platforms as well as
- // platforms whose parent physics already bounce.
+ // Preserve repeated-fling acceleration with a cap on the added momentum.
final momentum = const BouncingScrollPhysics().carriedMomentum(
existingVelocity,
);
diff --git a/mobile/apps/photos/lib/ui/viewer/file/gallery_file_viewer_filmstrip.dart b/mobile/apps/photos/lib/ui/viewer/file/gallery_file_viewer_filmstrip.dart
index b3fb3e625b..d556a25afb 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/gallery_file_viewer_filmstrip.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/gallery_file_viewer_filmstrip.dart
@@ -1,10 +1,13 @@
+import "package:ente_components/ente_components.dart" show fillDarkDark;
import "package:ente_strings/ente_strings.dart";
import "package:flutter/foundation.dart";
import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
import "package:photos/core/constants.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/file/file_type.dart";
import "package:photos/service_locator.dart";
+import "package:photos/theme/colors.dart" show strokeFaintDark;
import "package:photos/ui/viewer/file/file_viewer_filmstrip.dart";
import "package:photos/ui/viewer/file/file_viewer_filmstrip_event.dart";
import "package:photos/ui/viewer/file/file_viewer_filmstrip_preview_layer.dart";
@@ -12,10 +15,9 @@ import "package:photos/ui/viewer/file/thumbnail_widget.dart";
/// Spacing contributed by the filmstrip to the gallery viewer's chrome.
abstract final class GalleryFileViewerFilmstripLayout {
- static const bottomControlsGap = 6.0;
static const upperContentGap = 6.0;
static const additionalBottomInset =
- FileViewerFilmstripLayout.height + bottomControlsGap + upperContentGap;
+ FileViewerFilmstripLayout.height + upperContentGap;
}
/// Keeps the filmstrip limited to internal users while it is being evaluated.
@@ -56,9 +58,30 @@ class GalleryFileViewerFilmstripPreviewLayer extends StatelessWidget {
if (index < 0 || index >= files.length) {
return const SizedBox.shrink();
}
- return _GalleryFilmstripThumbnail(
- file: files[index],
- fit: BoxFit.contain,
+ final file = files[index];
+ return Stack(
+ fit: StackFit.expand,
+ children: [
+ _GalleryFilmstripThumbnail(file: file, fit: BoxFit.contain),
+ if (file.fileType == FileType.video)
+ Center(
+ child: Container(
+ width: 54,
+ height: 54,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(
+ color: Colors.black.withValues(alpha: 0.3),
+ shape: BoxShape.circle,
+ border: Border.all(color: strokeFaintDark, width: 1),
+ ),
+ child: const HugeIcon(
+ icon: HugeIcons.strokeRoundedPlay,
+ size: 32,
+ color: Colors.white,
+ ),
+ ),
+ ),
+ ],
);
},
);
@@ -92,10 +115,7 @@ class GalleryFileViewerFilmstripOverlay extends StatelessWidget {
return Positioned(
left: safePadding.left,
right: safePadding.right,
- bottom:
- safePadding.bottom +
- bottomControlsHeight +
- GalleryFileViewerFilmstripLayout.bottomControlsGap,
+ bottom: safePadding.bottom + bottomControlsHeight,
height: FileViewerFilmstripLayout.height,
child: ValueListenableBuilder<bool>(
valueListenable: enableFullScreenNotifier,
@@ -153,6 +173,7 @@ class _GalleryFilmstripThumbnail extends StatelessWidget {
file,
key: ObjectKey(file),
rawThumbnail: true,
+ placeholderColor: fillDarkDark,
diskLoadDeferDuration: galleryThumbnailDiskLoadDeferDuration,
serverLoadDeferDuration: galleryThumbnailServerLoadDeferDuration,
shouldShowSyncStatus: false,
diff --git a/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_test.dart b/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_test.dart
index f4be55ab7f..d01b8a11b8 100644
--- a/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/file/file_viewer_filmstrip_test.dart
@@ -337,6 +337,40 @@ void main() {
);
});
+ testWidgets("iOS and Android filmstrips have the same fling deceleration", (
+ tester,
+ ) async {
+ final simulations = <TargetPlatform, List<Simulation>>{};
+ for (final platform in [TargetPlatform.android, TargetPlatform.iOS]) {
+ await tester.pumpWidget(
+ _TestApp(
+ platform: platform,
+ child: const _FilmstripHarness(itemCount: 100, selectedIndex: 50),
+ ),
+ );
+ await tester.pumpAndSettle();
+
+ final position = _filmstripPosition(tester);
+ simulations[platform] = [
+ for (final velocity in [-500.0, 500.0, 5000.0])
+ position.physics.createBallisticSimulation(position, velocity)!,
+ ];
+ }
+
+ final android = simulations[TargetPlatform.android]!;
+ final ios = simulations[TargetPlatform.iOS]!;
+ for (var index = 0; index < android.length; index++) {
+ for (final time in [0.0, 0.1, 0.25, 0.5, 1.0]) {
+ expect(ios[index].x(time), closeTo(android[index].x(time), 0.01));
+ expect(ios[index].dx(time), closeTo(android[index].dx(time), 0.01));
+ }
+ expect(
+ _settlingTime(ios[index], start: 0),
+ closeTo(_settlingTime(android[index], start: 0), 0.01),
+ );
+ }
+ });
+
testWidgets("a second fling keeps moving while the strip is coasting", (
tester,
) async {
@@ -619,12 +653,14 @@ void _expectNearestToStripCenter(WidgetTester tester, int index) {
class _TestApp extends StatelessWidget {
final Widget child;
+ final TargetPlatform? platform;
- const _TestApp({required this.child});
+ const _TestApp({required this.child, this.platform});
@override
Widget build(BuildContext context) {
return MaterialApp(
+ theme: ThemeData(platform: platform),
home: Scaffold(
backgroundColor: Colors.black,
body: Center(child: SizedBox(width: 380, child: child)),