Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] Stabilize album cover transitions and face filters

r4khul1a1ee58631fa
diff --git a/mobile/apps/photos/lib/ui/collections/album/row_item.dart b/mobile/apps/photos/lib/ui/collections/album/row_item.dart
index 57f29e177b..b6a2da1662 100644
--- a/mobile/apps/photos/lib/ui/collections/album/row_item.dart
+++ b/mobile/apps/photos/lib/ui/collections/album/row_item.dart
@@ -124,6 +124,8 @@ class AlbumRowItemWidget extends StatelessWidget {
);
return Hero(
tag: tagPrefix,
+ createRectTween: (begin, end) =>
+ RectTween(begin: begin, end: end),
transitionOnUserGestures: true,
child: ClipSmoothRect(
radius: SmoothBorderRadius(
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dart
index 516f5f32df..359fdfdab2 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dart
@@ -3,6 +3,7 @@ import "dart:ui" as ui;
import "package:ente_components/ente_components.dart";
import "package:figma_squircle/figma_squircle.dart";
+import "package:flutter/foundation.dart" show ValueListenable;
import "package:flutter/material.dart";
import "package:flutter/rendering.dart";
import "package:flutter/services.dart";
@@ -16,6 +17,7 @@ import "package:photos/services/app_navigation_service.dart";
import "package:photos/ui/viewer/file/file_icons_widget.dart";
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";
+import "package:photos/ui/viewer/gallery/state/inherited_search_filter_data.dart";
class AlbumCoverAppBar extends StatefulWidget {
const AlbumCoverAppBar({
@@ -45,6 +47,24 @@ class AlbumCoverAppBar extends StatefulWidget {
BuildContext context, {
required double collapsedHeight,
required double bottomHeight,
+ }) {
+ final geometry = _resolveCoverGeometry(
+ context,
+ collapsedHeight: collapsedHeight,
+ bottomHeight: bottomHeight,
+ );
+ return HeaderAppBarGeometry(
+ minExtent: geometry.minExtent,
+ maxExtent:
+ geometry.minExtent +
+ math.min(_coverCollapseScrollExtent, geometry.collapseExtent),
+ );
+ }
+
+ static HeaderAppBarGeometry _resolveCoverGeometry(
+ BuildContext context, {
+ required double collapsedHeight,
+ required double bottomHeight,
}) {
final topPadding = MediaQuery.paddingOf(context).top;
return HeaderAppBarGeometry(
@@ -58,6 +78,9 @@ class AlbumCoverAppBar extends StatefulWidget {
}
class _AlbumCoverAppBarState extends State<AlbumCoverAppBar> with RouteAware {
+ final _coverPhotoKey = GlobalKey();
+ final _coverForegroundKey = GlobalKey();
+ final _coverForegroundNotifier = _CoverForegroundNotifier();
late SystemUiOverlayStyle _pinnedOverlayStyle;
bool _isCovered = false;
@@ -89,6 +112,7 @@ class _AlbumCoverAppBarState extends State<AlbumCoverAppBar> with RouteAware {
@override
void dispose() {
AppNavigationService.instance.routeObserver.unsubscribe(this);
+ _coverForegroundNotifier.dispose();
SystemChrome.setSystemUIOverlayStyle(_pinnedOverlayStyle);
WidgetsBinding.instance.scheduleFrame();
super.dispose();
@@ -99,78 +123,142 @@ class _AlbumCoverAppBarState extends State<AlbumCoverAppBar> with RouteAware {
final colors = context.componentColors;
final bottomHeight = widget.bottom?.preferredSize.height ?? 0;
final description = widget.collection.displayDescription;
- final animation = MediaQuery.disableAnimationsOf(context)
- ? kAlwaysCompleteAnimation
- : ModalRoute.of(context)?.animation ?? kAlwaysCompleteAnimation;
-
- return SliverPersistentHeader(
- pinned: true,
- delegate: _AlbumCoverDelegate(
- geometry: AlbumCoverAppBar.resolveGeometry(
- context,
+ final geometry = AlbumCoverAppBar._resolveCoverGeometry(
+ context,
+ collapsedHeight: widget.collapsedHeight,
+ bottomHeight: bottomHeight,
+ );
+
+ return _CoverCollapseSliver(
+ expandedCollapseExtent: geometry.collapseExtent,
+ child: SliverPersistentHeader(
+ pinned: true,
+ delegate: _AlbumCoverDelegate(
+ geometry: geometry,
+ topPadding: MediaQuery.paddingOf(context).top,
collapsedHeight: widget.collapsedHeight,
bottomHeight: bottomHeight,
- ),
- topPadding: MediaQuery.paddingOf(context).top,
- collapsedHeight: widget.collapsedHeight,
- bottomHeight: bottomHeight,
- colors: colors,
- backgroundColor: widget.backgroundColor,
- pinnedOverlayStyle: _pinnedOverlayStyle,
- isCovered: _isCovered,
- title: widget.title,
- actionsBuilder: widget.actionsBuilder,
- bottom: widget.bottom,
- photo: _CoverPhoto(
- cover: widget.cover,
+ colors: colors,
backgroundColor: widget.backgroundColor,
- heroTag: widget.heroTag,
- contentOpacity: animation,
- ),
- content: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- _CoverCaption(GalleryFilesState.maybeOf(context)?.captureDateRange),
- Semantics(
- header: true,
- child: Text(
- widget.title,
- maxLines: 2,
- overflow: TextOverflow.ellipsis,
- textAlign: TextAlign.center,
- style: TextStyles.display1.copyWith(color: colors.specialWhite),
+ pinnedOverlayStyle: _pinnedOverlayStyle,
+ isCovered: _isCovered,
+ title: widget.title,
+ actionsBuilder: widget.actionsBuilder,
+ bottom: widget.bottom,
+ foregroundKey: _coverForegroundKey,
+ photoBuilder: (foreground, collapseOffset) => _CoverPhoto(
+ photoKey: _coverPhotoKey,
+ foreground: foreground,
+ foregroundNotifier: _coverForegroundNotifier,
+ collapseOffset: collapseOffset,
+ imageBottomInset: _coverBottomInset(bottomHeight) - 1,
+ cover: widget.cover,
+ backgroundColor: widget.backgroundColor,
+ heroTag: widget.heroTag,
+ ),
+ content: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ _CoverCaption(
+ GalleryFilesState.maybeOf(context)?.captureDateRange,
),
- ),
- if (description != null) ...[
- const SizedBox(height: Spacing.sm),
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 18),
+ Semantics(
+ header: true,
child: Text(
- description,
- maxLines: _descriptionMaxLines,
+ widget.title,
+ maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
- style: TextStyles.mini.copyWith(
- color: colors.specialWhite.withValues(alpha: 0.92),
+ style: TextStyles.display1.copyWith(
+ color: colors.specialWhite,
),
),
),
+ if (description != null) ...[
+ const SizedBox(height: Spacing.sm),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 18),
+ child: Text(
+ description,
+ maxLines: _descriptionMaxLines,
+ overflow: TextOverflow.ellipsis,
+ textAlign: TextAlign.center,
+ style: TextStyles.mini.copyWith(
+ color: colors.specialWhite.withValues(alpha: 0.92),
+ ),
+ ),
+ ),
+ ],
+ if (widget.coverActions.isNotEmpty) ...[
+ const SizedBox(height: _contentSpacing),
+ Row(
+ mainAxisSize: MainAxisSize.min,
+ spacing: Spacing.md,
+ children: widget.coverActions,
+ ),
+ ],
],
- if (widget.coverActions.isNotEmpty) ...[
- const SizedBox(height: _contentSpacing),
- Row(
- mainAxisSize: MainAxisSize.min,
- spacing: Spacing.md,
- children: widget.coverActions,
- ),
- ],
- ],
+ ),
),
),
);
}
}
+class _CoverCollapseSliver extends SingleChildRenderObjectWidget {
+ const _CoverCollapseSliver({
+ required this.expandedCollapseExtent,
+ required super.child,
+ });
+
+ final double expandedCollapseExtent;
+
+ @override
+ RenderObject createRenderObject(BuildContext context) =>
+ _RenderCoverCollapseSliver(expandedCollapseExtent);
+
+ @override
+ void updateRenderObject(
+ BuildContext context,
+ covariant _RenderCoverCollapseSliver renderObject,
+ ) {
+ renderObject.expandedCollapseExtent = expandedCollapseExtent;
+ }
+}
+
+class _RenderCoverCollapseSliver extends RenderProxySliver {
+ _RenderCoverCollapseSliver(this._expandedCollapseExtent);
+
+ double _expandedCollapseExtent;
+
+ set expandedCollapseExtent(double value) {
+ if (_expandedCollapseExtent == value) return;
+ _expandedCollapseExtent = value;
+ markNeedsLayout();
+ }
+
+ @override
+ void performLayout() {
+ final scrollExtent = math.min(
+ _coverCollapseScrollExtent,
+ _expandedCollapseExtent,
+ );
+ final offset = constraints.scrollOffset;
+ final coverOffset = offset < scrollExtent
+ ? offset * _expandedCollapseExtent / scrollExtent
+ : offset + _expandedCollapseExtent - scrollExtent;
+ child!.layout(
+ constraints.copyWith(scrollOffset: coverOffset),
+ parentUsesSize: true,
+ );
+ final childGeometry = child!.geometry!;
+ geometry = childGeometry.copyWith(
+ scrollExtent:
+ childGeometry.scrollExtent - _expandedCollapseExtent + scrollExtent,
+ );
+ }
+}
+
class AlbumCoverActionButton extends StatelessWidget {
const AlbumCoverActionButton({
super.key,
@@ -214,21 +302,52 @@ class AlbumCoverActionButton extends StatelessWidget {
}
}
+class _CoverForegroundNotifier extends ValueNotifier<Widget> {
+ _CoverForegroundNotifier() : super(const SizedBox.shrink());
+
+ void update(Widget foreground, BuildContext context) {
+ if (hasListeners) {
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (context.mounted) value = foreground;
+ });
+ } else {
+ value = foreground;
+ }
+ }
+}
+
class _CoverPhoto extends StatelessWidget {
const _CoverPhoto({
+ required this.photoKey,
+ required this.foreground,
+ required this.foregroundNotifier,
+ required this.collapseOffset,
+ required this.imageBottomInset,
required this.cover,
required this.backgroundColor,
this.heroTag,
- required this.contentOpacity,
});
- final Animation<double> contentOpacity;
+ final GlobalKey photoKey;
+ final Widget foreground;
+ final _CoverForegroundNotifier foregroundNotifier;
+ final double collapseOffset;
+ final double imageBottomInset;
final EnteFile cover;
final Color backgroundColor;
final String? heroTag;
@override
Widget build(BuildContext context) {
+ final filterData = InheritedSearchFilterData.maybeOf(context);
+ final contextualForeground = MediaQuery(
+ data: MediaQuery.of(context),
+ child: InheritedSearchFilterData(
+ searchFilterDataProvider: filterData?.searchFilterDataProvider,
+ child: foreground,
+ ),
+ );
+ foregroundNotifier.update(contextualForeground, context);
final thumbnail = ThumbnailWidget(
cover,
rawThumbnail: true,
@@ -236,25 +355,46 @@ class _CoverPhoto extends StatelessWidget {
useRequestedThumbnailSizeForLocalCache: true,
useCachedThumbnailAsPlaceholder: true,
);
- final photo = Stack(
+ final background = Stack(
+ key: photoKey,
fit: StackFit.expand,
clipBehavior: Clip.none,
children: [
- thumbnail,
- _CoverPhotoScrims(backgroundColor: backgroundColor),
+ Positioned(
+ top: -collapseOffset,
+ left: 0,
+ right: 0,
+ bottom: imageBottomInset,
+ child: Stack(
+ fit: StackFit.expand,
+ clipBehavior: Clip.none,
+ children: [
+ thumbnail,
+ _CoverPhotoScrims(backgroundColor: backgroundColor),
+ ],
+ ),
+ ),
],
);
- if (heroTag == null) {
+ final photo = Stack(
+ fit: StackFit.expand,
+ clipBehavior: Clip.none,
+ children: [background, contextualForeground],
+ );
+ if (heroTag == null || MediaQuery.disableAnimationsOf(context)) {
return photo;
}
const motionCurve = Curves.easeInOut;
return Hero(
tag: heroTag!,
+ createRectTween: (begin, end) => RectTween(begin: begin, end: end),
curve: motionCurve,
reverseCurve: motionCurve,
transitionOnUserGestures: true,
- placeholderBuilder: (context, size, child) =>
- SizedBox.fromSize(size: size, child: child),
+ placeholderBuilder: (context, size, child) => SizedBox.fromSize(
+ size: size,
+ child: Offstage(child: background),
+ ),
flightShuttleBuilder:
(
flightContext,
@@ -303,13 +443,17 @@ class _CoverPhoto extends StatelessWidget {
} else {
cardRadius = SmoothBorderRadius.zero;
}
- final image =
- _heroImage(fromHeroContext) ?? _heroImage(cardContext);
+ final image = flightDirection == HeroFlightDirection.push
+ ? _heroImage(cardContext) ?? _heroImage(photoKey.currentContext)
+ : _heroImage(photoKey.currentContext) ??
+ _heroImage(cardContext);
return _CoverHeroFlight(
animation: (ModalRoute.of(coverContext)! as PageRoute).animation!
.drive(CurveTween(curve: motionCurve)),
image: image?.image,
- contentOpacity: contentOpacity,
+ foreground: foregroundNotifier,
+ coverSize: (coverContext.findRenderObject()! as RenderBox).size,
+ imageBottomInset: imageBottomInset,
card: card,
showVideoIcon: cover.fileType == FileType.video,
cardRadius: cardRadius,
@@ -321,7 +465,7 @@ class _CoverPhoto extends StatelessWidget {
}
}
-RenderImage? _heroImage(BuildContext context) {
+RenderImage? _heroImage(BuildContext? context) {
RenderImage? image;
void visit(RenderObject renderObject) {
if (renderObject is RenderImage && renderObject.image != null) {
@@ -331,7 +475,7 @@ RenderImage? _heroImage(BuildContext context) {
}
}
- final renderObject = context.findRenderObject();
+ final renderObject = context?.findRenderObject();
if (renderObject != null) {
visit(renderObject);
}
@@ -341,8 +485,10 @@ RenderImage? _heroImage(BuildContext context) {
class _CoverHeroFlight extends StatefulWidget {
const _CoverHeroFlight({
required this.animation,
- required this.contentOpacity,
required this.image,
+ required this.foreground,
+ required this.coverSize,
+ required this.imageBottomInset,
required this.card,
required this.showVideoIcon,
required this.cardRadius,
@@ -350,8 +496,10 @@ class _CoverHeroFlight extends StatefulWidget {
});
final Animation<double> animation;
- final Animation<double> contentOpacity;
final ui.Image? image;
+ final ValueListenable<Widget> foreground;
+ final Size coverSize;
+ final double imageBottomInset;
final Widget card;
final bool showVideoIcon;
final SmoothBorderRadius cardRadius;
@@ -372,36 +520,74 @@ class _CoverHeroFlightState extends State<_CoverHeroFlight> {
@override
Widget build(BuildContext context) {
- return FadeTransition(
- opacity: ReverseAnimation(widget.contentOpacity),
- child: AnimatedBuilder(
- animation: widget.animation,
+ final foreground = FadeTransition(
+ opacity: widget.animation.drive(
+ CurveTween(curve: const Interval(0.35, 1, curve: Curves.easeOut)),
+ ),
+ child: FittedBox(
+ fit: BoxFit.fill,
+ child: SizedBox.fromSize(
+ size: widget.coverSize,
+ child: RepaintBoundary(
+ child: Material(
+ type: MaterialType.transparency,
+ child: ValueListenableBuilder<Widget>(
+ valueListenable: widget.foreground,
+ builder: (_, foreground, _) => foreground,
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ return AnimatedBuilder(
+ animation: widget.animation,
+ child: Stack(
+ fit: StackFit.expand,
+ children: [
+ if (_image != null)
+ RawImage(image: _image, fit: BoxFit.cover)
+ else
+ widget.card,
+ if (_image != null && widget.showVideoIcon)
+ FadeTransition(
+ opacity: ReverseAnimation(widget.animation),
+ child: const VideoOverlayIcon(),
+ ),
+ FadeTransition(
+ opacity: widget.animation,
+ child: _CoverPhotoScrims(backgroundColor: widget.backgroundColor),
+ ),
+ ],
+ ),
+ builder: (context, child) => ClipSmoothRect(
+ radius: SmoothBorderRadius.lerp(
+ widget.cardRadius,
+ SmoothBorderRadius.zero,
+ widget.animation.value,
+ )!,
child: Stack(
fit: StackFit.expand,
children: [
- if (_image != null)
- RawImage(image: _image, fit: BoxFit.cover)
- else
- widget.card,
- if (_image != null && widget.showVideoIcon)
- FadeTransition(
- opacity: ReverseAnimation(widget.animation),
- child: const VideoOverlayIcon(),
- ),
- FadeTransition(
- opacity: widget.animation,
- child: _CoverPhotoScrims(backgroundColor: widget.backgroundColor),
+ Positioned.fill(
+ bottom: widget.imageBottomInset * widget.animation.value,
+ child: child!,
),
+ if (widget.imageBottomInset > 0)
+ Positioned(
+ left: 0,
+ right: 0,
+ bottom: 0,
+ height: widget.imageBottomInset * widget.animation.value,
+ child: ColoredBox(
+ color: widget.backgroundColor.withValues(
+ alpha: widget.animation.value,
+ ),
+ ),
+ ),
+ foreground,
],
),
- builder: (context, child) => ClipSmoothRect(
- radius: SmoothBorderRadius.lerp(
- widget.cardRadius,
- SmoothBorderRadius.zero,
- widget.animation.value,
- )!,
- child: child!,
- ),
),
);
}
@@ -530,8 +716,19 @@ class _CoverCaption extends StatelessWidget {
@override
Widget build(BuildContext context) {
final dateRange = this.dateRange;
+ final style = TextStyles.tiny.copyWith(
+ color: context.componentColors.specialWhite.withValues(alpha: 0.82),
+ );
if (dateRange == null) {
- return const SizedBox.shrink();
+ return ExcludeSemantics(
+ child: Padding(
+ padding: const EdgeInsets.only(bottom: _contentSpacing),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: Spacing.sm),
+ child: Text(" ", style: style),
+ ),
+ ),
+ );
}
final start = DateTime.fromMicrosecondsSinceEpoch(dateRange.oldest);
final end = DateTime.fromMicrosecondsSinceEpoch(dateRange.newest);
@@ -572,9 +769,6 @@ class _CoverCaption extends StatelessWidget {
final captions = end.year - start.year >= 2
? [yearRange]
: [dayRange, monthRange, yearRange];
- final style = TextStyles.tiny.copyWith(
- color: context.componentColors.specialWhite.withValues(alpha: 0.82),
- );
return LayoutBuilder(
builder: (context, constraints) {
@@ -625,7 +819,8 @@ class _AlbumCoverDelegate extends SliverPersistentHeaderDelegate {
required this.title,
required this.actionsBuilder,
required this.bottom,
- required this.photo,
+ required this.foregroundKey,
+ required this.photoBuilder,
required this.content,
});
@@ -640,7 +835,8 @@ class _AlbumCoverDelegate extends SliverPersistentHeaderDelegate {
final String title;
final List<Widget> Function(Color foregroundColor) actionsBuilder;
final PreferredSizeWidget? bottom;
- final Widget photo;
+ final GlobalKey foregroundKey;
+ final Widget Function(Widget foreground, double collapseOffset) photoBuilder;
final Widget content;
@override
@@ -660,15 +856,17 @@ class _AlbumCoverDelegate extends SliverPersistentHeaderDelegate {
bool overlapsContent,
) {
final collapseOffset = math.min(shrinkOffset, geometry.collapseExtent);
+ final collapseProgress = collapseOffset / geometry.collapseExtent;
final pinnedProgress =
- ((collapseOffset / geometry.collapseExtent - _pinnedFadeStart) /
- (1 - _pinnedFadeStart))
- .clamp(0.0, 1.0);
- final contentOpacity = (1 - collapseOffset / _contentFadeExtent).clamp(
+ ((collapseProgress - _pinnedFadeStart) / (1 - _pinnedFadeStart)).clamp(
+ 0.0,
+ 1.0,
+ );
+ final contentOpacity = (1 - collapseProgress / _pinnedFadeStart).clamp(
0.0,
1.0,
);
- final titleOpacity = (1 - contentOpacity * 2).clamp(0.0, 1.0);
+ final titleOpacity = contentOpacity == 0 ? 1.0 : 0.0;
final foregroundColor = Color.lerp(
colors.specialWhite,
colors.textBase,
@@ -679,132 +877,137 @@ class _AlbumCoverDelegate extends SliverPersistentHeaderDelegate {
final coverBottomInset = _coverBottomInset(bottomHeight);
final respectRightInset = Theme.of(context).platform != TargetPlatform.iOS;
- return AnnotatedRegion<SystemUiOverlayStyle>(
- value: pinnedProgress < 0.5 && !isCovered
- ? _coverOverlayStyle
- : pinnedOverlayStyle,
- child: Stack(
- fit: StackFit.expand,
- children: [
- Positioned(
- top: -collapseOffset,
- left: 0,
- right: 0,
- bottom: coverBottomInset - 1,
- child: HeroMode(enabled: collapseOffset == 0, child: photo),
+ final foreground = Stack(
+ key: foregroundKey,
+ fit: StackFit.expand,
+ children: [
+ Positioned(
+ top: 0,
+ left: 0,
+ right: 0,
+ height: topPadding + _topScrimHeight,
+ child: const IgnorePointer(
+ child: DecoratedBox(
+ decoration: BoxDecoration(
+ gradient: LinearGradient(
+ begin: Alignment.topCenter,
+ end: Alignment.bottomCenter,
+ colors: [_scrimColor, _transparentScrimColor],
+ ),
+ ),
+ ),
),
+ ),
+ if (contentOpacity > 0)
Positioned(
- top: 0,
- left: 0,
- right: 0,
- height: topPadding + _topScrimHeight,
- child: const IgnorePointer(
- child: DecoratedBox(
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- colors: [_scrimColor, _transparentScrimColor],
+ top: topPadding + collapsedHeight,
+ left: Spacing.lg,
+ right: Spacing.lg,
+ bottom: coverBottomInset + collapsedHeight,
+ child: SafeArea(
+ top: false,
+ bottom: false,
+ child: LayoutBuilder(
+ builder: (context, constraints) => Opacity(
+ opacity: contentOpacity,
+ child: FittedBox(
+ fit: BoxFit.scaleDown,
+ alignment: Alignment.center,
+ child: SizedBox(
+ width: constraints.maxWidth,
+ child: content,
+ ),
),
),
),
),
),
- if (contentOpacity > 0)
- Positioned(
- top: topPadding + collapsedHeight,
- left: Spacing.lg,
- right: Spacing.lg,
- bottom: coverBottomInset + collapsedHeight,
- child: SafeArea(
- top: false,
- bottom: false,
- child: LayoutBuilder(
- builder: (context, constraints) => Opacity(
- opacity: contentOpacity,
- child: FittedBox(
- fit: BoxFit.scaleDown,
- alignment: Alignment.center,
- child: SizedBox(
- width: constraints.maxWidth,
- child: content,
+ if (pinnedProgress > 0)
+ Positioned.fill(
+ child: ColoredBox(
+ color: backgroundColor.withValues(alpha: pinnedProgress),
+ ),
+ ),
+ Positioned(
+ top:
+ topPadding +
+ (Spacing.lg - (collapsedHeight - _compactHeaderControlSize) / 2) *
+ (1 - pinnedProgress),
+ left: Spacing.lg,
+ right: Spacing.lg,
+ height: collapsedHeight,
+ child: SafeArea(
+ top: false,
+ bottom: false,
+ left: false,
+ right: respectRightInset,
+ child: Row(
+ spacing: Spacing.md,
+ children: [
+ IconButton(
+ tooltip: MaterialLocalizations.of(context).backButtonTooltip,
+ icon: const Icon(Icons.arrow_back),
+ color: foregroundColor,
+ iconSize: IconSizes.medium,
+ onPressed: () => Navigator.maybePop(context),
+ ),
+ Expanded(
+ child: ExcludeSemantics(
+ excluding: contentOpacity > 0,
+ child: Opacity(
+ opacity: titleOpacity,
+ alwaysIncludeSemantics: true,
+ child: Text(
+ title,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyles.display3.copyWith(
+ color: foregroundColor,
+ ),
),
),
),
),
- ),
- ),
- if (pinnedProgress > 0)
- Positioned.fill(
- child: ColoredBox(
- color: backgroundColor.withValues(alpha: pinnedProgress),
- ),
+ Row(
+ mainAxisSize: MainAxisSize.min,
+ spacing: _headerActionSpacing,
+ children: actionsBuilder(foregroundColor),
+ ),
+ ],
),
+ ),
+ ),
+ if (bottom != null)
Positioned(
- top:
- topPadding +
- (Spacing.lg -
- (collapsedHeight - _compactHeaderControlSize) / 2) *
- (1 - pinnedProgress),
- left: Spacing.lg,
- right: Spacing.lg,
- height: collapsedHeight,
+ key: const ValueKey("album_cover_bottom"),
+ left: 0,
+ right: 0,
+ bottom: 0,
+ height: bottomHeight,
child: SafeArea(
top: false,
bottom: false,
left: false,
right: respectRightInset,
- child: Row(
- spacing: Spacing.md,
- children: [
- IconButton(
- tooltip: MaterialLocalizations.of(
- context,
- ).backButtonTooltip,
- icon: const Icon(Icons.arrow_back),
- color: foregroundColor,
- iconSize: IconSizes.medium,
- onPressed: () => Navigator.maybePop(context),
- ),
- Expanded(
- child: ExcludeSemantics(
- excluding: contentOpacity > 0,
- child: Opacity(
- opacity: titleOpacity,
- child: Text(
- title,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: TextStyles.display3.copyWith(
- color: foregroundColor,
- ),
- ),
- ),
- ),
- ),
- Row(
- mainAxisSize: MainAxisSize.min,
- spacing: _headerActionSpacing,
- children: actionsBuilder(foregroundColor),
- ),
- ],
- ),
+ child: bottom!,
),
),
- if (bottom != null)
- Positioned(
- left: 0,
- right: 0,
- bottom: 0,
- height: bottomHeight,
- child: SafeArea(
- top: false,
- bottom: false,
- left: false,
- right: respectRightInset,
- child: bottom!,
- ),
+ ],
+ );
+
+ return AnnotatedRegion<SystemUiOverlayStyle>(
+ value: pinnedProgress < 0.5 && !isCovered
+ ? _coverOverlayStyle
+ : pinnedOverlayStyle,
+ child: Stack(
+ fit: StackFit.expand,
+ children: [
+ Positioned.fill(
+ child: HeroMode(
+ enabled: collapseOffset == 0,
+ child: photoBuilder(foreground, collapseOffset),
),
+ ),
],
),
);
@@ -819,6 +1022,7 @@ double _coverBottomInset(double bottomHeight) {
}
const _coverHeight = 441.0;
+const _coverCollapseScrollExtent = 120.0;
const _coverDissolveHeight = 100.0;
const _topScrimHeight = 31.0;
const _bottomOverlap = 25.0;
@@ -829,7 +1033,6 @@ const _contentScrimHeight = 157.0;
const _contentScrimBlur = 54.25;
const _compactHeaderControlSize = 38.0;
const _headerActionSpacing = 6.0;
-const _contentFadeExtent = 120.0;
const _pinnedFadeStart = 0.6;
const _foregroundSwitchStart = 0.4;
const _foregroundSwitchEnd = 0.6;
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
index 09ff137d78..b8babc5718 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
@@ -1,6 +1,7 @@
import 'dart:async';
import "dart:io";
+import "package:ente_components/ente_components.dart" show AppBarCollapseSpacer;
import "package:ente_pure_utils/ente_pure_utils.dart";
import 'package:ente_ui/components/loading_widget.dart';
import 'package:flutter/foundation.dart';
@@ -1051,6 +1052,11 @@ class GalleryState extends State<Gallery> {
child: widget.footer,
),
),
+ if (widget.appBar?.extendBodyForCollapse ??
+ false)
+ AppBarCollapseSpacer(
+ collapseExtent: appBarCollapseExtent,
+ ),
],
),
);
@@ -1106,6 +1112,12 @@ class _GalleryAppBarScrollBody extends StatelessWidget {
slivers: [
appBarConfig.buildSliver(context),
SliverFillRemaining(hasScrollBody: false, child: child),
+ if (appBarConfig.extendBodyForCollapse)
+ AppBarCollapseSpacer(
+ collapseExtent: appBarConfig
+ .resolveGeometry(context)
+ .collapseExtent,
+ ),
],
);
}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_config.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_config.dart
index a8fa11f43b..1539873837 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_config.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_config.dart
@@ -8,8 +8,10 @@ class GalleryAppBarConfig {
const GalleryAppBarConfig({
required this.sliverBuilder,
required this.geometryBuilder,
+ this.extendBodyForCollapse = false,
});
+ final bool extendBodyForCollapse;
final WidgetBuilder sliverBuilder;
final GalleryAppBarGeometryBuilder geometryBuilder;
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
index c58f38ddb4..8d1872f7b1 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
@@ -85,6 +85,7 @@ class GalleryAppBarWidget extends StatefulWidget {
}) {
assert(cover == null || collection != null);
return GalleryAppBarConfig(
+ extendBodyForCollapse: cover != null && bottom == null,
sliverBuilder: (_) => GalleryAppBarWidget._(
type,
title,
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/state/search_filter_data_provider.dart b/mobile/apps/photos/lib/ui/viewer/gallery/state/search_filter_data_provider.dart
index 7262827881..5bb1abb00f 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/state/search_filter_data_provider.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/state/search_filter_data_provider.dart
@@ -19,8 +19,7 @@ class SearchFilterDataProvider {
_appliedFiltersNotifier.appliedFilters;
void clearAndAddRecommendations(List<HierarchicalSearchFilter> filters) {
- _recommendedFiltersNotifier.clearFilters();
- _safelyAddToRecommended(filters);
+ _safelyAddToRecommended(filters, replace: true);
}
void applyFilters(List<HierarchicalSearchFilter> filters) {
@@ -84,7 +83,10 @@ class SearchFilterDataProvider {
}
}
- void _safelyAddToRecommended(List<HierarchicalSearchFilter> filters) {
+ void _safelyAddToRecommended(
+ List<HierarchicalSearchFilter> filters, {
+ bool replace = false,
+ }) {
if (_appliedFiltersNotifier.appliedFilters.any(
(e) => e is OnlyThemFilter,
)) {
@@ -95,7 +97,7 @@ class SearchFilterDataProvider {
final List<HierarchicalSearchFilter> filtersToAvoid = [
...appliedFilters,
- ...recommendations,
+ if (!replace) ...recommendations,
];
if (appliedFilters.isEmpty) {
@@ -105,6 +107,7 @@ class SearchFilterDataProvider {
_recommendedFiltersNotifier.addFilters(
filters,
filtersToAvoid: filtersToAvoid,
+ replace: replace,
);
}
@@ -144,7 +147,9 @@ class _RecommendedFiltersNotifier extends ChangeNotifier {
void addFilters(
List<HierarchicalSearchFilter> filters, {
required List<HierarchicalSearchFilter> filtersToAvoid,
+ bool replace = false,
}) {
+ if (replace) _recommendedFilters.clear();
for (HierarchicalSearchFilter filter in filters) {
bool avoidFilter = false;
for (HierarchicalSearchFilter filterToAvoid in filtersToAvoid) {
@@ -166,9 +171,4 @@ class _RecommendedFiltersNotifier extends ChangeNotifier {
_recommendedFilters.removeWhere((filter) => filters.contains(filter));
notifyListeners();
}
-
- void clearFilters() {
- _recommendedFilters.clear();
- notifyListeners();
- }
}
diff --git a/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/app_bar_filter_chips.dart b/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/app_bar_filter_chips.dart
index 7e9b3d4168..bac30a1389 100644
--- a/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/app_bar_filter_chips.dart
+++ b/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/app_bar_filter_chips.dart
@@ -33,7 +33,8 @@ class AppBarFilterChips extends StatefulWidget {
}
class _AppBarFilterChipsState extends State<AppBarFilterChips> {
- final _filterChipKeys = <HierarchicalSearchFilter, GlobalKey>{};
+ var _filterChipKeys = <HierarchicalSearchFilter, GlobalKey>{};
+ List<HierarchicalSearchFilter> _previousRecommendations = const [];
SearchFilterDataProvider? _searchFilterDataProvider;
HierarchicalSearchFilter? _filterToRevealAfterApply;
@@ -89,6 +90,23 @@ class _AppBarFilterChipsState extends State<AppBarFilterChips> {
final recommendations = getRecommendedFiltersForAppBar(
searchFilterDataProvider,
);
+ final oldKeys = _filterChipKeys;
+ _filterChipKeys = {
+ for (final filter in [...appliedFilters, ...recommendations])
+ filter:
+ oldKeys.remove(filter) ??
+ oldKeys.remove(
+ _previousRecommendations
+ .where(
+ (previous) =>
+ oldKeys.containsKey(previous) &&
+ filter.isSameFilter(previous),
+ )
+ .firstOrNull,
+ ) ??
+ GlobalKey(),
+ };
+ _previousRecommendations = recommendations;
final hasFilters = appliedFilters.isNotEmpty || recommendations.isNotEmpty;
if (!hasFilters && !widget.animateRecommendations) {
return const SizedBox.shrink();
@@ -168,9 +186,8 @@ class _AppBarFilterChipsState extends State<AppBarFilterChips> {
}
Widget _buildFilterChip(HierarchicalSearchFilter filter) {
- final chipKey = _keyForFilter(filter);
return KeyedSubtree(
- key: chipKey,
+ key: _filterChipKeys[filter]!,
child: HierarchicalFilterChip(
filter: filter,
apply: () => _applyFilter(filter),
@@ -179,10 +196,6 @@ class _AppBarFilterChipsState extends State<AppBarFilterChips> {
);
}
- GlobalKey _keyForFilter(HierarchicalSearchFilter filter) {
- return _filterChipKeys[filter] ??= GlobalKey();
- }
-
void _applyFilter(HierarchicalSearchFilter filter) {
_filterToRevealAfterApply = filter;
_searchFilterDataProvider!.applyFilters([filter]);
diff --git a/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/chip_widgets/face_filter_chip.dart b/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/chip_widgets/face_filter_chip.dart
index 4e4ba7c0a1..82752f1687 100644
--- a/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/chip_widgets/face_filter_chip.dart
+++ b/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/chip_widgets/face_filter_chip.dart
@@ -9,6 +9,7 @@ class FaceFilterChip extends StatelessWidget {
final VoidCallback remove;
final bool isApplied;
final double? avatarSize;
+ final Object? retryKey;
const FaceFilterChip({
required this.personId,
@@ -17,6 +18,7 @@ class FaceFilterChip extends StatelessWidget {
required this.remove,
required this.isApplied,
this.avatarSize,
+ this.retryKey,
super.key,
});
@@ -27,6 +29,7 @@ class FaceFilterChip extends StatelessWidget {
personId: personId,
clusterID: clusterId,
useFullFile: false,
+ retryKey: retryKey,
),
state: isApplied
? FilterChipComponentState.selected
diff --git a/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/chip_widgets/hierarchical_filter_chip.dart b/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/chip_widgets/hierarchical_filter_chip.dart
index 19a27b3aae..d2fe79df02 100644
--- a/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/chip_widgets/hierarchical_filter_chip.dart
+++ b/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/chip_widgets/hierarchical_filter_chip.dart
@@ -31,6 +31,7 @@ class HierarchicalFilterChip extends StatelessWidget {
remove: remove,
isApplied: filter.isApplied,
avatarSize: faceAvatarSize,
+ retryKey: filter,
);
}
if (filter is OnlyThemFilter) {
diff --git a/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/chip_widgets/only_them_filter_chip.dart b/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/chip_widgets/only_them_filter_chip.dart
index 5742cba09a..3d55595d7b 100644
--- a/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/chip_widgets/only_them_filter_chip.dart
+++ b/mobile/apps/photos/lib/ui/viewer/hierarchicial_search/chip_widgets/only_them_filter_chip.dart
@@ -61,6 +61,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
personId: faceFilters.first.personId,
clusterID: faceFilters.first.clusterId,
useFullFile: false,
+ retryKey: faceFilters,
),
),
);
@@ -75,6 +76,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
personId: faceFilters.first.personId,
clusterID: faceFilters.first.clusterId,
useFullFile: false,
+ retryKey: faceFilters,
),
),
const SizedBox(width: 1),
@@ -85,6 +87,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
personId: faceFilters.last.personId,
clusterID: faceFilters.last.clusterId,
useFullFile: false,
+ retryKey: faceFilters,
),
),
],
@@ -102,6 +105,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
personId: faceFilters[0].personId,
clusterID: faceFilters[0].clusterId,
useFullFile: false,
+ retryKey: faceFilters,
),
),
const SizedBox(width: 1),
@@ -119,6 +123,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
personId: faceFilters[1].personId,
clusterID: faceFilters[1].clusterId,
useFullFile: false,
+ retryKey: faceFilters,
),
),
),
@@ -134,6 +139,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
personId: faceFilters[2].personId,
clusterID: faceFilters[2].clusterId,
useFullFile: false,
+ retryKey: faceFilters,
),
),
),
@@ -161,6 +167,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
personId: faceFilters[0].personId,
clusterID: faceFilters[0].clusterId,
useFullFile: false,
+ retryKey: faceFilters,
),
),
),
@@ -176,6 +183,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
personId: faceFilters[1].personId,
clusterID: faceFilters[1].clusterId,
useFullFile: false,
+ retryKey: faceFilters,
),
),
),
@@ -196,6 +204,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
personId: faceFilters[2].personId,
clusterID: faceFilters[2].clusterId,
useFullFile: false,
+ retryKey: faceFilters,
),
),
),
@@ -211,6 +220,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
personId: faceFilters[3].personId,
clusterID: faceFilters[3].clusterId,
useFullFile: false,
+ retryKey: faceFilters,
),
),
),
diff --git a/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart b/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart
index 507852edf5..75d2377d14 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart
@@ -33,6 +33,7 @@ class PersonFaceWidget extends StatefulWidget {
final bool useFullFile;
final VoidCallback? onErrorCallback;
final bool keepAlive;
+ final Object? retryKey;
// Physical pixels; null or non-positive decodes at full resolution.
final int? cachedPixelWidth;
@@ -44,6 +45,7 @@ class PersonFaceWidget extends StatefulWidget {
this.onErrorCallback,
this.keepAlive = false,
this.cachedPixelWidth,
+ this.retryKey,
super.key,
}) : assert(
personId != null || clusterID != null,
@@ -60,6 +62,7 @@ class _PersonFaceWidgetState extends State<PersonFaceWidget>
int? _faceCropFileId;
AvatarIdentity? _personIdentity;
bool _showingFallback = false;
+ bool _faceCropFailed = false;
bool _fallbackEverUsed = false;
bool _personHasContactLink = false;
int? _linkedContactUserId;
@@ -98,6 +101,10 @@ class _PersonFaceWidgetState extends State<PersonFaceWidget>
_linkedContactUserId = null;
_personIdentity = null;
faceCropFuture = _startFaceCropLoad();
+ } else if (_faceCropFailed &&
+ widget.retryKey != null &&
+ oldWidget.retryKey != widget.retryKey) {
+ faceCropFuture = _startFaceCropLoad();
}
}
@@ -206,9 +213,17 @@ class _PersonFaceWidgetState extends State<PersonFaceWidget>
);
}
- Future<Uint8List?> _startFaceCropLoad() {
+ Future<Uint8List?> _startFaceCropLoad() async {
+ _faceCropFailed = false;
final generation = ++_loadGeneration;
- return _loadFaceCrop(generation);
+ try {
+ final crop = await _loadFaceCrop(generation);
+ if (_isCurrentLoad(generation)) _faceCropFailed = crop == null;
+ return crop;
+ } catch (_) {
+ if (_isCurrentLoad(generation)) _faceCropFailed = true;
+ rethrow;
+ }
}
Future<Uint8List?> _loadFaceCrop(int generation) async {
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/album_cover_app_bar_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/album_cover_app_bar_test.dart
index 83bd4e0806..7e8cac92a3 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/album_cover_app_bar_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/album_cover_app_bar_test.dart
@@ -143,6 +143,47 @@ void main() {
await tester.pump(const Duration(seconds: 1));
}
});
+ testWidgets("keeps the title still when capture dates arrive", (
+ tester,
+ ) async {
+ final cover = EnteFile()..generatedID = 5;
+ ThumbnailInMemoryLruCache.put(cover, base64Decode(_onePixelPng));
+ final files = ValueNotifier<List<EnteFile>>([]);
+ addTearDown(files.dispose);
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: lightThemeData,
+ home: ValueListenableBuilder<List<EnteFile>>(
+ valueListenable: files,
+ builder: (_, files, _) {
+ final header = _coverHeader(cover);
+ header.collection.pubMagicMetadata = CollectionPubMagicMetadata(
+ description:
+ "An album description that wraps onto several lines.",
+ );
+ return GalleryFilesState(
+ child: Scaffold(body: CustomScrollView(slivers: [header])),
+ )..setGalleryFiles = files;
+ },
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ final title = find.byWidgetPredicate(
+ (widget) =>
+ widget is Text && widget.data == "Album" && widget.maxLines == 2,
+ );
+ final initialRect = tester.getRect(title);
+ files.value = [
+ EnteFile()..creationTime = DateTime(2024).microsecondsSinceEpoch,
+ EnteFile()..creationTime = DateTime(2026).microsecondsSinceEpoch,
+ ];
+ await tester.pumpAndSettle();
+ expect(find.text("2024 – 2026"), findsOneWidget);
+ expect(tester.getRect(title), initialRect);
+ await tester.pumpWidget(const SizedBox.shrink());
+ await tester.pump(const Duration(seconds: 1));
+ });
testWidgets("keeps one accessible title and restores status bar styles", (
tester,
) async {
@@ -180,14 +221,27 @@ void main() {
);
await tester.pump();
expect(iconBrightness.last, "Brightness.light");
- await tester.drag(find.byType(CustomScrollView), const Offset(0, -100));
+ final gesture = await tester.startGesture(
+ tester.getCenter(find.byType(CustomScrollView)),
+ );
+ await gesture.moveBy(const Offset(0, -100));
+ await tester.pump(const Duration(seconds: 1));
+ final compactTitle = find.byWidgetPredicate(
+ (widget) =>
+ widget is Text && widget.data == "Album" && widget.maxLines == 1,
+ );
+ final titleOpacity = find
+ .ancestor(of: compactTitle, matching: find.byType(Opacity))
+ .first;
+ expect(tester.widget<Opacity>(titleOpacity).opacity, 1);
+ await gesture.up();
await tester.pumpAndSettle();
expect(find.bySemanticsLabel(RegExp(r"^Album$")), findsOneWidget);
await tester.drag(find.byType(CustomScrollView), const Offset(0, -400));
await tester.pumpAndSettle();
expect(find.bySemanticsLabel(RegExp(r"^Album$")), findsOneWidget);
expect(iconBrightness.last, "Brightness.dark");
- await tester.drag(find.byType(CustomScrollView), const Offset(0, 500));
+ tester.state<ScrollableState>(find.byType(Scrollable)).position.jumpTo(0);
await tester.pumpAndSettle();
final context = tester.element(find.byType(Scaffold));
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart
index df467f5a55..64f68df4f3 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart
@@ -1,10 +1,12 @@
import "dart:convert";
import "dart:io";
+import "dart:typed_data";
import "package:dio/dio.dart";
import "package:ente_components/ente_components.dart";
import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:ente_strings/ente_strings.dart";
+import "package:ente_ui/components/loading_widget.dart";
import "package:figma_squircle/figma_squircle.dart";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
@@ -17,6 +19,7 @@ import "package:photos/core/configuration.dart";
import "package:photos/core/constants.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/db/files_db.dart";
+import "package:photos/db/ml/db.dart";
import "package:photos/ente_theme_data.dart";
import "package:photos/events/collection_meta_event.dart";
import "package:photos/events/collection_updated_event.dart";
@@ -28,6 +31,9 @@ import "package:photos/models/file/file_type.dart";
import "package:photos/models/gallery_type.dart";
import "package:photos/models/ignored_file.dart";
import "package:photos/models/metadata/collection_magic.dart";
+import "package:photos/models/ml/face/face.dart";
+import "package:photos/models/search/hierarchical/camera_filter.dart";
+import "package:photos/models/search/hierarchical/face_filter.dart";
import "package:photos/models/selected_files.dart";
import "package:photos/module/download/thumbnail.dart";
import "package:photos/service_locator.dart";
@@ -35,6 +41,8 @@ import "package:photos/services/app_navigation_service.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/services/favorites_service.dart";
import "package:photos/services/ignored_files_service.dart";
+import "package:photos/settings/local_settings.dart";
+import "package:photos/src/rust/frb_generated.dart";
import "package:photos/ui/collections/album/row_item.dart";
import "package:photos/ui/components/bottom_action_bar/action_bar_widget.dart";
import "package:photos/ui/components/bottom_action_bar/selection_action_sheet.dart";
@@ -45,6 +53,11 @@ import "package:photos/ui/viewer/gallery/gallery.dart";
import "package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart";
import "package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart";
import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";
+import "package:photos/ui/viewer/gallery/state/inherited_search_filter_data.dart";
+import "package:photos/ui/viewer/gallery/state/search_filter_data_provider.dart";
+import "package:photos/ui/viewer/hierarchicial_search/app_bar_filter_chips.dart";
+import "package:photos/ui/viewer/people/person_face_widget.dart";
+import "package:photos/utils/face/face_thumbnail_cache.dart";
import "package:shared_preferences/shared_preferences.dart";
void main() {
@@ -144,6 +157,47 @@ void main() {
expect(find.text("Open album"), findsOneWidget);
});
+ testWidgets("lets a short album fully collapse its cover", (tester) async {
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = const Size(402, 874);
+ addTearDown(tester.view.resetDevicePixelRatio);
+ addTearDown(tester.view.resetPhysicalSize);
+ final previousLayout = localSettings.getGalleryLayoutType();
+ final previousGridSize = localSettings.getPhotoGridSize();
+ addTearDown(() async {
+ await localSettings.setGalleryLayoutType(previousLayout);
+ await localSettings.setPhotoGridSize(previousGridSize);
+ });
+ await localSettings.setGalleryLayoutType(GalleryLayoutType.justified);
+ await localSettings.setPhotoGridSize(5);
+ final collection = _collection();
+ final cover = _file(1)..pubMmdEncodedJson = '{"w":400,"h":600}';
+ await tester.runAsync(() async {
+ await FilesDB.instance.insertMultiple([cover]);
+ await CollectionsService.instance.getCover(collection);
+ });
+ await _pumpAlbum(tester, collection);
+ await _expectCover(tester, cover, count: 1);
+ final boundaries = tester.state<GalleryBoundariesProviderState>(
+ find.byType(GalleryBoundariesProvider),
+ );
+ final position = boundaries.scrollControllerNotifier.value!.position;
+ final header = tester.widget<AlbumCoverAppBar>(
+ find.byType(AlbumCoverAppBar),
+ );
+ final geometry = AlbumCoverAppBar.resolveGeometry(
+ tester.element(find.byType(AlbumCoverAppBar)),
+ collapsedHeight: header.collapsedHeight,
+ bottomHeight: header.bottom?.preferredSize.height ?? 0,
+ );
+ expect(position.maxScrollExtent, closeTo(geometry.collapseExtent, 0.01));
+ await tester.drag(find.byType(CustomScrollView), const Offset(0, -160));
+ await tester.pumpAndSettle();
+ expect(position.pixels, closeTo(geometry.collapseExtent, 0.01));
+ expect(tester.takeException(), isNull);
+ await _disposeAlbum(tester);
+ });
+
testWidgets("uses a pending local photo and excludes ignored photos", (
tester,
) async {
@@ -522,7 +576,88 @@ void main() {
(widget) => widget is Hero && widget.tag == heroTag,
),
);
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 75));
+ final headerHero = find.descendant(
+ of: find.byType(AlbumCoverAppBar),
+ matching: find.byType(Hero),
+ );
+ final provider = InheritedSearchFilterData.of(
+ tester.element(headerHero),
+ ).searchFilterDataProvider!;
+ void refreshRecommendations() => provider.clearAndAddRecommendations([
+ FaceFilter(
+ personId: null,
+ clusterId: "hero-cluster",
+ faceName: "Person",
+ faceFile: newest,
+ occurrence: 2,
+ ),
+ for (var i = 0; i < 12; i++)
+ CameraFilter(cameraModel: "Camera ${i % 10}", occurrence: 1),
+ ]);
+ var notifications = 0;
+ provider.addListener(
+ toRecommended: true,
+ listener: () => notifications++,
+ );
+ refreshRecommendations();
+ expect(notifications, 1);
+ await tester.pump();
+ final carousel = find.byType(AppBarFilterChips);
+ final face = find.byType(PersonFaceWidget);
+ final faceElement = tester.element(face);
+ final coverImage = find.descendant(
+ of: headerHero,
+ matching: find.byType(Image, skipOffstage: false),
+ skipOffstage: false,
+ );
+ final coverImageElement = tester.element(coverImage);
+ expect(
+ find.descendant(of: headerHero, matching: find.byType(Image)),
+ findsNothing,
+ );
+ expect(
+ find.descendant(of: flightClip, matching: carousel),
+ findsOneWidget,
+ );
+ final carouselFade = find
+ .descendant(of: carousel, matching: find.byType(FadeTransition))
+ .first;
+ expect(tester.widget<FadeTransition>(carouselFade).opacity.value, 0);
+ await tester.pump(const Duration(milliseconds: 50));
+ expect(
+ tester.widget<FadeTransition>(carouselFade).opacity.value,
+ inExclusiveRange(0, 1),
+ );
+ final shuttleFade = find
+ .ancestor(of: flightClip, matching: find.byType(FadeTransition))
+ .first;
+ expect(tester.widget<FadeTransition>(shuttleFade).opacity.value, 1);
+ await tester.pumpAndSettle();
+ expect(tester.element(coverImage), same(coverImageElement));
+ expect(tester.element(face), same(faceElement));
+ final beforeRefresh = notifications;
+ refreshRecommendations();
+ expect(notifications, beforeRefresh + 1);
await tester.pumpAndSettle();
+ expect(tester.element(face), same(faceElement));
+ final carouselScroll = tester.state<ScrollableState>(
+ find.descendant(of: carousel, matching: find.byType(Scrollable)),
+ );
+ carouselScroll.position.jumpTo(60);
+ final galleryScroll = tester
+ .state<GalleryBoundariesProviderState>(
+ find.byType(GalleryBoundariesProvider),
+ )
+ .scrollControllerNotifier
+ .value!;
+ for (final offset in [120.0, 0.0]) {
+ galleryScroll.jumpTo(offset);
+ await tester.pump();
+ expect(tester.element(face), same(faceElement));
+ expect(carouselScroll.position.pixels, 60);
+ }
await _expectCover(tester, newest, count: 2);
expect(
find.descendant(
@@ -531,10 +666,7 @@ void main() {
),
findsOneWidget,
);
- final headerHero = find.descendant(
- of: find.byType(AlbumCoverAppBar),
- matching: find.byType(Hero),
- );
+
expect(tester.widget<Hero>(headerHero).tag, heroTag);
collection.pubMagicMetadata = CollectionPubMagicMetadata(asc: true);
@@ -562,13 +694,146 @@ void main() {
);
expect(tester.widget<Hero>(albumHero).tag, heroTag);
+ await tester.timedDragFrom(
+ const Offset(1, 300),
+ const Offset(80, 0),
+ const Duration(seconds: 1),
+ );
+ await tester.pumpAndSettle();
+ expect(tester.element(face), same(faceElement));
+ expect(carouselScroll.position.pixels, 60);
Navigator.of(tester.element(find.byType(CollectionPage))).pop();
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 40));
+ expect(
+ find.descendant(of: flightClip, matching: carousel),
+ findsOneWidget,
+ );
+ expect(tester.element(face), same(faceElement));
+ expect(
+ tester.widget<ClipSmoothRect>(flightClip).radius.topLeft.x,
+ inExclusiveRange(0, 20),
+ );
await tester.pumpAndSettle();
expect(find.byType(AlbumRowItemWidget), findsOneWidget);
expect(tester.takeException(), isNull);
await _disposeAlbum(tester);
},
);
+ testWidgets(
+ "retries failed faces on refresh without reloading loaded faces",
+ (tester) async {
+ EntePhotosRust.initMock(api: _FakePhotosRustApi());
+ MLDataDB.initialize(preferRust: false);
+ Future<void> cacheFace(String cluster, int id) async {
+ final face = Face.empty(id);
+ await cachedFaceCropPath(
+ face.faceID,
+ false,
+ ).writeAsBytes(base64Decode(_onePixelPng));
+ await getCachedFaceCrops(
+ _file(id),
+ [face],
+ personOrClusterID: cluster,
+ useTempCache: false,
+ );
+ }
+
+ await tester.runAsync(() => cacheFace("loaded-cluster", 901));
+ final provider = SearchFilterDataProvider(
+ initialGalleryFilter: CameraFilter(
+ cameraModel: "initial",
+ occurrence: 100,
+ ),
+ );
+ addTearDown(provider.dispose);
+ void refresh() => provider.clearAndAddRecommendations([
+ for (final cluster in ["loaded-cluster", "failed-cluster"])
+ FaceFilter(
+ personId: null,
+ clusterId: cluster,
+ faceName: null,
+ faceFile: null,
+ occurrence: 1,
+ ),
+ ]);
+ refresh();
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: lightThemeData,
+ localizationsDelegates: StringsLocalizations.localizationsDelegates,
+ supportedLocales: StringsLocalizations.supportedLocales,
+ home: Scaffold(
+ body: InheritedSearchFilterData(
+ searchFilterDataProvider: provider,
+ child: const AppBarFilterChips(animateRecommendations: true),
+ ),
+ ),
+ ),
+ );
+ Finder face(String cluster) => find.byWidgetPredicate(
+ (widget) => widget is PersonFaceWidget && widget.clusterID == cluster,
+ );
+ Future<Uint8List?>? future(String cluster) => tester
+ .widget<FutureBuilder<Uint8List?>>(
+ find.descendant(
+ of: face(cluster),
+ matching: find.byType(FutureBuilder<Uint8List?>),
+ ),
+ )
+ .future;
+ Future<void> settleFaces(int imageCount) async {
+ await tester.runAsync(() async {
+ for (var i = 0; i < 100; i++) {
+ await tester.pump();
+ final images = tester.widgetList<RawImage>(find.byType(RawImage));
+ if (find.byType(EnteLoadingWidget).evaluate().isEmpty &&
+ images.length == imageCount &&
+ images.every((image) => image.image != null)) {
+ return;
+ }
+ await Future<void>.delayed(const Duration(milliseconds: 10));
+ }
+ });
+ expect(find.byType(EnteLoadingWidget), findsNothing);
+ expect(find.byType(RawImage), findsNWidgets(imageCount));
+ }
+
+ await settleFaces(1);
+ final loadedElement = tester.element(face("loaded-cluster"));
+ final loadedFuture = future("loaded-cluster");
+ final failedFuture = future("failed-cluster");
+ final loadedImage = tester.widget<RawImage>(find.byType(RawImage)).image;
+ await tester.runAsync(() => cacheFace("failed-cluster", 902));
+ refresh();
+ await tester.pump();
+ expect(tester.element(face("loaded-cluster")), same(loadedElement));
+ expect(future("loaded-cluster"), same(loadedFuture));
+ expect(future("failed-cluster"), isNot(same(failedFuture)));
+ expect(
+ tester
+ .widget<RawImage>(
+ find.descendant(
+ of: face("loaded-cluster"),
+ matching: find.byType(RawImage),
+ ),
+ )
+ .image,
+ same(loadedImage),
+ );
+ await settleFaces(2);
+ final recoveredFuture = future("failed-cluster");
+ refresh();
+ await tester.pump();
+ expect(future("loaded-cluster"), same(loadedFuture));
+ expect(future("failed-cluster"), same(recoveredFuture));
+ expect(
+ tester.widget<AnimatedOpacity>(find.byType(AnimatedOpacity)).opacity,
+ 1,
+ );
+ await _disposeAlbum(tester);
+ },
+ );
}
Collection _collection() => Collection(
@@ -693,3 +958,8 @@ class _FakePathProvider extends PathProviderPlatform {
const _onePixelPng =
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";
+
+class _FakePhotosRustApi extends Fake implements EntePhotosRustApi {
+ @override
+ bool crateApiMlDbApiDecideMlDbBackend({required bool preferRust}) => false;
+}
diff --git a/mobile/packages/ente_components/lib/components/app_bar_component.dart b/mobile/packages/ente_components/lib/components/app_bar_component.dart
index b9a72d9cde..57801693f6 100644
--- a/mobile/packages/ente_components/lib/components/app_bar_component.dart
+++ b/mobile/packages/ente_components/lib/components/app_bar_component.dart
@@ -253,15 +253,15 @@ class _AppBarComponentState extends State<AppBarComponent> {
showExpandedBackButton: widget.showExpandedBackButton,
),
...widget.slivers,
- _AppBarCollapseSpacer(collapseExtent: metrics.collapseExtent),
+ AppBarCollapseSpacer(collapseExtent: metrics.collapseExtent),
],
),
);
}
}
-class _AppBarCollapseSpacer extends StatelessWidget {
- const _AppBarCollapseSpacer({required this.collapseExtent});
+class AppBarCollapseSpacer extends StatelessWidget {
+ const AppBarCollapseSpacer({super.key, required this.collapseExtent});
final double collapseExtent;