Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Expand Memory Lane slider touch area

ashil-pilotc7dd48f9151b
diff --git a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page_v2.dart b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page_v2.dart
index 184a6d6e77..43761d11b7 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page_v2.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page_v2.dart
@@ -26,6 +26,7 @@ import "package:photos/ui/home/memories/memory_progress_indicator.dart";
import "package:photos/ui/home/memories/memory_viewer_constants.dart";
import "package:photos/ui/viewer/gallery/jump_to_date_gallery.dart";
import "package:photos/ui/viewer/people/memory_lane_caption.dart";
+import "package:photos/ui/viewer/people/memory_lane_scrubber.dart";
import "package:photos/utils/dialog_util.dart";
import "package:photos/utils/face/face_thumbnail_cache.dart";
import "package:photos/utils/share_util.dart";
@@ -253,12 +254,7 @@ class _MemoryLanePageV2State extends State<MemoryLanePageV2> {
});
}
- void _seekFromPosition(double x, double width) {
- if (width <= 0) return;
- final index = (x / width * _entries.length).floor().clamp(
- 0,
- _entries.length - 1,
- );
+ void _seekToIndex(int index) {
setState(() {
_playbackTimer?.cancel();
_playbackToken = null;
@@ -773,115 +769,13 @@ class _MemoryLanePageV2State extends State<MemoryLanePageV2> {
SizedBox(height: screenSize.height * 0.01),
],
if (_entries.isNotEmpty)
- ConstrainedBox(
- constraints: const BoxConstraints(minHeight: 32),
- child: Padding(
- padding: EdgeInsets.symmetric(
- horizontal: screenSize.width * 0.16,
- ),
- child: Row(
- mainAxisAlignment: .center,
- children: [
- Expanded(
- child: LayoutBuilder(
- builder: (context, constraints) {
- const maxDotSize = 15.0;
- const dotSpacing = 5.0;
- final dotCount =
- ((constraints.maxWidth +
- dotSpacing) /
- (maxDotSize + dotSpacing))
- .floor()
- .clamp(1, _entries.length);
- final activeDot =
- i * dotCount ~/ _entries.length;
- return GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTapUp: (details) {
- if (constraints.maxWidth <= 0) {
- return;
- }
- final index =
- (details.localPosition.dx /
- constraints.maxWidth *
- _entries.length)
- .floor()
- .clamp(
- 0,
- _entries.length - 1,
- );
- unawaited(
- _play(
- index,
- fastTransition: true,
- ),
- );
- },
- onHorizontalDragStart: (details) {
- _seekFromPosition(
- details.localPosition.dx,
- constraints.maxWidth,
- );
- },
- onHorizontalDragUpdate: (details) =>
- _seekFromPosition(
- details.localPosition.dx,
- constraints.maxWidth,
- ),
- onHorizontalDragEnd: (_) =>
- unawaited(_play(i)),
- onHorizontalDragCancel: () =>
- unawaited(_play(i)),
- child: Row(
- spacing: dotSpacing,
- children: List.generate(dotCount, (
- index,
- ) {
- final distance =
- (index - activeDot).abs();
- final double size =
- switch (distance) {
- 0 => maxDotSize,
- 1 => 10,
- 2 => 7.5,
- _ => 5,
- };
- return Expanded(
- child: SizedBox(
- height: 40,
- child: Center(
- child: AnimatedContainer(
- duration:
- const Duration(
- milliseconds: 200,
- ),
- width: size,
- height: size,
- decoration: BoxDecoration(
- shape:
- BoxShape.circle,
- color: Colors.white
- .withValues(
- alpha:
- distance ==
- 0
- ? 1
- : 0.5,
- ),
- ),
- ),
- ),
- ),
- );
- }),
- ),
- );
- },
- ),
- ),
- ],
- ),
- ),
+ MemoryLaneScrubber(
+ totalEntries: _entries.length,
+ currentIndex: i,
+ onTap: (index) =>
+ unawaited(_play(index, fastTransition: true)),
+ onSeek: _seekToIndex,
+ onSeekEnd: () => unawaited(_play(i)),
),
SizedBox(height: screenSize.height * 0.055),
],
diff --git a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_scrubber.dart b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_scrubber.dart
new file mode 100644
index 0000000000..ec637956f8
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_scrubber.dart
@@ -0,0 +1,86 @@
+import "package:flutter/material.dart";
+
+class MemoryLaneScrubber extends StatelessWidget {
+ const MemoryLaneScrubber({
+ required this.totalEntries,
+ required this.currentIndex,
+ required this.onTap,
+ required this.onSeek,
+ required this.onSeekEnd,
+ super.key,
+ }) : assert(totalEntries > 0);
+
+ final int totalEntries;
+ final int currentIndex;
+ final ValueChanged<int> onTap;
+ final ValueChanged<int> onSeek;
+ final VoidCallback onSeekEnd;
+
+ @override
+ Widget build(BuildContext context) {
+ return LayoutBuilder(
+ builder: (context, constraints) {
+ final horizontalPadding = MediaQuery.sizeOf(context).width * 0.16;
+ final trackWidth = constraints.maxWidth - horizontalPadding * 2;
+ if (trackWidth <= 0) return const SizedBox(height: 40);
+
+ const maxDotSize = 15.0;
+ const dotSpacing = 5.0;
+ final dotCount = ((trackWidth + dotSpacing) / (maxDotSize + dotSpacing))
+ .floor()
+ .clamp(1, totalEntries);
+ final activeDot = currentIndex * dotCount ~/ totalEntries;
+
+ int indexAt(double x) =>
+ ((x - horizontalPadding) / trackWidth * totalEntries).floor().clamp(
+ 0,
+ totalEntries - 1,
+ );
+
+ return GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTapUp: (details) => onTap(indexAt(details.localPosition.dx)),
+ onHorizontalDragStart: (details) =>
+ onSeek(indexAt(details.localPosition.dx)),
+ onHorizontalDragUpdate: (details) =>
+ onSeek(indexAt(details.localPosition.dx)),
+ onHorizontalDragEnd: (_) => onSeekEnd(),
+ onHorizontalDragCancel: onSeekEnd,
+ child: Padding(
+ padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
+ child: Row(
+ spacing: dotSpacing,
+ children: List.generate(dotCount, (index) {
+ final distance = (index - activeDot).abs();
+ final double size = switch (distance) {
+ 0 => maxDotSize,
+ 1 => 10,
+ 2 => 7.5,
+ _ => 5,
+ };
+ return Expanded(
+ child: SizedBox(
+ height: 40,
+ child: Center(
+ child: AnimatedContainer(
+ duration: const Duration(milliseconds: 200),
+ width: size,
+ height: size,
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ color: Colors.white.withValues(
+ alpha: distance == 0 ? 1 : 0.5,
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }),
+ ),
+ ),
+ );
+ },
+ );
+ }
+}
diff --git a/mobile/apps/photos/test/ui/viewer/people/memory_lane_scrubber_test.dart b/mobile/apps/photos/test/ui/viewer/people/memory_lane_scrubber_test.dart
new file mode 100644
index 0000000000..f3e7b7004b
--- /dev/null
+++ b/mobile/apps/photos/test/ui/viewer/people/memory_lane_scrubber_test.dart
@@ -0,0 +1,98 @@
+import "package:flutter/material.dart";
+import "package:flutter_test/flutter_test.dart";
+import "package:photos/ui/viewer/people/memory_lane_scrubber.dart";
+
+void main() {
+ testWidgets("keeps endpoint taps and drags within the current memory", (
+ tester,
+ ) async {
+ for (final fromLeft in [true, false]) {
+ var memoryIndex = 1;
+ int? photoIndex;
+ var seekEnds = 0;
+ await _pumpMemoryPager(
+ tester,
+ onPageChanged: (index) => memoryIndex = index,
+ onTap: (index) => photoIndex = index,
+ onSeek: (index) => photoIndex = index,
+ onSeekEnd: () => seekEnds++,
+ );
+ final track = tester.getRect(find.byType(Row));
+ final start = Offset(
+ fromLeft ? track.left - 12 : track.right + 12,
+ track.center.dy,
+ );
+
+ await tester.dragFrom(start, Offset(fromLeft ? 340 : -340, 0));
+ await tester.pumpAndSettle();
+ expect(memoryIndex, 1);
+ expect(photoIndex, fromLeft ? 19 : 0);
+ expect(seekEnds, 1);
+
+ await tester.tapAt(start);
+ await tester.pumpAndSettle();
+ expect(photoIndex, fromLeft ? 0 : 19);
+
+ await tester.tapAt(track.center);
+ await tester.pumpAndSettle();
+ expect(photoIndex, 10);
+ await tester.pumpWidget(const SizedBox.shrink());
+ }
+ });
+
+ testWidgets("allows memory-card swipes outside the scrubber", (tester) async {
+ var memoryIndex = 1;
+ await _pumpMemoryPager(
+ tester,
+ onPageChanged: (index) => memoryIndex = index,
+ onTap: (_) => fail("A card swipe must not seek a photo"),
+ onSeek: (_) => fail("A card swipe must not seek a photo"),
+ onSeekEnd: () => fail("A card swipe must not end a seek"),
+ );
+
+ final pager = tester.getRect(find.byType(PageView));
+ await tester.dragFrom(pager.center, const Offset(-300, 0));
+ await tester.pumpAndSettle();
+ expect(memoryIndex, 2);
+ });
+}
+
+Future<void> _pumpMemoryPager(
+ WidgetTester tester, {
+ required ValueChanged<int> onPageChanged,
+ required ValueChanged<int> onTap,
+ required ValueChanged<int> onSeek,
+ required VoidCallback onSeekEnd,
+}) async {
+ final controller = PageController(initialPage: 1);
+ addTearDown(controller.dispose);
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Center(
+ child: SizedBox(
+ width: 400,
+ height: 400,
+ child: PageView(
+ controller: controller,
+ physics: const BouncingScrollPhysics(),
+ onPageChanged: onPageChanged,
+ children: [
+ const SizedBox.expand(),
+ Align(
+ alignment: Alignment.bottomCenter,
+ child: MemoryLaneScrubber(
+ totalEntries: 20,
+ currentIndex: 10,
+ onTap: onTap,
+ onSeek: onSeek,
+ onSeekEnd: onSeekEnd,
+ ),
+ ),
+ const SizedBox.expand(),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+}