TF-2253 Fix missing email content on mobile

(cherry picked from commit 505658435e6c835250fc218baa12df86f5234998)
This commit is contained in:
dab246
2023-10-11 19:34:22 +07:00
committed by Dat H. Pham
parent b8b8411b44
commit 4bac00eccc
2 changed files with 117 additions and 104 deletions
@@ -66,7 +66,12 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if (Platform.isAndroid) {
_actualHeight = widget.heightContent ?? _minHeight; _actualHeight = widget.heightContent ?? _minHeight;
} else {
_actualHeight = _minHeight;
}
log('_HtmlContentViewState::initState():_actualHeight: $_actualHeight');
_htmlData = generateHtml( _htmlData = generateHtml(
widget.contentHtml, widget.contentHtml,
direction: widget.direction, direction: widget.direction,
@@ -101,6 +106,7 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
key: ValueKey(_htmlData), key: ValueKey(_htmlData),
initialSettings: InAppWebViewSettings( initialSettings: InAppWebViewSettings(
transparentBackground: true, transparentBackground: true,
verticalScrollBarEnabled: false
), ),
onWebViewCreated: (controller) async { onWebViewCreated: (controller) async {
_webViewController = controller; _webViewController = controller;
@@ -123,8 +129,6 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
if (_isLoading) if (_isLoading)
const Align( const Align(
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
child: Padding(
padding: EdgeInsets.all(16),
child: SizedBox( child: SizedBox(
width: 30, width: 30,
height: 30, height: 30,
@@ -133,7 +137,6 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
) )
) )
) )
)
], ],
); );
}); });
@@ -179,15 +182,19 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
} }
Future<void> _setActualHeightView() async { Future<void> _setActualHeightView() async {
final scrollHeight = await _webViewController.evaluateJavascript(source: 'document.body.scrollHeight'); if (Platform.isAndroid) {
log('_HtmlContentViewState::_setActualHeightView():scrollHeight: $scrollHeight | type: ${scrollHeight.runtimeType}'); await Future.delayed(const Duration(milliseconds: 1000));
}
final scrollHeight = await _webViewController.getContentHeight();
log('_HtmlContentViewState::_setActualHeightView():scrollHeight: $scrollHeight');
if (mounted && if (mounted &&
scrollHeight != null && scrollHeight != null &&
scrollHeight is double &&
scrollHeight > 0 scrollHeight > 0
) { ) {
final newHeight = scrollHeight + _offsetHeight;
log('_HtmlContentViewState::_setActualHeightView():newHeight: $newHeight');
setState(() { setState(() {
_actualHeight = scrollHeight + _offsetHeight; _actualHeight = newHeight;
_isLoading = false; _isLoading = false;
}); });
} }
@@ -205,8 +212,8 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
if (mounted && if (mounted &&
scrollWidth != null && scrollWidth != null &&
offsetWidth != null && offsetWidth != null &&
scrollWidth is double && scrollWidth is num &&
offsetWidth is double offsetWidth is num
) { ) {
final isScrollActivated = scrollWidth.round() == offsetWidth.round(); final isScrollActivated = scrollWidth.round() == offsetWidth.round();
if (isScrollActivated) { if (isScrollActivated) {
@@ -121,7 +121,8 @@ class EmailView extends GetWidget<SingleEmailController> {
} }
}), }),
Expanded( Expanded(
child: Obx(() { child: LayoutBuilder(builder: (context, constraints) {
return Obx(() {
if (controller.emailSupervisorController.supportedPageView.isTrue) { if (controller.emailSupervisorController.supportedPageView.isTrue) {
final currentListEmail = controller.emailSupervisorController.currentListEmail; final currentListEmail = controller.emailSupervisorController.currentListEmail;
return PageView.builder( return PageView.builder(
@@ -142,7 +143,8 @@ class EmailView extends GetWidget<SingleEmailController> {
child: Obx(() => _buildEmailMessage( child: Obx(() => _buildEmailMessage(
context: context, context: context,
presentationEmail: currentEmail, presentationEmail: currentEmail,
calendarEvent: controller.calendarEvent.value calendarEvent: controller.calendarEvent.value,
maxHeight: constraints.maxHeight
)) ))
) )
); );
@@ -185,7 +187,8 @@ class EmailView extends GetWidget<SingleEmailController> {
child: Obx(() => _buildEmailMessage( child: Obx(() => _buildEmailMessage(
context: context, context: context,
presentationEmail: currentEmail, presentationEmail: currentEmail,
calendarEvent: controller.calendarEvent.value calendarEvent: controller.calendarEvent.value,
maxHeight: constraints.maxHeight
)) ))
) )
); );
@@ -216,6 +219,7 @@ class EmailView extends GetWidget<SingleEmailController> {
}); });
} }
} }
});
}), }),
), ),
EmailViewBottomBarWidget( EmailViewBottomBarWidget(
@@ -302,6 +306,7 @@ class EmailView extends GetWidget<SingleEmailController> {
required PresentationEmail presentationEmail, required PresentationEmail presentationEmail,
CalendarEvent? calendarEvent, CalendarEvent? calendarEvent,
List<String>? emailAddressSender, List<String>? emailAddressSender,
double? maxHeight,
}) { }) {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@@ -407,6 +412,7 @@ class EmailView extends GetWidget<SingleEmailController> {
), ),
child: HtmlContentViewer( child: HtmlContentViewer(
contentHtml: allEmailContents, contentHtml: allEmailContents,
heightContent: maxHeight,
mailtoDelegate: controller.openMailToLink, mailtoDelegate: controller.openMailToLink,
onScrollHorizontalEnd: controller.toggleScrollPhysicsPagerView, onScrollHorizontalEnd: controller.toggleScrollPhysicsPagerView,
onWebViewLoaded: (isScrollPageViewActivated) { onWebViewLoaded: (isScrollPageViewActivated) {