TF-4075 Jump to attachments list position on mobile
(cherry picked from commit cd2ca1ec3c5b5160820823905d9f0183536b07e3)
This commit is contained in:
@@ -25,4 +25,18 @@ extension ScrollControllerExtension on ScrollController {
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
|
||||
void scrollToBottomWithPadding({required double padding}) {
|
||||
try {
|
||||
final maxExtent = position.maxScrollExtent;
|
||||
|
||||
final targetOffset = (maxExtent - padding).clamp(0.0, maxExtent);
|
||||
|
||||
animateTo(
|
||||
targetOffset,
|
||||
duration: const Duration(milliseconds: 500),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,10 +86,23 @@ class CollapseEmailInThreadDetailAction extends EmailUIAction {
|
||||
}
|
||||
|
||||
class OpenAttachmentListAction extends EmailUIAction {
|
||||
OpenAttachmentListAction(this.emailId);
|
||||
OpenAttachmentListAction({
|
||||
required this.emailId,
|
||||
required this.countAttachments,
|
||||
required this.screenHeight,
|
||||
this.isDisplayAllAttachments = false,
|
||||
});
|
||||
|
||||
final EmailId? emailId;
|
||||
final int countAttachments;
|
||||
final bool isDisplayAllAttachments;
|
||||
final double screenHeight;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [emailId];
|
||||
List<Object?> get props => [
|
||||
emailId,
|
||||
countAttachments,
|
||||
isDisplayAllAttachments,
|
||||
screenHeight,
|
||||
];
|
||||
}
|
||||
@@ -432,7 +432,12 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
if (_currentEmailId == null || action.emailId != _currentEmailId) {
|
||||
return;
|
||||
}
|
||||
jumpToAttachmentList();
|
||||
jumpToAttachmentList(
|
||||
emailId: _currentEmailId!,
|
||||
countAttachments: action.countAttachments,
|
||||
screenHeight: action.screenHeight,
|
||||
isDisplayAllAttachments: action.isDisplayAllAttachments,
|
||||
);
|
||||
mailboxDashBoardController.clearEmailUIAction();
|
||||
}
|
||||
}));
|
||||
@@ -1765,10 +1770,12 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
|
||||
void showAllAttachmentsAction() {
|
||||
isDisplayAllAttachments.value = true;
|
||||
threadDetailController?.isDisplayAllAttachments = true;
|
||||
}
|
||||
|
||||
void hideAllAttachmentsAction() {
|
||||
isDisplayAllAttachments.value = false;
|
||||
threadDetailController?.isDisplayAllAttachments = false;
|
||||
}
|
||||
|
||||
void _unsubscribeEmail(BuildContext context, PresentationEmail presentationEmail) {
|
||||
|
||||
+41
-7
@@ -1,16 +1,50 @@
|
||||
import 'package:core/presentation/extensions/scroll_controller_extension.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/controller/single_email_controller.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/utils/email_utils.dart';
|
||||
|
||||
extension HandleOpenAttachmentListExtension on SingleEmailController {
|
||||
void jumpToAttachmentList() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (attachmentListKey == null) return;
|
||||
void jumpToAttachmentList({
|
||||
required EmailId emailId,
|
||||
required int countAttachments,
|
||||
required double screenHeight,
|
||||
bool isDisplayAllAttachments = false,
|
||||
}) {
|
||||
final scrollController = threadDetailController?.scrollController;
|
||||
if (scrollController == null || !scrollController.hasClients) {
|
||||
logError(
|
||||
'$runtimeType::jumpToAttachmentList(): scrollController is null');
|
||||
return;
|
||||
}
|
||||
|
||||
threadDetailController?.scrollController?.scrollToWidgetTop(
|
||||
key: attachmentListKey!,
|
||||
padding: 70,
|
||||
);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (PlatformInfo.isWeb && attachmentListKey != null) {
|
||||
scrollController.scrollToWidgetTop(
|
||||
key: attachmentListKey!,
|
||||
padding: 70,
|
||||
);
|
||||
} else {
|
||||
final emailContentHeight =
|
||||
(screenHeight - 180).clamp(0.0, screenHeight).toDouble();
|
||||
|
||||
final totalItems = isDisplayAllAttachments
|
||||
? countAttachments + 1
|
||||
: EmailUtils.maxMobileVisibleAttachments + 1;
|
||||
|
||||
final totalAttachmentsHeight =
|
||||
totalItems * EmailUtils.attachmentItemHeight +
|
||||
(totalItems - 1) * EmailUtils.attachmentItemSpacing;
|
||||
|
||||
log('$runtimeType::jumpToAttachmentList(): totalAttachmentsHeight: $totalAttachmentsHeight, emailContentHeight: $emailContentHeight');
|
||||
scrollController.scrollToBottomWithPadding(
|
||||
padding: totalAttachmentsHeight < emailContentHeight
|
||||
? 0
|
||||
: emailContentHeight,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ class EmailUtils {
|
||||
static const double desktopItemMaxWidth = 260;
|
||||
static const double desktopMoreButtonMaxWidth = 70;
|
||||
static const double attachmentItemSpacing = 8;
|
||||
static const double attachmentItemHeight = 36;
|
||||
static const int maxMobileVisibleAttachments = 3;
|
||||
|
||||
EmailUtils._();
|
||||
|
||||
@@ -109,7 +109,7 @@ class AttachmentItemWidget extends StatelessWidget {
|
||||
);
|
||||
|
||||
return TMailContainerWidget(
|
||||
height: 36,
|
||||
height: EmailUtils.attachmentItemHeight,
|
||||
borderRadius: 8,
|
||||
border: Border.all(color: AppColor.m3Tertiary70),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
|
||||
@@ -65,7 +65,7 @@ class EmailAttachmentsWidget extends StatelessWidget {
|
||||
bool isMobile = responsiveUtils.isMobile(context);
|
||||
|
||||
final hideButton = SizedBox(
|
||||
height: 36,
|
||||
height: EmailUtils.attachmentItemHeight,
|
||||
width: isMobile ? double.infinity : null,
|
||||
child: ConfirmDialogButton(
|
||||
label: AppLocalizations.of(context).hideAll,
|
||||
@@ -105,7 +105,9 @@ class EmailAttachmentsWidget extends StatelessWidget {
|
||||
return AttachmentItemWidget(
|
||||
attachment: attachment,
|
||||
imagePaths: imagePaths,
|
||||
margin: const EdgeInsets.only(top: 8),
|
||||
margin: const EdgeInsets.only(
|
||||
top: EmailUtils.attachmentItemSpacing,
|
||||
),
|
||||
downloadAttachmentAction: downloadAttachmentAction,
|
||||
viewAttachmentAction: viewAttachmentAction,
|
||||
singleEmailControllerTag: singleEmailControllerTag,
|
||||
@@ -113,10 +115,10 @@ class EmailAttachmentsWidget extends StatelessWidget {
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const SizedBox(height: EmailUtils.attachmentItemSpacing),
|
||||
if (hiddenItemsCount > 0)
|
||||
SizedBox(
|
||||
height: 36,
|
||||
height: EmailUtils.attachmentItemHeight,
|
||||
width: double.infinity,
|
||||
child: ConfirmDialogButton(
|
||||
label: AppLocalizations.of(context).moreAttachments(
|
||||
@@ -200,7 +202,7 @@ class EmailAttachmentsWidget extends StatelessWidget {
|
||||
}).toList(),
|
||||
if (hiddenItemsCount > 0)
|
||||
SizedBox(
|
||||
height: 36,
|
||||
height: EmailUtils.attachmentItemHeight,
|
||||
child: ConfirmDialogButton(
|
||||
label: '+$hiddenItemsCount',
|
||||
backgroundColor: Theme.of(context).colorScheme.outline.withValues(
|
||||
|
||||
@@ -68,8 +68,4 @@ extension GetThreadDetailActionStatus on ThreadDetailController {
|
||||
bool get threadDetailCanPermanentlyDelete {
|
||||
return threadDetailIsTrashed || threadDetailIsSpam || threadDetailIsDraft;
|
||||
}
|
||||
|
||||
bool get isEmailExpandedHasAttachments {
|
||||
return currentEmailLoaded.value?.attachments.isNotEmpty == true;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-2
@@ -18,6 +18,7 @@ import 'package:tmail_ui_user/features/thread/domain/state/mark_as_multiple_emai
|
||||
import 'package:tmail_ui_user/features/thread/domain/state/mark_as_star_multiple_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/close_thread_detail_action.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/get_thread_detail_action_status.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/parsing_email_opened_properties_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/thread_detail_controller.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
||||
@@ -219,9 +220,14 @@ extension OnThreadDetailActionClick on ThreadDetailController {
|
||||
return destinationMailbox.id;
|
||||
}
|
||||
|
||||
void onOpenAttachmentListAction() {
|
||||
void onOpenAttachmentListAction(double screenHeight) {
|
||||
mailboxDashBoardController.dispatchEmailUIAction(
|
||||
OpenAttachmentListAction(currentExpandedEmailId.value),
|
||||
OpenAttachmentListAction(
|
||||
emailId: currentExpandedEmailId.value,
|
||||
countAttachments: currentAttachmentsList.length,
|
||||
screenHeight: screenHeight,
|
||||
isDisplayAllAttachments: isDisplayAllAttachments,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/thread_detail_controller.dart';
|
||||
|
||||
extension ParsingEmailOpenedPropertiesExtension on ThreadDetailController {
|
||||
List<Attachment> get currentAttachmentsList =>
|
||||
currentEmailLoaded.value?.attachments ?? [];
|
||||
|
||||
bool get isEmailExpandedHasAttachments =>
|
||||
currentAttachmentsList.isNotEmpty == true;
|
||||
}
|
||||
@@ -123,6 +123,7 @@ class ThreadDetailController extends BaseController {
|
||||
ScrollController? scrollController;
|
||||
CreateNewEmailRuleFilterInteractor? _createNewEmailRuleFilterInteractor;
|
||||
bool loadThreadOnThreadChanged = false;
|
||||
bool isDisplayAllAttachments = false;
|
||||
|
||||
AccountId? get accountId => mailboxDashBoardController.accountId.value;
|
||||
Session? get session => mailboxDashBoardController.sessionCurrent;
|
||||
@@ -232,6 +233,7 @@ class ThreadDetailController extends BaseController {
|
||||
currentEmailLoaded.value = null;
|
||||
cachedEmailLoaded.clear();
|
||||
_threadGetDebouncer.value = null;
|
||||
isDisplayAllAttachments = false;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -11,19 +11,19 @@ import 'package:tmail_ui_user/features/email/presentation/action/email_ui_action
|
||||
import 'package:tmail_ui_user/features/email/presentation/styles/email_view_app_bar_widget_styles.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/widgets/email_view_bottom_bar_widget.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/extensions/vacation_response_extension.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/vacation/widgets/vacation_notification_message_widget.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/domain/state/get_thread_by_id_state.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/close_thread_detail_action.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/get_thread_detail_action_status.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/get_thread_details_email_views.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/on_thread_detail_action_click.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/on_thread_page_changed.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/extension/parsing_email_opened_properties_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/thread_detail_controller.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/widgets/thread_detail_app_bar.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/presentation/widgets/thread_detail_cupertino_loading_widget.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
import '../../manage_account/presentation/vacation/widgets/vacation_notification_message_widget.dart';
|
||||
|
||||
class ThreadDetailView extends GetWidget<ThreadDetailController> {
|
||||
const ThreadDetailView({super.key});
|
||||
|
||||
@@ -45,7 +45,9 @@ class ThreadDetailView extends GetWidget<ThreadDetailController> {
|
||||
onThreadActionClick: controller.onThreadDetailActionClick,
|
||||
onThreadMoreActionClick: controller.onThreadDetailMoreActionClick,
|
||||
onOpenAttachmentListAction: controller.isEmailExpandedHasAttachments
|
||||
? controller.onOpenAttachmentListAction
|
||||
? () => controller.onOpenAttachmentListAction(
|
||||
controller.responsiveUtils.getSizeScreenHeight(context),
|
||||
)
|
||||
: null,
|
||||
optionWidgets: [
|
||||
if (controller.previousAvailable)
|
||||
|
||||
Reference in New Issue
Block a user