Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refactor contact suggestions display and improve scrolling functionality

AmanRajSinghMourya98b7de293b20
diff --git a/mobile/apps/photos/lib/ui/sharing/add_people_sheet.dart b/mobile/apps/photos/lib/ui/sharing/add_people_sheet.dart
index 31be20a08e..d2f1dc2e92 100644
--- a/mobile/apps/photos/lib/ui/sharing/add_people_sheet.dart
+++ b/mobile/apps/photos/lib/ui/sharing/add_people_sheet.dart
@@ -160,12 +160,10 @@ class _AddPeopleSheetState extends State<_AddPeopleSheet> {
for (final suggestion in widget.selected)
normalizedSharingEmail(suggestion.email),
};
- final query = normalizedSharingEmail(_textController.text);
- final filteredContacts = _contacts
+ final availableContacts = _contacts
.where(
(contact) =>
- !selectedEmails.contains(normalizedSharingEmail(contact.email)) &&
- matchesResolvedSuggestionQuery(contact, query),
+ !selectedEmails.contains(normalizedSharingEmail(contact.email)),
)
.toList();
final keyboardVisible = MediaQuery.viewInsetsOf(context).bottom > 0;
@@ -203,7 +201,6 @@ class _AddPeopleSheetState extends State<_AddPeopleSheet> {
_emailIsValid = EmailValidator.validate(value.trim());
_emailHasNoAccount = false;
});
- _scrollContactsToStart();
},
onSubmit: _tryAddTypedEmail,
),
@@ -220,19 +217,12 @@ class _AddPeopleSheetState extends State<_AddPeopleSheet> {
shareKey: _fallbackShareKey,
onTap: _shareFallback,
),
- if (filteredContacts.isNotEmpty) ...[
- const SizedBox(height: Spacing.xxl),
- ShareSectionTitle(context.strings.fromYourContacts),
- Flexible(
- fit: FlexFit.loose,
- child: _ContactSuggestions(
- contacts: filteredContacts,
- scrollController: _contactsScrollController,
- onToggle: _toggleSuggestion,
- ),
- ),
- ShareSectionDescription(
- context.strings.longPressAnEmailToVerifyEndToEndEncryption,
+ if (availableContacts.isNotEmpty) ...[
+ const SizedBox(height: Spacing.xl),
+ _ContactSuggestions(
+ contacts: availableContacts,
+ scrollController: _contactsScrollController,
+ onToggle: _toggleSuggestion,
),
],
],
@@ -357,15 +347,6 @@ class _AddPeopleSheetState extends State<_AddPeopleSheet> {
});
}
- void _scrollContactsToStart() {
- WidgetsBinding.instance.addPostFrameCallback((_) {
- if (!mounted || !_contactsScrollController.hasClients) {
- return;
- }
- _contactsScrollController.jumpTo(0);
- });
- }
-
bool _isSelected(String email) {
return widget.selected.any(
(selected) =>
@@ -527,8 +508,6 @@ class _ContactSuggestions extends StatelessWidget {
required this.onToggle,
});
- static const _crossAxisCount = 4;
- static const _visibleRows = 2;
static double rowExtent(BuildContext context) {
const textStyle = TextStyles.mini;
final lineExtent =
@@ -547,63 +526,118 @@ class _ContactSuggestions extends StatelessWidget {
@override
Widget build(BuildContext context) {
final rowExtent = _ContactSuggestions.rowExtent(context);
- final maxViewportHeight = rowExtent * _visibleRows + Spacing.lg;
- final totalRows = (contacts.length / _crossAxisCount).ceil();
- final contentHeight =
- totalRows * rowExtent + math.max(0, totalRows - 1) * Spacing.lg;
- return LayoutBuilder(
- builder: (context, constraints) {
- final availableHeight = constraints.hasBoundedHeight
- ? constraints.maxHeight
- : maxViewportHeight;
- final viewportHeight = math.max(
- 0.0,
- math.min(contentHeight, math.min(maxViewportHeight, availableHeight)),
- );
- if (viewportHeight == 0) {
- return const SizedBox.shrink();
- }
- final showScrollbar = contentHeight > viewportHeight + 0.5;
- final grid = GridView.builder(
- key: const ValueKey("contact-suggestions-scroll"),
- controller: scrollController,
- primary: false,
- padding: showScrollbar
- ? const EdgeInsetsDirectional.only(end: Spacing.sm + 5)
- : EdgeInsets.zero,
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: _crossAxisCount,
- mainAxisSpacing: Spacing.lg,
- crossAxisSpacing: Spacing.sm,
- mainAxisExtent: rowExtent,
+ final avatarSize = getAvatarSize(AvatarType.huge);
+ const arrowSize = 36.0;
+ final itemWidth = avatarSize + Spacing.lg;
+ final scrollStep = itemWidth + Spacing.lg;
+
+ return SizedBox(
+ height: rowExtent,
+ 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: scrollController,
+ primary: false,
+ scrollDirection: Axis.horizontal,
+ padding: const EdgeInsets.symmetric(horizontal: arrowSize),
+ itemCount: contacts.length,
+ itemBuilder: (context, index) {
+ final contact = contacts[index];
+ return SizedBox(
+ width: itemWidth,
+ child: _ContactSuggestion(
+ key: ValueKey(
+ "contact-${contact.email.trim().toLowerCase()}",
+ ),
+ suggestion: contact,
+ onTap: () => onToggle(contact),
+ onLongPress: () => showVerifyIdentitySheet(
+ context,
+ self: false,
+ email: contact.email,
+ ),
+ ),
+ );
+ },
+ separatorBuilder: (_, _) => const SizedBox(width: Spacing.lg),
+ ),
+ ),
),
- itemCount: contacts.length,
- itemBuilder: (context, index) {
- final contact = contacts[index];
- return _ContactSuggestion(
- key: ValueKey("contact-${contact.email.trim().toLowerCase()}"),
- suggestion: contact,
- onTap: () => onToggle(contact),
- onLongPress: () => showVerifyIdentitySheet(
- context,
- self: false,
- email: contact.email,
+ PositionedDirectional(
+ start: 0,
+ top: 0,
+ child: SizedBox(
+ height: avatarSize,
+ child: Center(
+ child: IconButtonComponent(
+ size: arrowSize,
+ variant: IconButtonComponentVariant.primary,
+ shouldSurfaceExecutionStates: false,
+ tooltip: context.strings.previous,
+ icon: const HugeIcon(
+ icon: HugeIcons.strokeRoundedArrowLeft01,
+ ),
+ onTap: () => _scroll(context, -scrollStep),
+ ),
),
- );
- },
- );
- return SizedBox(
- height: viewportHeight,
- child: showScrollbar
- ? shareScrollbar(
- context,
- key: const ValueKey("contact-suggestions-scrollbar"),
- controller: scrollController,
- child: grid,
- )
- : grid,
- );
- },
+ ),
+ ),
+ PositionedDirectional(
+ end: 0,
+ top: 0,
+ child: SizedBox(
+ height: avatarSize,
+ child: Center(
+ child: IconButtonComponent(
+ size: arrowSize,
+ variant: IconButtonComponentVariant.primary,
+ shouldSurfaceExecutionStates: false,
+ tooltip: context.strings.next,
+ icon: const HugeIcon(
+ icon: HugeIcons.strokeRoundedArrowRight01,
+ ),
+ onTap: () => _scroll(context, scrollStep),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Future<void> _scroll(BuildContext context, double offset) async {
+ if (!scrollController.hasClients) {
+ return;
+ }
+ final position = scrollController.position;
+ final target = (position.pixels + offset)
+ .clamp(position.minScrollExtent, position.maxScrollExtent)
+ .toDouble();
+ if (MediaQuery.disableAnimationsOf(context)) {
+ scrollController.jumpTo(target);
+ return;
+ }
+ await scrollController.animateTo(
+ target,
+ duration: Motion.slow,
+ curve: Curves.easeOutCubic,
);
}
}
diff --git a/mobile/apps/photos/lib/ui/sharing/choose_access_sheet.dart b/mobile/apps/photos/lib/ui/sharing/choose_access_sheet.dart
index f926f9cbd6..e200343a5a 100644
--- a/mobile/apps/photos/lib/ui/sharing/choose_access_sheet.dart
+++ b/mobile/apps/photos/lib/ui/sharing/choose_access_sheet.dart
@@ -3,6 +3,7 @@ import "package:ente_strings/ente_strings.dart";
import "package:flutter/material.dart";
import "package:photos/models/api/collection/user.dart";
import "package:photos/models/collection/collection.dart";
+import "package:photos/ui/components/collection_share_badge.dart";
import "package:photos/ui/sharing/share_components.dart";
import "package:photos/ui/sharing/verify_identity_dialog.dart";
import "package:photos/ui/sharing/widgets/selected_person_chip.dart";
@@ -48,6 +49,7 @@ class _ChooseAccessSheetState extends State<_ChooseAccessSheet> {
@override
Widget build(BuildContext context) {
+ final colors = context.componentColors;
return ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.sizeOf(context).height * 0.95,
@@ -78,10 +80,19 @@ class _ChooseAccessSheetState extends State<_ChooseAccessSheet> {
title: shareableRoleLabel(context, role),
subtitle: shareableRoleDescription(context, role),
icon: albumSharingRoleIcon(role),
- trailing: RadioComponent(
- selected: _role == role,
- onChanged: (_) => _selectRole(role),
- ),
+ trailing: _role == role
+ ? const CollectionSelectedBadge()
+ : SizedBox.square(
+ dimension: IconSizes.small,
+ child: DecoratedBox(
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ border: Border.all(
+ color: colors.strokeDark,
+ ),
+ ),
+ ),
+ ),
onTap: () => _selectRole(role),
),
],
diff --git a/mobile/apps/photos/lib/ui/sharing/widgets/participant_role_row.dart b/mobile/apps/photos/lib/ui/sharing/widgets/participant_role_row.dart
index acaed5b5d6..325ac5e8fc 100644
--- a/mobile/apps/photos/lib/ui/sharing/widgets/participant_role_row.dart
+++ b/mobile/apps/photos/lib/ui/sharing/widgets/participant_role_row.dart
@@ -64,16 +64,11 @@ class _ParticipantRoleRowState extends State<ParticipantRoleRow> {
onSelected: (action) => action == _ParticipantRoleAction.remove
? _removeParticipant()
: _changeRole(action.role!),
- child: SizedBox.square(
- dimension: kMinInteractiveDimension,
- child: Center(
- child: HugeIcon(
- icon: albumSharingRoleIcon(role),
- color: context.componentColors.textBase,
- size: IconSizes.small,
- strokeWidth: 1.6,
- ),
- ),
+ child: HugeIcon(
+ icon: albumSharingRoleIcon(role),
+ color: context.componentColors.textBase,
+ size: IconSizes.small,
+ strokeWidth: 1.6,
),
),
);
diff --git a/mobile/apps/photos/lib/ui/sharing/widgets/participant_row.dart b/mobile/apps/photos/lib/ui/sharing/widgets/participant_row.dart
index 2033fb975c..f1a622cdf1 100644
--- a/mobile/apps/photos/lib/ui/sharing/widgets/participant_row.dart
+++ b/mobile/apps/photos/lib/ui/sharing/widgets/participant_row.dart
@@ -87,7 +87,7 @@ class _ScrollableParticipantRosterState
final textExtent =
MediaQuery.textScalerOf(context).scale(textStyle.fontSize!) *
textStyle.height!;
- return math.max(kMinInteractiveDimension, textExtent) + 20.0;
+ return math.max(60.0, textExtent + 20.0);
}
}