Skip to content

Commit

Permalink
TF-2253 Fix missing email content on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Oct 11, 2023
1 parent 109f457 commit 5056584
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
@override
void initState() {
super.initState();
_actualHeight = widget.heightContent ?? _minHeight;
if (Platform.isAndroid) {
_actualHeight = widget.heightContent ?? _minHeight;
} else {
_actualHeight = _minHeight;
}
log('_HtmlContentViewState::initState():_actualHeight: $_actualHeight');
_htmlData = generateHtml(
widget.contentHtml,
direction: widget.direction,
Expand Down Expand Up @@ -101,6 +106,7 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
key: ValueKey(_htmlData),
initialSettings: InAppWebViewSettings(
transparentBackground: true,
verticalScrollBarEnabled: false
),
onWebViewCreated: (controller) async {
_webViewController = controller;
Expand All @@ -123,14 +129,11 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
if (_isLoading)
const Align(
alignment: Alignment.topCenter,
child: Padding(
padding: EdgeInsets.all(16),
child: SizedBox(
width: 30,
height: 30,
child: CupertinoActivityIndicator(
color: AppColor.colorLoading
)
child: SizedBox(
width: 30,
height: 30,
child: CupertinoActivityIndicator(
color: AppColor.colorLoading
)
)
)
Expand Down Expand Up @@ -179,15 +182,19 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
}

Future<void> _setActualHeightView() async {
final scrollHeight = await _webViewController.evaluateJavascript(source: 'document.body.scrollHeight');
log('_HtmlContentViewState::_setActualHeightView():scrollHeight: $scrollHeight | type: ${scrollHeight.runtimeType}');
if (Platform.isAndroid) {
await Future.delayed(const Duration(milliseconds: 1000));
}
final scrollHeight = await _webViewController.getContentHeight();
log('_HtmlContentViewState::_setActualHeightView():scrollHeight: $scrollHeight');
if (mounted &&
scrollHeight != null &&
scrollHeight is double &&
scrollHeight > 0
) {
final newHeight = scrollHeight + _offsetHeight;
log('_HtmlContentViewState::_setActualHeightView():newHeight: $newHeight');
setState(() {
_actualHeight = scrollHeight + _offsetHeight;
_actualHeight = newHeight;
_isLoading = false;
});
}
Expand All @@ -205,8 +212,8 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
if (mounted &&
scrollWidth != null &&
offsetWidth != null &&
scrollWidth is double &&
offsetWidth is double
scrollWidth is num &&
offsetWidth is num
) {
final isScrollActivated = scrollWidth.round() == offsetWidth.round();
if (isScrollActivated) {
Expand Down
184 changes: 95 additions & 89 deletions lib/features/email/presentation/email_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,101 +121,105 @@ class EmailView extends GetWidget<SingleEmailController> {
}
}),
Expanded(
child: Obx(() {
if (controller.emailSupervisorController.supportedPageView.isTrue) {
final currentListEmail = controller.emailSupervisorController.currentListEmail;
return PageView.builder(
physics: controller.emailSupervisorController.scrollPhysicsPageView.value,
itemCount: currentListEmail.length,
allowImplicitScrolling: true,
controller: controller.emailSupervisorController.pageController,
onPageChanged: controller.emailSupervisorController.onPageChanged,
itemBuilder: (context, index) {
final currentEmail = currentListEmail[index];
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 {
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(),
child: LayoutBuilder(builder: (context, constraints) {
return Obx(() {
if (controller.emailSupervisorController.supportedPageView.isTrue) {
final currentListEmail = controller.emailSupervisorController.currentListEmail;
return PageView.builder(
physics: controller.emailSupervisorController.scrollPhysicsPageView.value,
itemCount: currentListEmail.length,
allowImplicitScrolling: true,
controller: controller.emailSupervisorController.pageController,
onPageChanged: controller.emailSupervisorController.onPageChanged,
itemBuilder: (context, index) {
final currentEmail = currentListEmail[index];
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,
maxHeight: constraints.maxHeight
))
)
);
} 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 {
return _buildEmailMessage(
context: context,
presentationEmail: currentEmail,
);
}
});
);
} else {
return _buildEmailMessage(
context: context,
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 {
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(),
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,
maxHeight: constraints.maxHeight
))
)
);
} 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 {
return _buildEmailMessage(
context: context,
presentationEmail: currentEmail,
);
}
});
);
} else {
return _buildEmailMessage(
context: context,
presentationEmail: currentEmail,
);
}
});
}
}
}
});
}),
),
EmailViewBottomBarWidget(
Expand Down Expand Up @@ -302,6 +306,7 @@ class EmailView extends GetWidget<SingleEmailController> {
required PresentationEmail presentationEmail,
CalendarEvent? calendarEvent,
List<String>? emailAddressSender,
double? maxHeight,
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down Expand Up @@ -407,6 +412,7 @@ class EmailView extends GetWidget<SingleEmailController> {
),
child: HtmlContentViewer(
contentHtml: allEmailContents,
heightContent: maxHeight,
mailtoDelegate: controller.openMailToLink,
onScrollHorizontalEnd: controller.toggleScrollPhysicsPagerView,
onWebViewLoaded: (isScrollPageViewActivated) {
Expand Down

0 comments on commit 5056584

Please sign in to comment.