From 354c08921b45af8259396f289e22324556b71f3f Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 30 Jun 2025 15:35:30 +0530 Subject: [PATCH 1/5] Remove unnecessary AnimatedBuilder --- .../ui/home/memories/memory_cover_widget.dart | 308 +++++++++--------- 1 file changed, 155 insertions(+), 153 deletions(-) diff --git a/mobile/lib/ui/home/memories/memory_cover_widget.dart b/mobile/lib/ui/home/memories/memory_cover_widget.dart index 6850d332a6..ddf3359903 100644 --- a/mobile/lib/ui/home/memories/memory_cover_widget.dart +++ b/mobile/lib/ui/home/memories/memory_cover_widget.dart @@ -61,160 +61,162 @@ class _MemoryCoverWidgetState extends State { final brightness = SchedulerBinding.instance.platformDispatcher.platformBrightness; - return AnimatedBuilder( - animation: widget.controller, - builder: (context, child) { - return Padding( - padding: const EdgeInsets.symmetric( - horizontal: MemoryCoverWidget.horizontalPadding, - ), - child: GestureDetector( - onTap: () async { - await routeToPage( - context, - forceCustomPageRoute: true, - AllMemoriesPage( - initialPageIndex: widget.currentMemoryIndex, - allMemories: widget.allMemories, - allTitles: widget.allTitle, - ), - ); - setState(() {}); - }, //Adding this row is a workaround for making height of memory cover - //render as [MemoryCoverWidgetNew.height] * scale. Without this, height of rendered memory - //cover will be [MemoryCoverWidgetNew.height]. - child: Row( - children: [ - Container( - height: widget.maxHeight, - width: widget.maxWidth, - decoration: BoxDecoration( - boxShadow: brightness == Brightness.dark - ? [ - const BoxShadow( - color: strokeFainterDark, - spreadRadius: MemoryCoverWidget.outerStrokeWidth, - blurRadius: 0, - ), - ] - : [...shadowFloatFaintestLight], - borderRadius: BorderRadius.circular(5), - ), - child: ClipRRect( - borderRadius: BorderRadius.circular(5), - child: isSeen - ? ColorFiltered( - colorFilter: const ColorFilter.mode( - Color(0xFFBFBFBF), - BlendMode.hue, - ), - child: Stack( - fit: StackFit.expand, - alignment: Alignment.bottomCenter, - children: [ - child!, - Container( - decoration: BoxDecoration( - gradient: LinearGradient( - colors: [ - Colors.black.withOpacity(0.5), - Colors.transparent, - ], - stops: const [0, 1], - begin: Alignment.bottomCenter, - end: Alignment.topCenter, - ), - ), - ), - Positioned( - bottom: 8, - child: SizedBox( - width: widget.maxWidth, - child: Padding( - padding: const EdgeInsets.symmetric( - horizontal: 8.0, - ), - child: Hero( - tag: title, - child: Center( - child: Text( - title, - style: getEnteTextTheme(context) - .miniBold - .copyWith( - color: isSeen - ? textFaintDark - : Colors.white, - ), - textAlign: TextAlign.left, - ), - ), - ), - ), - ), - ), - ], - ), - ) - : Stack( - fit: StackFit.expand, - alignment: Alignment.bottomCenter, - children: [ - child!, - Container( - decoration: BoxDecoration( - gradient: LinearGradient( - colors: [ - Colors.black.withOpacity(0.5), - Colors.transparent, - ], - stops: const [0, 1], - begin: Alignment.bottomCenter, - end: Alignment.topCenter, - ), - ), - ), - Positioned( - bottom: 8, - child: SizedBox( - width: widget.maxWidth, - child: Padding( - padding: const EdgeInsets.symmetric( - horizontal: 8.0, - ), - child: Hero( - tag: title, - child: Center( - child: Text( - title, - style: getEnteTextTheme(context) - .miniBold - .copyWith( - color: Colors.white, - ), - textAlign: TextAlign.left, - ), - ), - ), - ), - ), - ), - ], - ), - ), - ), - ], + return Padding( + padding: const EdgeInsets.symmetric( + horizontal: MemoryCoverWidget.horizontalPadding, + ), + child: GestureDetector( + onTap: () async { + await routeToPage( + context, + forceCustomPageRoute: true, + AllMemoriesPage( + initialPageIndex: widget.currentMemoryIndex, + allMemories: widget.allMemories, + allTitles: widget.allTitle, ), - ), - ); - }, - child: Hero( - tag: "memories" + memory.file.tag, - child: ThumbnailWidget( - memory.file, - shouldShowArchiveStatus: false, - shouldShowSyncStatus: false, - key: Key("memories" + memory.file.tag), + ); + setState(() {}); + }, //Adding this row is a workaround for making height of memory cover + //render as [MemoryCoverWidgetNew.height] * scale. Without this, height of rendered memory + //cover will be [MemoryCoverWidgetNew.height]. + child: Row( + children: [ + Container( + height: widget.maxHeight, + width: widget.maxWidth, + decoration: BoxDecoration( + boxShadow: brightness == Brightness.dark + ? [ + const BoxShadow( + color: strokeFainterDark, + spreadRadius: MemoryCoverWidget.outerStrokeWidth, + blurRadius: 0, + ), + ] + : [...shadowFloatFaintestLight], + borderRadius: BorderRadius.circular(5), + ), + child: ClipRRect( + borderRadius: BorderRadius.circular(5), + child: isSeen + ? ColorFiltered( + colorFilter: const ColorFilter.mode( + Color(0xFFBFBFBF), + BlendMode.hue, + ), + child: Stack( + fit: StackFit.expand, + alignment: Alignment.bottomCenter, + children: [ + Hero( + tag: "memories" + memory.file.tag, + child: ThumbnailWidget( + memory.file, + shouldShowArchiveStatus: false, + shouldShowSyncStatus: false, + key: Key("memories" + memory.file.tag), + ), + ), + Container( + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [ + Colors.black.withOpacity(0.5), + Colors.transparent, + ], + stops: const [0, 1], + begin: Alignment.bottomCenter, + end: Alignment.topCenter, + ), + ), + ), + Positioned( + bottom: 8, + child: SizedBox( + width: widget.maxWidth, + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 8.0, + ), + child: Hero( + tag: title, + child: Center( + child: Text( + title, + style: getEnteTextTheme(context) + .miniBold + .copyWith( + color: isSeen + ? textFaintDark + : Colors.white, + ), + textAlign: TextAlign.left, + ), + ), + ), + ), + ), + ), + ], + ), + ) + : Stack( + fit: StackFit.expand, + alignment: Alignment.bottomCenter, + children: [ + Hero( + tag: "memories" + memory.file.tag, + child: ThumbnailWidget( + memory.file, + shouldShowArchiveStatus: false, + shouldShowSyncStatus: false, + key: Key("memories" + memory.file.tag), + ), + ), + Container( + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [ + Colors.black.withOpacity(0.5), + Colors.transparent, + ], + stops: const [0, 1], + begin: Alignment.bottomCenter, + end: Alignment.topCenter, + ), + ), + ), + Positioned( + bottom: 8, + child: SizedBox( + width: widget.maxWidth, + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 8.0, + ), + child: Hero( + tag: title, + child: Center( + child: Text( + title, + style: getEnteTextTheme(context) + .miniBold + .copyWith( + color: Colors.white, + ), + textAlign: TextAlign.left, + ), + ), + ), + ), + ), + ), + ], + ), + ), + ), + ], ), ), ); From 489c8069236fcc05f8997d336298c648e9edb31e Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 30 Jun 2025 15:36:38 +0530 Subject: [PATCH 2/5] Add mounted check --- mobile/lib/ui/home/memories/memory_cover_widget.dart | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mobile/lib/ui/home/memories/memory_cover_widget.dart b/mobile/lib/ui/home/memories/memory_cover_widget.dart index ddf3359903..10bbe78d3d 100644 --- a/mobile/lib/ui/home/memories/memory_cover_widget.dart +++ b/mobile/lib/ui/home/memories/memory_cover_widget.dart @@ -224,11 +224,13 @@ class _MemoryCoverWidgetState extends State { void _preloadFirstUnseenMemory() { Future.delayed(const Duration(seconds: 5), () { - if (widget.memories.isEmpty) return; + if (mounted) { + if (widget.memories.isEmpty) return; - final index = _getNextMemoryIndex(); - preloadThumbnail(widget.memories[index].file); - preloadFile(widget.memories[index].file); + final index = _getNextMemoryIndex(); + preloadThumbnail(widget.memories[index].file); + preloadFile(widget.memories[index].file); + } }); } From e27f4544d05771451f25fca044c086e4139eb4f5 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 30 Jun 2025 15:43:37 +0530 Subject: [PATCH 3/5] Remove unnecessary scroll controller --- mobile/lib/ui/home/memories/memories_widget.dart | 5 ----- mobile/lib/ui/home/memories/memory_cover_widget.dart | 2 -- 2 files changed, 7 deletions(-) diff --git a/mobile/lib/ui/home/memories/memories_widget.dart b/mobile/lib/ui/home/memories/memories_widget.dart index 5a47a7c46f..392cbf97cb 100644 --- a/mobile/lib/ui/home/memories/memories_widget.dart +++ b/mobile/lib/ui/home/memories/memories_widget.dart @@ -20,7 +20,6 @@ class MemoriesWidget extends StatefulWidget { } class _MemoriesWidgetState extends State { - late ScrollController _controller; late StreamSubscription _memoriesSettingSubscription; late StreamSubscription _memoriesChangedSubscription; late StreamSubscription _memorySeenSubscription; @@ -48,7 +47,6 @@ class _MemoriesWidgetState extends State { setState(() {}); } }); - _controller = ScrollController(); } @override @@ -66,7 +64,6 @@ class _MemoriesWidgetState extends State { _memoriesSettingSubscription.cancel(); _memoriesChangedSubscription.cancel(); _memorySeenSubscription.cancel(); - _controller.dispose(); super.dispose(); } @@ -127,13 +124,11 @@ class _MemoriesWidgetState extends State { parent: BouncingScrollPhysics(), ), scrollDirection: Axis.horizontal, - controller: _controller, itemCount: collatedMemories.length, itemBuilder: (context, itemIndex) { return MemoryCoverWidget( memories: collatedMemories[itemIndex].$1, allMemories: collatedMemories.map((e) => e.$1).toList(), - controller: _controller, maxHeight: _maxHeight, maxWidth: _maxWidth, title: collatedMemories[itemIndex].$2, diff --git a/mobile/lib/ui/home/memories/memory_cover_widget.dart b/mobile/lib/ui/home/memories/memory_cover_widget.dart index 10bbe78d3d..cfa77bbdda 100644 --- a/mobile/lib/ui/home/memories/memory_cover_widget.dart +++ b/mobile/lib/ui/home/memories/memory_cover_widget.dart @@ -12,7 +12,6 @@ import "package:photos/utils/navigation_util.dart"; class MemoryCoverWidget extends StatefulWidget { final List memories; final List> allMemories; - final ScrollController controller; final double maxHeight; final double maxWidth; static const outerStrokeWidth = 1.0; @@ -25,7 +24,6 @@ class MemoryCoverWidget extends StatefulWidget { const MemoryCoverWidget({ required this.memories, required this.allMemories, - required this.controller, required this.maxHeight, required this.maxWidth, required this.title, From d4e9bdd03500032be8e19f685ad131961d53abe4 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 30 Jun 2025 15:49:52 +0530 Subject: [PATCH 4/5] Use better names --- mobile/lib/ui/home/memories/memories_widget.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mobile/lib/ui/home/memories/memories_widget.dart b/mobile/lib/ui/home/memories/memories_widget.dart index 392cbf97cb..40d0b272f0 100644 --- a/mobile/lib/ui/home/memories/memories_widget.dart +++ b/mobile/lib/ui/home/memories/memories_widget.dart @@ -23,8 +23,8 @@ class _MemoriesWidgetState extends State { late StreamSubscription _memoriesSettingSubscription; late StreamSubscription _memoriesChangedSubscription; late StreamSubscription _memorySeenSubscription; - late double _maxHeight; - late double _maxWidth; + late double _memoryheight; + late double _memoryWidth; @override void initState() { @@ -55,8 +55,8 @@ class _MemoriesWidgetState extends State { final screenWidth = MediaQuery.sizeOf(context).width; //factor will be 2 for most phones in portrait mode final factor = (screenWidth / 220).ceil(); - _maxWidth = screenWidth / (factor * 2); - _maxHeight = _maxWidth / MemoryCoverWidget.aspectRatio; + _memoryWidth = screenWidth / (factor * 2); + _memoryheight = _memoryWidth / MemoryCoverWidget.aspectRatio; } @override @@ -81,7 +81,7 @@ class _MemoriesWidgetState extends State { builder: (context, snapshot) { if (snapshot.hasError || !snapshot.hasData) { return SizedBox( - height: _maxHeight + 12 + 10, + height: _memoryheight + 12 + 10, child: const EnteLoadingWidget(), ); } else { @@ -118,7 +118,7 @@ class _MemoriesWidgetState extends State { collatedMemories.addAll(seenMemories.map((e) => (e.memories, e.title))); return SizedBox( - height: _maxHeight + MemoryCoverWidget.outerStrokeWidth * 2, + height: _memoryheight + MemoryCoverWidget.outerStrokeWidth * 2, child: ListView.builder( physics: const AlwaysScrollableScrollPhysics( parent: BouncingScrollPhysics(), @@ -129,8 +129,8 @@ class _MemoriesWidgetState extends State { return MemoryCoverWidget( memories: collatedMemories[itemIndex].$1, allMemories: collatedMemories.map((e) => e.$1).toList(), - maxHeight: _maxHeight, - maxWidth: _maxWidth, + maxHeight: _memoryheight, + maxWidth: _memoryWidth, title: collatedMemories[itemIndex].$2, allTitle: collatedMemories.map((e) => e.$2).toList(), currentMemoryIndex: itemIndex, From 2608a8c9ab1a20ee8f15385638ee5ff4154ccd28 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 30 Jun 2025 15:53:47 +0530 Subject: [PATCH 5/5] Performance improvement in memories animation --- mobile/lib/ui/home/memories/full_screen_memory.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mobile/lib/ui/home/memories/full_screen_memory.dart b/mobile/lib/ui/home/memories/full_screen_memory.dart index 4cca88027c..a72f33fbb3 100644 --- a/mobile/lib/ui/home/memories/full_screen_memory.dart +++ b/mobile/lib/ui/home/memories/full_screen_memory.dart @@ -741,6 +741,7 @@ class _MemoriesZoomWidgetState extends State : ClipRect( child: AnimatedBuilder( animation: _controller, + child: widget.child, builder: (context, child) { return Transform.scale( scale: _scaleAnimation.value, @@ -749,7 +750,7 @@ class _MemoriesZoomWidgetState extends State _panAnimation.value.dx * 100, _panAnimation.value.dy * 100, ), - child: widget.child, + child: child, ), ); },