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();
_actualHeight = widget.heightContent ?? _minHeight; if (Platform.isAndroid) {
_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,14 +129,11 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
if (_isLoading) if (_isLoading)
const Align( const Align(
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
child: Padding( child: SizedBox(
padding: EdgeInsets.all(16), width: 30,
child: SizedBox( height: 30,
width: 30, child: CupertinoActivityIndicator(
height: 30, color: AppColor.colorLoading
child: CupertinoActivityIndicator(
color: AppColor.colorLoading
)
) )
) )
) )
@@ -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) {
+95 -89
View File
@@ -121,101 +121,105 @@ class EmailView extends GetWidget<SingleEmailController> {
} }
}), }),
Expanded( Expanded(
child: Obx(() { child: LayoutBuilder(builder: (context, constraints) {
if (controller.emailSupervisorController.supportedPageView.isTrue) { return Obx(() {
final currentListEmail = controller.emailSupervisorController.currentListEmail; if (controller.emailSupervisorController.supportedPageView.isTrue) {
return PageView.builder( final currentListEmail = controller.emailSupervisorController.currentListEmail;
physics: controller.emailSupervisorController.scrollPhysicsPageView.value, return PageView.builder(
itemCount: currentListEmail.length, physics: controller.emailSupervisorController.scrollPhysicsPageView.value,
allowImplicitScrolling: true, itemCount: currentListEmail.length,
controller: controller.emailSupervisorController.pageController, allowImplicitScrolling: true,
onPageChanged: controller.emailSupervisorController.onPageChanged, controller: controller.emailSupervisorController.pageController,
itemBuilder: (context, index) { onPageChanged: controller.emailSupervisorController.onPageChanged,
final currentEmail = currentListEmail[index]; itemBuilder: (context, index) {
if (PlatformInfo.isMobile) { final currentEmail = currentListEmail[index];
return SingleChildScrollView( if (PlatformInfo.isMobile) {
physics : const ClampingScrollPhysics(), return SingleChildScrollView(
child: Container( physics : const ClampingScrollPhysics(),
width: double.infinity, child: Container(
alignment: Alignment.center, width: double.infinity,
color: Colors.white, alignment: Alignment.center,
child: Obx(() => _buildEmailMessage( color: Colors.white,
context: context, child: Obx(() => _buildEmailMessage(
presentationEmail: currentEmail, context: context,
calendarEvent: controller.calendarEvent.value presentationEmail: currentEmail,
)) calendarEvent: controller.calendarEvent.value,
) maxHeight: constraints.maxHeight
); ))
} else { )
return Obx(() { );
final calendarEvent = controller.calendarEvent.value; } else {
if (currentEmail.hasCalendarEvent && calendarEvent != null) { return Obx(() {
return SingleChildScrollView( final calendarEvent = controller.calendarEvent.value;
physics : const ClampingScrollPhysics(), if (currentEmail.hasCalendarEvent && calendarEvent != null) {
child: Container( return SingleChildScrollView(
width: double.infinity, physics : const ClampingScrollPhysics(),
alignment: Alignment.center, child: Container(
color: Colors.white, width: double.infinity,
child: _buildEmailMessage( alignment: Alignment.center,
context: context, color: Colors.white,
presentationEmail: currentEmail, child: _buildEmailMessage(
calendarEvent: calendarEvent, context: context,
emailAddressSender: currentEmail.listEmailAddressSender.getListAddress(), presentationEmail: currentEmail,
calendarEvent: calendarEvent,
emailAddressSender: currentEmail.listEmailAddressSender.getListAddress(),
)
) )
) );
); } else {
} else { return _buildEmailMessage(
return _buildEmailMessage( context: context,
context: context, presentationEmail: currentEmail,
presentationEmail: currentEmail, );
); }
} });
}); }
} }
}
);
} else {
if (PlatformInfo.isMobile) {
return SingleChildScrollView(
physics : const ClampingScrollPhysics(),
child: Container(
width: double.infinity,
alignment: Alignment.center,
color: Colors.white,
child: Obx(() => _buildEmailMessage(
context: context,
presentationEmail: currentEmail,
calendarEvent: controller.calendarEvent.value
))
)
); );
} else { } else {
return Obx(() { if (PlatformInfo.isMobile) {
final calendarEvent = controller.calendarEvent.value; return SingleChildScrollView(
if (currentEmail.hasCalendarEvent && calendarEvent != null) { physics : const ClampingScrollPhysics(),
return SingleChildScrollView( child: Container(
physics : const ClampingScrollPhysics(), width: double.infinity,
child: Container( alignment: Alignment.center,
width: double.infinity, color: Colors.white,
alignment: Alignment.center, child: Obx(() => _buildEmailMessage(
color: Colors.white, context: context,
child: _buildEmailMessage( presentationEmail: currentEmail,
context: context, calendarEvent: controller.calendarEvent.value,
presentationEmail: currentEmail, maxHeight: constraints.maxHeight
calendarEvent: calendarEvent, ))
emailAddressSender: currentEmail.listEmailAddressSender.getListAddress(), )
);
} else {
return Obx(() {
final calendarEvent = controller.calendarEvent.value;
if (currentEmail.hasCalendarEvent && calendarEvent != null) {
return SingleChildScrollView(
physics : const ClampingScrollPhysics(),
child: Container(
width: double.infinity,
alignment: Alignment.center,
color: Colors.white,
child: _buildEmailMessage(
context: context,
presentationEmail: currentEmail,
calendarEvent: calendarEvent,
emailAddressSender: currentEmail.listEmailAddressSender.getListAddress(),
)
) )
) );
); } else {
} else { return _buildEmailMessage(
return _buildEmailMessage( context: context,
context: context, presentationEmail: currentEmail,
presentationEmail: currentEmail, );
); }
} });
}); }
} }
} });
}), }),
), ),
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) {