Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use self-sizing search tab rows

ashilkna2b50bfee187
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/contacts_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/contacts_section.dart
index ed204ce066..7406561efc 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/contacts_section.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/contacts_section.dart
@@ -166,20 +166,16 @@ class _ContactsSectionState extends State<ContactsSection> {
(_contactSearchResults.length >= kSearchSectionLimit - 1),
),
const SizedBox(height: 4),
- SearchTabHorizontalListView(
- height: ContactRecommendation.heightFor(context),
- itemCount: _contactSearchResults.length + 1,
- itemBuilder: (context, index) {
- if (index == _contactSearchResults.length) {
- return const ContactCTA();
- }
- final contactSearchResult = _contactSearchResults[index];
- return ContactRecommendation(
- contactSearchResult,
- key: ValueKey(contactSearchResult.name()),
- );
- },
- separatorBuilder: (context, index) => const SizedBox(width: 12),
+ SearchTabHorizontalRow(
+ spacing: 12,
+ children: [
+ for (final contactSearchResult in _contactSearchResults)
+ ContactRecommendation(
+ contactSearchResult,
+ key: ValueKey(contactSearchResult.name()),
+ ),
+ const ContactCTA(),
+ ],
),
],
),
@@ -190,19 +186,11 @@ class _ContactsSectionState extends State<ContactsSection> {
class ContactRecommendation extends StatefulWidget {
static const _avatarSize = 62.0;
- static const _height = 92.0;
+ static const _minHeight = 92.0;
final GenericSearchResult contactSearchResult;
const ContactRecommendation(this.contactSearchResult, {super.key});
- static double heightFor(BuildContext context) {
- return (_avatarSize +
- 10 +
- searchTabSingleLineTextHeight(context, TextStyles.mini))
- .clamp(_height, double.infinity)
- .toDouble();
- }
-
@override
State<ContactRecommendation> createState() => _ContactRecommendationState();
}
@@ -226,32 +214,38 @@ class _ContactRecommendationState extends State<ContactRecommendation> {
routeToPage(context, ContactResultPage(widget.contactSearchResult));
}
},
- child: SizedBox(
- width: 92,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- ClipOval(
- child: SizedBox(
- width: ContactRecommendation._avatarSize,
- height: ContactRecommendation._avatarSize,
- child: ContactAvatarWidget(
- contactUserId: contactUserId,
- email: contactEmail,
- personId: personId,
- size: ContactRecommendation._avatarSize,
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(
+ minHeight: ContactRecommendation._minHeight,
+ ),
+ child: SizedBox(
+ width: 92,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ ClipOval(
+ child: SizedBox(
+ width: ContactRecommendation._avatarSize,
+ height: ContactRecommendation._avatarSize,
+ child: ContactAvatarWidget(
+ contactUserId: contactUserId,
+ email: contactEmail,
+ personId: personId,
+ size: ContactRecommendation._avatarSize,
+ ),
),
),
- ),
- const SizedBox(height: 10),
- Text(
- widget.contactSearchResult.name(),
- style: TextStyles.mini.copyWith(color: colors.textBase),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- textAlign: TextAlign.center,
- ),
- ],
+ const SizedBox(height: 10),
+ Text(
+ widget.contactSearchResult.name(),
+ style: TextStyles.mini.copyWith(color: colors.textBase),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ textAlign: TextAlign.center,
+ ),
+ ],
+ ),
),
),
);
@@ -272,6 +266,7 @@ class ContactCTA extends StatelessWidget {
child: SizedBox(
width: 62,
child: Column(
+ mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/file_type_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/file_type_section.dart
index 99c94a055c..7ece8e64ed 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/file_type_section.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/file_type_section.dart
@@ -70,13 +70,11 @@ class FileTypeSection extends StatelessWidget {
children: [
const SectionHeader(SectionType.fileTypesAndExtension, hasMore: true),
const SizedBox(height: 8),
- SearchTabHorizontalListView(
- height: _FileTypeCard.heightFor(context),
- itemCount: previewTiles.length,
- itemBuilder: (context, index) {
- return _FileTypeRecommendation(previewTiles[index]);
- },
- separatorBuilder: (context, index) => const SizedBox(width: 10),
+ SearchTabHorizontalRow(
+ spacing: 10,
+ children: [
+ for (final tile in previewTiles) _FileTypeRecommendation(tile),
+ ],
),
],
),
@@ -200,7 +198,7 @@ class _FileTypeCard extends StatelessWidget {
const _FileTypeCard(this.tile);
- static double heightFor(BuildContext context) {
+ static double _heightFor(BuildContext context) {
return (_labelTop +
searchTabSingleLineTextHeight(context, _labelStyle(Colors.black)) +
_labelBottomPadding)
@@ -211,7 +209,7 @@ class _FileTypeCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
- final height = heightFor(context);
+ final height = _heightFor(context);
return CustomPaint(
painter: _FileTypeCardBackgroundPainter(colorScheme.fill),
child: SizedBox(
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
index 6c30036ab6..970b5fbf1c 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
@@ -113,18 +113,13 @@ class _LocationsSectionState extends State<LocationsSection> {
(_locationsSearchResults.length >= kSearchSectionLimit - 1),
),
const SizedBox(height: 4),
- SearchTabHorizontalListView(
- height: LocationRecommendation.heightFor(context),
- itemCount: _locationsSearchResults.length + 1,
- itemBuilder: (context, index) {
- if (index == 0) {
- return const GoToMapTile();
- }
- return LocationRecommendation(
- _locationsSearchResults[index - 1],
- );
- },
- separatorBuilder: (context, index) => const SizedBox(width: 10),
+ SearchTabHorizontalRow(
+ spacing: 10,
+ children: [
+ const GoToMapTile(),
+ for (final locationSearchResult in _locationsSearchResults)
+ LocationRecommendation(locationSearchResult),
+ ],
),
],
),
@@ -135,23 +130,13 @@ class _LocationsSectionState extends State<LocationsSection> {
class LocationRecommendation extends StatelessWidget {
static const width = 108.0;
- static const _height = 158.0;
+ static const _minHeight = 158.0;
static const outerCornerRadius = 20.0;
static const cornerSmoothing = 1.0;
static const sideOfThumbnail = 108.0;
final GenericSearchResult locationSearchResult;
const LocationRecommendation(this.locationSearchResult, {super.key});
- static double heightFor(BuildContext context) {
- return (sideOfThumbnail +
- 8 +
- searchTabSingleLineTextHeight(context, TextStyles.body) +
- 2 +
- searchTabSingleLineTextHeight(context, TextStyles.mini))
- .clamp(_height, double.infinity)
- .toDouble();
- }
-
@override
Widget build(BuildContext context) {
final heroTag =
@@ -168,87 +153,91 @@ class LocationRecommendation extends StatelessWidget {
}
},
child: RepaintBoundary(
- child: SizedBox(
- width: width,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Stack(
- children: [
- ClipSmoothRect(
- radius: SmoothBorderRadius(
- cornerRadius: outerCornerRadius,
- cornerSmoothing: cornerSmoothing,
- ),
- child: SizedBox(
- width: sideOfThumbnail,
- height: sideOfThumbnail,
- child: locationSearchResult.previewThumbnail() != null
- ? Hero(
- tag: heroTag,
- child: ThumbnailWidget(
- locationSearchResult.previewThumbnail()!,
- shouldShowSyncStatus: false,
- shouldShowFavoriteIcon: false,
- ),
- )
- : const NoThumbnailWidget(),
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(minHeight: _minHeight),
+ child: SizedBox(
+ width: width,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Stack(
+ children: [
+ ClipSmoothRect(
+ radius: SmoothBorderRadius(
+ cornerRadius: outerCornerRadius,
+ cornerSmoothing: cornerSmoothing,
+ ),
+ child: SizedBox(
+ width: sideOfThumbnail,
+ height: sideOfThumbnail,
+ child: locationSearchResult.previewThumbnail() != null
+ ? Hero(
+ tag: heroTag,
+ child: ThumbnailWidget(
+ locationSearchResult.previewThumbnail()!,
+ shouldShowSyncStatus: false,
+ shouldShowFavoriteIcon: false,
+ ),
+ )
+ : const NoThumbnailWidget(),
+ ),
),
- ),
- Positioned(
- left: 8,
- bottom: 8,
- child: Stack(
- clipBehavior: Clip.none,
- alignment: Alignment.center,
- children: [
- ClipOval(
- child: Container(
- color: const Color.fromRGBO(0, 0, 0, 0.6),
- width: 15,
- height: 15,
+ Positioned(
+ left: 8,
+ bottom: 8,
+ child: Stack(
+ clipBehavior: Clip.none,
+ alignment: Alignment.center,
+ children: [
+ ClipOval(
+ child: Container(
+ color: const Color.fromRGBO(0, 0, 0, 0.6),
+ width: 15,
+ height: 15,
+ ),
),
- ),
- Container(
- width: 16,
- height: 16,
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- border: Border.all(
- width: 0.5,
- color: strokeSolidMutedLight,
+ Container(
+ width: 16,
+ height: 16,
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ border: Border.all(
+ width: 0.5,
+ color: strokeSolidMutedLight,
+ ),
),
),
- ),
- const Icon(
- Icons.location_on_sharp,
- color: Colors.white,
- size: 11,
- ),
- ],
+ const Icon(
+ Icons.location_on_sharp,
+ color: Colors.white,
+ size: 11,
+ ),
+ ],
+ ),
),
+ ],
+ ),
+ const SizedBox(height: 8),
+ Text(
+ locationSearchResult.name(),
+ style: TextStyles.body.copyWith(color: textTheme.body.color),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ ),
+ const SizedBox(height: 2),
+ Text(
+ AppLocalizations.of(
+ context,
+ ).itemCount(count: locationSearchResult.fileCount()),
+ style: TextStyles.mini.copyWith(
+ color: textTheme.miniMuted.color,
),
- ],
- ),
- const SizedBox(height: 8),
- Text(
- locationSearchResult.name(),
- style: TextStyles.body.copyWith(color: textTheme.body.color),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ),
- const SizedBox(height: 2),
- Text(
- AppLocalizations.of(
- context,
- ).itemCount(count: locationSearchResult.fileCount()),
- style: TextStyles.mini.copyWith(
- color: textTheme.miniMuted.color,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ),
- ],
+ ],
+ ),
),
),
),
@@ -270,6 +259,7 @@ class GoToMapTile extends StatelessWidget {
child: SizedBox(
width: LocationRecommendation.width,
child: Column(
+ mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipSmoothRect(
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/magic_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/magic_section.dart
index d530c02c50..da930de87f 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/magic_section.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/magic_section.dart
@@ -108,13 +108,12 @@ class _MagicSectionState extends State<MagicSection> {
hasMore: (_magicSearchResults.length >= kSearchSectionLimit - 1),
),
const SizedBox(height: 4),
- SearchTabHorizontalListView(
- height: MagicRecommendation.heightFor(context),
- itemCount: _magicSearchResults.length,
- itemBuilder: (context, index) {
- return MagicRecommendation(_magicSearchResults[index]);
- },
- separatorBuilder: (context, index) => const SizedBox(width: 10),
+ SearchTabHorizontalRow(
+ spacing: 10,
+ children: [
+ for (final magicSearchResult in _magicSearchResults)
+ MagicRecommendation(magicSearchResult),
+ ],
),
],
),
@@ -125,23 +124,13 @@ class _MagicSectionState extends State<MagicSection> {
class MagicRecommendation extends StatelessWidget {
static const _width = 108.0;
- static const _height = 158.0;
+ static const _minHeight = 158.0;
static const _thumbnailSize = 108.0;
static const _cornerRadius = 20.0;
static const _cornerSmoothing = 1.0;
final GenericSearchResult magicSearchResult;
const MagicRecommendation(this.magicSearchResult, {super.key});
- static double heightFor(BuildContext context) {
- return (_thumbnailSize +
- 8 +
- searchTabSingleLineTextHeight(context, TextStyles.body) +
- 2 +
- searchTabSingleLineTextHeight(context, TextStyles.mini))
- .clamp(_height, double.infinity)
- .toDouble();
- }
-
@override
Widget build(BuildContext context) {
final heroTag =
@@ -154,47 +143,53 @@ class MagicRecommendation extends StatelessWidget {
magicSearchResult.onResultTap!(context);
},
- child: SizedBox(
- width: _width,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- ClipSmoothRect(
- radius: SmoothBorderRadius(
- cornerRadius: _cornerRadius,
- cornerSmoothing: _cornerSmoothing,
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(minHeight: _minHeight),
+ child: SizedBox(
+ width: _width,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ ClipSmoothRect(
+ radius: SmoothBorderRadius(
+ cornerRadius: _cornerRadius,
+ cornerSmoothing: _cornerSmoothing,
+ ),
+ child: SizedBox(
+ width: _thumbnailSize,
+ height: _thumbnailSize,
+ child: magicSearchResult.previewThumbnail() != null
+ ? Hero(
+ tag: heroTag,
+ child: ThumbnailWidget(
+ magicSearchResult.previewThumbnail()!,
+ shouldShowSyncStatus: false,
+ ),
+ )
+ : const NoThumbnailWidget(),
+ ),
),
- child: SizedBox(
- width: _thumbnailSize,
- height: _thumbnailSize,
- child: magicSearchResult.previewThumbnail() != null
- ? Hero(
- tag: heroTag,
- child: ThumbnailWidget(
- magicSearchResult.previewThumbnail()!,
- shouldShowSyncStatus: false,
- ),
- )
- : const NoThumbnailWidget(),
+ const SizedBox(height: 8),
+ Text(
+ magicSearchResult.name(),
+ style: TextStyles.body.copyWith(color: textTheme.body.color),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
),
- ),
- const SizedBox(height: 8),
- Text(
- magicSearchResult.name(),
- style: TextStyles.body.copyWith(color: textTheme.body.color),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ),
- const SizedBox(height: 2),
- Text(
- AppLocalizations.of(
- context,
- ).itemCount(count: magicSearchResult.fileCount()),
- style: TextStyles.mini.copyWith(color: textTheme.miniMuted.color),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ),
- ],
+ const SizedBox(height: 2),
+ Text(
+ AppLocalizations.of(
+ context,
+ ).itemCount(count: magicSearchResult.fileCount()),
+ style: TextStyles.mini.copyWith(
+ color: textTheme.miniMuted.color,
+ ),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ ),
+ ],
+ ),
),
),
);
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart
index 250bfdd335..ec8515be3d 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart
@@ -1,5 +1,4 @@
import "dart:async";
-import "dart:math" as math;
import "package:ente_components/theme/text_styles.dart";
import "package:ente_pure_utils/ente_pure_utils.dart";
@@ -140,6 +139,8 @@ class _PeopleSectionState extends State<PeopleSection> {
}
class SearchExampleRow extends StatelessWidget {
+ static const _minTileHeight = 158.0;
+
final SectionType sectionType;
final List<GenericSearchResult> examples;
@@ -147,16 +148,18 @@ class SearchExampleRow extends StatelessWidget {
@override
Widget build(BuildContext context) {
- return SearchTabHorizontalListView(
- height: PersonSearchExample.heightFor(context),
- itemCount: examples.length,
- itemBuilder: (context, index) {
- return PersonSearchExample(
- searchResult: examples[index],
- selectedPeople: null,
- );
- },
- separatorBuilder: (context, index) => const SizedBox(width: 10),
+ return SearchTabHorizontalRow(
+ spacing: 10,
+ children: [
+ for (final example in examples)
+ ConstrainedBox(
+ constraints: const BoxConstraints(minHeight: _minTileHeight),
+ child: PersonSearchExample(
+ searchResult: example,
+ selectedPeople: null,
+ ),
+ ),
+ ],
);
}
}
@@ -173,18 +176,6 @@ class PersonSearchExample extends StatelessWidget {
this.size = 108,
});
- static double heightFor(BuildContext context, {double size = 108}) {
- final labelHeight =
- size +
- 8 +
- searchTabSingleLineTextHeight(context, TextStyles.body) +
- 2 +
- searchTabSingleLineTextHeight(context, TextStyles.mini);
- final clusterLabelHeight =
- size + 6 + searchTabSingleLineTextHeight(context, TextStyles.body);
- return math.max(158, math.max(labelHeight, clusterLabelHeight));
- }
-
void toggleSelection() {
selectedPeople?.toggleSelection(
searchResult.params[kPersonParamID]! as String,
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab_horizontal_scroll.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab_horizontal_scroll.dart
index cca266f629..b6450c54e6 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab_horizontal_scroll.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab_horizontal_scroll.dart
@@ -11,37 +11,42 @@ double searchTabSingleLineTextHeight(BuildContext context, TextStyle style) {
return textPainter.height;
}
-class SearchTabHorizontalListView extends StatelessWidget {
- const SearchTabHorizontalListView({
- required this.height,
- required this.itemCount,
- required this.itemBuilder,
- required this.separatorBuilder,
+class SearchTabHorizontalRow extends StatelessWidget {
+ const SearchTabHorizontalRow({
+ required this.children,
+ required this.spacing,
super.key,
});
- final double height;
- final int itemCount;
- final IndexedWidgetBuilder itemBuilder;
- final IndexedWidgetBuilder separatorBuilder;
+ final List<Widget> children;
+ final double spacing;
@override
Widget build(BuildContext context) {
return _SearchTabHorizontalViewport(
- height: height,
- child: ListView.separated(
+ child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(
horizontal: searchTabHorizontalPadding,
),
physics: const BouncingScrollPhysics(),
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
scrollDirection: Axis.horizontal,
- itemCount: itemCount,
- itemBuilder: itemBuilder,
- separatorBuilder: separatorBuilder,
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: _spacedChildren(),
+ ),
),
);
}
+
+ List<Widget> _spacedChildren() {
+ return [
+ for (final (index, child) in children.indexed) ...[
+ if (index != 0) SizedBox(width: spacing),
+ child,
+ ],
+ ];
+ }
}
class SearchTabHorizontalScrollView extends StatelessWidget {
@@ -56,45 +61,37 @@ class SearchTabHorizontalScrollView extends StatelessWidget {
@override
Widget build(BuildContext context) {
- return _SearchTabHorizontalViewport(
+ return SizedBox(
height: height,
- child: SingleChildScrollView(
- padding: const EdgeInsets.symmetric(
- horizontal: searchTabHorizontalPadding,
+ child: _SearchTabHorizontalViewport(
+ child: SingleChildScrollView(
+ padding: const EdgeInsets.symmetric(
+ horizontal: searchTabHorizontalPadding,
+ ),
+ physics: const BouncingScrollPhysics(),
+ keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
+ scrollDirection: Axis.horizontal,
+ child: child,
),
- physics: const BouncingScrollPhysics(),
- keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
- scrollDirection: Axis.horizontal,
- child: child,
),
);
}
}
class _SearchTabHorizontalViewport extends StatelessWidget {
- const _SearchTabHorizontalViewport({
- required this.height,
- required this.child,
- });
+ const _SearchTabHorizontalViewport({required this.child});
- final double height;
final Widget child;
@override
Widget build(BuildContext context) {
- return SizedBox(
- height: height,
- child: LayoutBuilder(
- builder: (context, constraints) {
- final width = constraints.maxWidth + (searchTabHorizontalPadding * 2);
- return OverflowBox(
- minWidth: width,
- maxWidth: width,
- alignment: Alignment.center,
- child: SizedBox(width: width, height: height, child: child),
- );
- },
- ),
+ return LayoutBuilder(
+ builder: (context, constraints) {
+ final widthFactor =
+ (constraints.maxWidth + (searchTabHorizontalPadding * 2)) /
+ constraints.maxWidth;
+ return FractionallySizedBox(widthFactor: widthFactor, child: child);
+ },
);
}
}