Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF-2948 Apply new identity view #3322

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions assets/images/ic_delete_rule.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions core/lib/presentation/extensions/color_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ extension AppColor on Color {
static const colorStarredSearchFilterIcon = Color(0xFFFFCC00);
static const colorMobileSearchFilterButton = Color(0xFFEBEDF0);
static const colorContactViewClearFilterButton = Color(0x001C3D0D);
static const colorDisableRadioButton = Color(0xFF86888B);

static const mapGradientColor = [
[Color(0xFF21D4FD), Color(0xFFB721FF)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ class TransformConfiguration {
const RemoveMaxWidthInImageStyleTransformer(),
]);

factory TransformConfiguration.forSignatureIdentity() => TransformConfiguration.create(
customDomTransformers: [
const RemoveScriptTransformer(),
const BlockQuotedTransformer(),
const BlockCodeTransformer(),
SanitizeHyperLinkTagInHtmlTransformer(useTooltip: PlatformInfo.isWeb),
const ImageTransformer(),
],
);

/// Provides easy access to a standard configuration that does not block external images.
static TransformConfiguration standardConfiguration = TransformConfiguration(
standardDomTransformers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class HtmlContentViewerOnWeb extends StatefulWidget {
final double widthContent;
final double heightContent;
final TextDirection? direction;
final double? minWidth;
final double? maxHeight;
final double? contentPadding;
final bool adjustHeight;

/// Handler for mailto: links
final Function(Uri?)? mailtoDelegate;
Expand All @@ -30,6 +34,10 @@ class HtmlContentViewerOnWeb extends StatefulWidget {
required this.widthContent,
required this.heightContent,
this.allowResizeToDocumentSize = true,
this.adjustHeight = false,
this.minWidth,
this.maxHeight,
this.contentPadding,
this.mailtoDelegate,
this.direction,
}) : super(key: key);
Expand All @@ -40,14 +48,16 @@ class HtmlContentViewerOnWeb extends StatefulWidget {

class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb> {

static const double _minWidth = 300;
static const double _defaultMinWidth = 300;
/// The view ID for the IFrameElement. Must be unique.
late String _createdViewId;
/// The actual height of the content view, used to automatically set the height
late double _actualHeight;
/// The actual width of the content view, used to automatically set the width
late double _actualWidth;

late double _minWidth;

Future<bool>? _webInit;
String? _htmlData;
bool _isLoading = true;
Expand All @@ -61,6 +71,7 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb> {
super.initState();
_actualHeight = widget.heightContent;
_actualWidth = widget.widthContent;
_minWidth = widget.minWidth ?? _defaultMinWidth;
_createdViewId = _getRandString(10);
_setUpWeb();

Expand All @@ -78,8 +89,9 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb> {
if (data['type'] != null && data['type'].contains('toDart: htmlHeight')) {
final docHeight = data['height'] ?? _actualHeight;
if (docHeight != null && mounted) {
final scrollHeightWithBuffer = docHeight + 30.0;
if (scrollHeightWithBuffer > minHeight) {
final bottomPadding = widget.adjustHeight ? 0 : 30.0;
final scrollHeightWithBuffer = docHeight + bottomPadding;
if (scrollHeightWithBuffer > minHeight || widget.adjustHeight) {
setState(() {
_actualHeight = scrollHeightWithBuffer;
_isLoading = false;
Expand Down Expand Up @@ -214,11 +226,13 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb> {

final htmlTemplate = HtmlUtils.generateHtmlDocument(
content: content,
minHeight: minHeight,
minHeight: widget.adjustHeight ? 0 : minHeight,
minWidth: _minWidth,
styleCSS: HtmlTemplate.tooltipLinkCss,
javaScripts: webViewActionScripts + scriptsDisableZoom + HtmlInteraction.scriptsHandleLazyLoadingBackgroundImage,
direction: widget.direction);
direction: widget.direction,
contentPadding: widget.contentPadding
);

return htmlTemplate;
}
Expand Down Expand Up @@ -246,47 +260,58 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb> {

@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraint) {
minHeight = math.max(constraint.maxHeight, minHeight);
return Stack(
children: [
if (_htmlData?.isNotEmpty == false)
const SizedBox.shrink()
else
FutureBuilder<bool>(
future: _webInit,
builder: (context, snapshot) {
if (snapshot.hasData) {
return SizedBox(
height: _actualHeight,
width: _actualWidth,
child: HtmlElementView(
key: ValueKey(_htmlData),
viewType: _createdViewId,
),
);
} else {
return const SizedBox.shrink();
}
return Stack(
children: [
if (_htmlData?.isNotEmpty == false)
const SizedBox.shrink()
else
FutureBuilder<bool>(
future: _webInit,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const SizedBox.shrink();
}

if (widget.adjustHeight) {
return Container(
height: _actualHeight,
width: _actualWidth,
constraints: widget.maxHeight != null
? BoxConstraints(maxHeight: widget.maxHeight!)
: null,
child: HtmlElementView(
key: ValueKey(_htmlData),
viewType: _createdViewId,
),
);
}
),
if (_isLoading)
const Align(
alignment: Alignment.topCenter,
child: Padding(
padding: EdgeInsets.all(16),
child: SizedBox(
width: 30,
height: 30,
child: CupertinoActivityIndicator(
color: AppColor.colorLoading
)

return SizedBox(
height: _actualHeight,
width: _actualWidth,
child: HtmlElementView(
key: ValueKey(_htmlData),
viewType: _createdViewId,
),
);
}
),
if (_isLoading)
const Align(
alignment: Alignment.topCenter,
child: Padding(
padding: EdgeInsets.all(16),
child: SizedBox(
width: 30,
height: 30,
child: CupertinoActivityIndicator(
color: AppColor.colorLoading
)
)
)
],
);
});
)
],
);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import 'package:core/utils/app_logger.dart';
import 'package:core/utils/html/html_interaction.dart';
import 'package:core/utils/html/html_utils.dart';
import 'package:core/utils/platform_info.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:url_launcher/url_launcher.dart' as launcher;
import 'package:url_launcher/url_launcher_string.dart';
Expand All @@ -22,6 +22,8 @@ class HtmlContentViewer extends StatefulWidget {
final String contentHtml;
final double? initialWidth;
final TextDirection? direction;
final double? contentPadding;
final bool adjustHeight;

final OnLoadWidthHtmlViewerAction? onLoadWidthHtmlViewer;
final OnMailtoDelegateAction? onMailtoDelegateAction;
Expand All @@ -30,8 +32,10 @@ class HtmlContentViewer extends StatefulWidget {
const HtmlContentViewer({
Key? key,
required this.contentHtml,
this.adjustHeight = false,
this.initialWidth,
this.direction,
this.contentPadding,
this.onLoadWidthHtmlViewer,
this.onMailtoDelegateAction,
this.onScrollHorizontalEnd
Expand All @@ -44,12 +48,13 @@ class HtmlContentViewer extends StatefulWidget {
class _HtmlContentViewState extends State<HtmlContentViewer> {

static const double _minHeight = 100.0;
static const double _offsetHeight = 30.0;
static const double _defaultOffsetHeight = 30.0;

late InAppWebViewController _webViewController;
late double _actualHeight;
late Set<Factory<OneSequenceGestureRecognizer>> _gestureRecognizers;
late String _customScripts;
late double _offsetHeight;

final _loadingBarNotifier = ValueNotifier(true);

Expand All @@ -63,6 +68,7 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
@override
void initState() {
super.initState();
_offsetHeight = widget.adjustHeight ? 0 : _defaultOffsetHeight;
if (PlatformInfo.isAndroid) {
_gestureRecognizers = {
Factory<LongPressGestureRecognizer>(() => LongPressGestureRecognizer()),
Expand Down Expand Up @@ -96,12 +102,14 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
_htmlData = HtmlUtils.generateHtmlDocument(
content: widget.contentHtml,
direction: widget.direction,
javaScripts: _customScripts
javaScripts: _customScripts,
contentPadding: widget.contentPadding,
);
}

@override
Widget build(BuildContext context) {
log('_HtmlContentViewState::build:_actualHeight = $_actualHeight');
return Stack(children: [
if (_htmlData == null)
const SizedBox.shrink()
Expand Down Expand Up @@ -165,7 +173,7 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
) async {
final maxContentHeight = math.max(oldContentSize.height, newContentSize.height);
log('_HtmlContentViewState::_onContentSizeChanged:maxContentHeight: $maxContentHeight');
if (maxContentHeight > _actualHeight && !_loadingBarNotifier.value && mounted) {
if ((maxContentHeight > _actualHeight || widget.adjustHeight) && !_loadingBarNotifier.value && mounted) {
log('_HtmlContentViewState::_onContentSizeChanged:HEIGHT_UPDATED: $maxContentHeight');
setState(() {
_actualHeight = maxContentHeight + _offsetHeight;
Expand All @@ -186,7 +194,7 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
void _onHandleContentSizeChangedEvent(List<dynamic> parameters) async {
final maxContentHeight = await _webViewController.evaluateJavascript(source: 'document.body.scrollHeight');
log('_HtmlContentViewState::_onHandleContentSizeChangedEvent:maxContentHeight: $maxContentHeight');
if (maxContentHeight is num && maxContentHeight > _actualHeight && !_loadingBarNotifier.value && mounted) {
if (maxContentHeight is num && (maxContentHeight > _actualHeight || widget.adjustHeight) && !_loadingBarNotifier.value && mounted) {
log('_HtmlContentViewState::_onHandleContentSizeChangedEvent:HEIGHT_UPDATED: $maxContentHeight');
setState(() {
_actualHeight = maxContentHeight + _offsetHeight;
Expand Down
5 changes: 3 additions & 2 deletions core/lib/utils/html/html_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class HtmlUtils {
String? styleCSS,
String? javaScripts,
bool hideScrollBar = true,
TextDirection? direction
TextDirection? direction,
double? contentPadding,
}) {
return '''
<!DOCTYPE html>
Expand All @@ -117,7 +118,7 @@ class HtmlUtils {
${styleCSS ?? ''}
</style>
</head>
<body ${direction == TextDirection.rtl ? 'dir="rtl"' : ''} style = "overflow-x: hidden">
<body ${direction == TextDirection.rtl ? 'dir="rtl"' : ''} style = "overflow-x: hidden; ${contentPadding != null ? 'margin: ${contentPadding}px;' : ''}">
<div class="tmail-content">$content</div>
${javaScripts ?? ''}
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,16 @@ class IdentityCreatorView extends GetWidget<IdentityCreatorController>
),
]
),
_buildHtmlEditorWeb(
context,
controller.contentHtmlEditor,
maxWidth),
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: maxWidth,
maxHeight: 300,
),
child: _buildHtmlEditorWeb(
context,
controller.contentHtmlEditor,
maxWidth),
),
],
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:jmap_dart_client/jmap/identities/identity.dart';
import 'package:tmail_ui_user/features/manage_account/domain/model/create_new_identity_request.dart';
import 'package:tmail_ui_user/features/manage_account/domain/model/edit_identity_request.dart';
import 'package:tmail_ui_user/features/manage_account/domain/model/identities_response.dart';
import 'package:tmail_ui_user/features/manage_account/domain/model/identity_signature.dart';

abstract class IdentityDataSource {
Future<IdentitiesResponse> getAllIdentities(Session session, AccountId accountId, {Properties? properties});
Expand All @@ -15,5 +16,5 @@ abstract class IdentityDataSource {

Future<bool> editIdentity(Session session, AccountId accountId, EditIdentityRequest editIdentityRequest);

Future<String> transformHtmlSignature(String signature);
Future<IdentitySignature> transformHtmlSignature(IdentitySignature identitySignature);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import 'package:core/presentation/utils/html_transformer/dom/block_code_transformers.dart';
import 'package:core/presentation/utils/html_transformer/dom/block_quoted_transformers.dart';
import 'package:core/presentation/utils/html_transformer/dom/image_transformers.dart';
import 'package:core/presentation/utils/html_transformer/dom/sanitize_hyper_link_tag_in_html_transformers.dart';
import 'package:core/presentation/utils/html_transformer/dom/script_transformers.dart';
import 'package:core/presentation/utils/html_transformer/html_transform.dart';
import 'package:core/presentation/utils/html_transformer/transform_configuration.dart';
import 'package:core/utils/platform_info.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
Expand All @@ -15,6 +9,7 @@ import 'package:tmail_ui_user/features/manage_account/data/network/identity_api.
import 'package:tmail_ui_user/features/manage_account/domain/model/create_new_identity_request.dart';
import 'package:tmail_ui_user/features/manage_account/domain/model/edit_identity_request.dart';
import 'package:tmail_ui_user/features/manage_account/domain/model/identities_response.dart';
import 'package:tmail_ui_user/features/manage_account/domain/model/identity_signature.dart';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';

class IdentityDataSourceImpl extends IdentityDataSource {
Expand Down Expand Up @@ -58,18 +53,13 @@ class IdentityDataSourceImpl extends IdentityDataSource {
}

@override
Future<String> transformHtmlSignature(String signature) {
Future<IdentitySignature> transformHtmlSignature(IdentitySignature identitySignature) {
return Future.sync(() async {
final signatureUnescape = await _htmlTransform.transformToHtml(
htmlContent: signature,
transformConfiguration: TransformConfiguration.create(customDomTransformers: [
const RemoveScriptTransformer(),
const BlockQuotedTransformer(),
const BlockCodeTransformer(),
SanitizeHyperLinkTagInHtmlTransformer(useTooltip: PlatformInfo.isWeb),
const ImageTransformer(),
]));
return signatureUnescape;
htmlContent: identitySignature.signature,
transformConfiguration: TransformConfiguration.forSignatureIdentity(),
);
return identitySignature.newSignature(signatureUnescape);
}).catchError(_exceptionThrower.throwException);
}
}
Loading
Loading