TF-4075 Jump to attachments list position on mobile
(cherry picked from commit cd2ca1ec3c5b5160820823905d9f0183536b07e3)
This commit is contained in:
+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,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user