π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Fix contact suggestion edge artifacts (#13273)
aman-pilotc6bf5c1ebbca
diff --git a/mobile/apps/photos/changes/contact-suggestion-edge-fade.md b/mobile/apps/photos/changes/contact-suggestion-edge-fade.mdnew file mode 100644index 0000000000..9825e1f6bd--- /dev/null+++ b/mobile/apps/photos/changes/contact-suggestion-edge-fade.md@@ -0,0 +1,2 @@+- Fixed visual artifacts and extra leading space in suggested contacts when adding people to an album.+- Contact arrows now scroll three people at a time, and searches with no matches show an empty state without collapsing the sheet.diff --git a/mobile/apps/photos/lib/ui/sharing/add_people_sheet.dart b/mobile/apps/photos/lib/ui/sharing/add_people_sheet.dartindex 81386566d4..a3db614bda 100644--- a/mobile/apps/photos/lib/ui/sharing/add_people_sheet.dart+++ b/mobile/apps/photos/lib/ui/sharing/add_people_sheet.dart@@ -193,7 +193,7 @@ class _AddPeopleSheetState extends State<_AddPeopleSheet> {onSubmit: _tryAddTypedEmail,onShareLink: _sharePublicLink,),- if (availableContacts.isNotEmpty) ...[+ if (availableContacts.isNotEmpty || query.isNotEmpty) ...[const SizedBox(height: Spacing.xl),_ContactSuggestions(contacts: availableContacts,@@ -513,10 +513,36 @@ class _ContactSuggestionsState extends State<_ContactSuggestions> {@overrideWidget build(BuildContext context) {final rowExtent = _ContactSuggestions.rowExtent(context);+ if (widget.contacts.isEmpty) {+ return SizedBox(+ height: rowExtent,+ width: double.infinity,+ child: Center(+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ HugeIcon(+ icon: HugeIcons.strokeRoundedAlert02,+ size: 33,+ color: context.componentColors.textLighter,+ ),+ const SizedBox(height: Spacing.sm),+ Text(+ context.strings.noMatchingResultsFound,+ textAlign: TextAlign.center,+ style: TextStyles.body.copyWith(+ color: context.componentColors.textLight,+ ),+ ),+ ],+ ),+ ),+ );+ }final avatarSize = getAvatarSize(AvatarType.huge);const arrowSize = 36.0;final itemWidth = avatarSize + Spacing.lg;- final scrollStep = itemWidth + Spacing.lg;+ final scrollStep = (itemWidth + Spacing.lg) * 3;return SizedBox(height: rowExtent,@@ -533,47 +559,76 @@ class _ContactSuggestionsState extends State<_ContactSuggestions> {child: Stack(children: [Positioned.fill(- child: ShaderMask(- blendMode: BlendMode.dstIn,- shaderCallback: (bounds) {- final fadeStop = (arrowSize / bounds.width).clamp(0.0, 0.5);- return LinearGradient(- colors: const [- Colors.transparent,- Colors.black,- Colors.black,- Colors.transparent,- ],- stops: [0, fadeStop, 1 - fadeStop, 1],- ).createShader(bounds);+ child: ListView.separated(+ key: const ValueKey("contact-suggestions-scroll"),+ controller: widget.scrollController,+ primary: false,+ scrollDirection: Axis.horizontal,+ padding: const EdgeInsetsDirectional.only(end: arrowSize),+ itemCount: widget.contacts.length,+ itemBuilder: (context, index) {+ final contact = widget.contacts[index];+ return SizedBox(+ width: itemWidth,+ child: _ContactSuggestion(+ key: ValueKey(+ "contact-${contact.email.trim().toLowerCase()}",+ ),+ suggestion: contact,+ onTap: () => widget.onToggle(contact),+ onLongPress: () => showVerifyIdentitySheet(+ context,+ self: false,+ email: contact.email,+ ),+ ),+ );},- child: ListView.separated(- key: const ValueKey("contact-suggestions-scroll"),- controller: widget.scrollController,- primary: false,- scrollDirection: Axis.horizontal,- padding: const EdgeInsets.symmetric(horizontal: arrowSize),- itemCount: widget.contacts.length,- itemBuilder: (context, index) {- final contact = widget.contacts[index];- return SizedBox(- width: itemWidth,- child: _ContactSuggestion(- key: ValueKey(- "contact-${contact.email.trim().toLowerCase()}",- ),- suggestion: contact,- onTap: () => widget.onToggle(contact),- onLongPress: () => showVerifyIdentitySheet(- context,- self: false,- email: contact.email,- ),+ separatorBuilder: (_, _) => const SizedBox(width: Spacing.lg),+ ),+ ),+ if (_canScrollBack)+ PositionedDirectional(+ start: 0,+ top: 0,+ bottom: 0,+ width: arrowSize,+ child: IgnorePointer(+ child: DecoratedBox(+ decoration: BoxDecoration(+ gradient: LinearGradient(+ begin: AlignmentDirectional.centerStart,+ end: AlignmentDirectional.centerEnd,+ colors: [+ context.componentColors.backgroundBase,+ context.componentColors.backgroundBase.withValues(+ alpha: 0,+ ),+ ],),- );- },- separatorBuilder: (_, _) =>- const SizedBox(width: Spacing.lg),+ ),+ ),+ ),+ ),+ PositionedDirectional(+ end: 0,+ top: 0,+ bottom: 0,+ width: arrowSize,+ child: IgnorePointer(+ child: DecoratedBox(+ decoration: BoxDecoration(+ gradient: LinearGradient(+ begin: AlignmentDirectional.centerStart,+ end: AlignmentDirectional.centerEnd,+ colors: [+ context.componentColors.backgroundBase.withValues(+ alpha: 0,+ ),+ context.componentColors.backgroundBase,+ ],+ ),+ ),),),),diff --git a/mobile/apps/photos/test/ui/sharing/add_people_sheet_test.dart b/mobile/apps/photos/test/ui/sharing/add_people_sheet_test.dartnew file mode 100644index 0000000000..04d24548bf--- /dev/null+++ b/mobile/apps/photos/test/ui/sharing/add_people_sheet_test.dart@@ -0,0 +1,199 @@+import 'dart:convert';++import 'package:dio/dio.dart';+import 'package:ente_strings/ente_strings.dart';+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:package_info_plus/package_info_plus.dart';+import 'package:photos/core/configuration.dart';+import 'package:photos/db/ml/base.dart';+import 'package:photos/ente_theme_data.dart';+import 'package:photos/service_locator.dart';+import 'package:photos/services/account/user_service.dart';+import 'package:photos/services/entity_service.dart';+import 'package:photos/services/machine_learning/face_ml/person/person_service.dart';+import 'package:photos/ui/sharing/add_people_sheet.dart';+import 'package:shared_preferences/shared_preferences.dart';++import 'library_sharing_test_helpers.dart';++void main() {+ TestWidgetsFlutterBinding.ensureInitialized();++ setUpAll(() async {+ SharedPreferences.setMockInitialValues({+ Configuration.userIDKey: 1,+ Configuration.emailKey: '[email protected]',+ UserService.keyUserDetails: jsonEncode({+ 'email': '[email protected]',+ 'usage': 0,+ 'subscription': {+ 'productID': 'free',+ 'storage': 0,+ 'originalTransactionID': '',+ 'paymentProvider': '',+ 'expiryTime': 0,+ 'price': '',+ 'period': '',+ },+ 'familyData': {+ 'storage': 0,+ 'expiryTime': 0,+ 'members': List.generate(+ 8,+ (index) => {+ 'id': '$index',+ 'email': '[email protected]',+ 'isAdmin': false,+ },+ ),+ },+ }),+ });+ final preferences = await SharedPreferences.getInstance();+ ServiceLocator.instance.init(+ preferences,+ Dio(),+ Dio(),+ Dio(),+ PackageInfo(+ appName: 'Photos',+ packageName: 'photos',+ version: '1.0.0',+ buildNumber: '1',+ ),+ );+ // Only preferences are needed; native plugins are unavailable in this test.+ try {+ await Configuration.instance.init(preferences);+ } catch (_) {}+ await UserService.instance.init();+ PersonService.init(_FakeEntityService(), _FakeMLDataDB(), preferences);+ });++ testWidgets(+ 'contacts start at the sheet inset and fade only after scrolling',+ (tester) async {+ await _openSheet(tester);++ final row = find.byKey(const ValueKey('contact-suggestions-scroll'));+ final first = find.byKey(+ const ValueKey('[email protected]'),+ );+ final leftFade = find.byWidgetPredicate(+ (widget) =>+ widget is PositionedDirectional &&+ widget.start == 0 &&+ widget.child is IgnorePointer,+ );+ expect(tester.getTopLeft(first).dx, tester.getTopLeft(row).dx);+ expect(leftFade, findsNothing);+ expect(find.byTooltip('Previous'), findsNothing);++ await tester.drag(row, const Offset(-120, 0));+ await tester.pumpAndSettle();+ expect(leftFade, findsOneWidget);+ expect(find.byTooltip('Previous'), findsOneWidget);++ await tester.drag(row, const Offset(500, 0));+ await tester.pumpAndSettle();+ expect(leftFade, findsNothing);+ expect(tester.getTopLeft(first).dx, tester.getTopLeft(row).dx);+ await tester.pumpWidget(const SizedBox.shrink());+ },+ );+ testWidgets('chevrons advance three contacts and clamp at the ends', (+ tester,+ ) async {+ await _openSheet(tester);+ final row = find.byKey(const ValueKey('contact-suggestions-scroll'));+ final controller = tester.widget<ListView>(row).controller!;++ await tester.tap(find.byTooltip('Next'));+ await tester.pumpAndSettle();+ expect(controller.offset, 264);+ expect(+ tester+ .getTopLeft(+ find.byKey(+ const ValueKey('[email protected]'),+ ),+ )+ .dx,+ tester.getTopLeft(row).dx,+ );++ await tester.tap(find.byTooltip('Previous'));+ await tester.pumpAndSettle();+ expect(controller.offset, 0);+ expect(find.byTooltip('Previous'), findsNothing);++ await tester.tap(find.byTooltip('Next'));+ await tester.pumpAndSettle();+ await tester.tap(find.byTooltip('Next'));+ await tester.pumpAndSettle();+ expect(controller.offset, controller.position.maxScrollExtent);+ expect(find.byTooltip('Next'), findsNothing);+ await tester.pumpWidget(const SizedBox.shrink());+ });++ for (final theme in [lightThemeData, darkThemeData]) {+ testWidgets(+ 'unmatched search preserves sheet height in ${theme.brightness.name} mode',+ (tester) async {+ await _openSheet(tester, theme: theme);+ final title = find.text('Add people');+ final originalTop = tester.getTopLeft(title).dy;+ final field = find.byType(TextField);++ await tester.enterText(field, '[email protected]');+ await tester.pumpAndSettle();+ expect(find.text('No matching results found'), findsOneWidget);+ expect(tester.getTopLeft(title).dy, originalTop);+ expect(+ find.byKey(const ValueKey('contact-suggestions-scroll')),+ findsNothing,+ );++ await tester.enterText(field, '');+ await tester.pumpAndSettle();+ expect(find.text('No matching results found'), findsNothing);+ expect(+ find.byKey(const ValueKey('contact-suggestions-scroll')),+ findsOneWidget,+ );+ expect(tester.getTopLeft(title).dy, originalTop);+ await tester.pumpWidget(const SizedBox.shrink());+ },+ );+ }+}++Future<void> _openSheet(WidgetTester tester, {ThemeData? theme}) async {+ await tester.binding.setSurfaceSize(const Size(402, 874));+ addTearDown(() => tester.binding.setSurfaceSize(null));+ await tester.pumpWidget(+ MaterialApp(+ theme: theme ?? darkThemeData,+ localizationsDelegates: StringsLocalizations.localizationsDelegates,+ supportedLocales: StringsLocalizations.supportedLocales,+ home: Scaffold(+ body: Builder(+ builder: (context) {+ return TextButton(+ onPressed: () =>+ showAddPeopleSheet(context, [librarySharingTestAlbum(1)]),+ child: const Text('Open'),+ );+ },+ ),+ ),+ ),+ );+ await tester.tap(find.text('Open'));+ await tester.pumpAndSettle();+}++class _FakeEntityService extends Fake implements EntityService {}++class _FakeMLDataDB extends Fake implements IMLDataDB<int> {}diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arbindex 9c710fd00f..3c8c0eee3a 100644--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb@@ -2804,6 +2804,7 @@},"noResult": "No result","noResultsFound": "No results found",+ "noMatchingResultsFound": "No matching results found","noSessionsFound": "No sessions found!","noSimilarImagesFound": "No similar images found","noSuggestionsForPerson": "No suggestions for {personName}",