TF-4084 Fix cannot read or scroll emails when opening them in Twake Mail on Android chrome mobile browser

This commit is contained in:
dab246
2025-10-03 13:50:30 +07:00
committed by Dat H. Pham
parent d686b66f75
commit 0f3002879d
3 changed files with 170 additions and 22 deletions
+80
View File
@@ -298,4 +298,84 @@ class HtmlInteraction {
});
</script>
''';
static String scriptsWheelEventListener({
required String viewId,
required String onScrollChangedEvent,
}) => '''
<script type="text/javascript">
function onWheel(e) {
const deltaY = event.deltaY;
window.parent.postMessage(JSON.stringify({
"view": "$viewId",
"type": "toDart: $onScrollChangedEvent",
"deltaY": deltaY
}), "*");
}
window.addEventListener('wheel', onWheel, { passive: true });
window.addEventListener('pagehide', (event) => {
window.removeEventListener('wheel', onWheel);
});
</script>
''';
static String scriptsTouchEventListener({
required String viewId,
required String onScrollChangedEvent,
required String onScrollEndEvent,
}) => '''
<script type="text/javascript">
let lastY = 0;
let lastTime = 0;
let velocity = 0;
function onTouchStart(e) {
lastY = e.touches[0].clientY;
lastTime = performance.now();
velocity = 0;
}
function onTouchMove(e) {
const now = performance.now();
const y = e.touches[0].clientY;
const dy = lastY - y;
const dt = now - lastTime;
if (dt > 0) {
velocity = dy / dt; // px per ms
velocity = Math.max(Math.min(velocity, 2), -2); // clamp velocity
}
lastY = y;
lastTime = now;
window.parent.postMessage(JSON.stringify({
view: "$viewId",
type: "toDart: $onScrollChangedEvent",
deltaY: dy,
}), '*');
}
function onTouchEnd(e) {
window.parent.postMessage(JSON.stringify({
view: "$viewId",
type: "toDart: $onScrollEndEvent",
velocity: velocity,
}), '*');
}
window.addEventListener('touchstart', onTouchStart, { passive: true });
window.addEventListener('touchmove', onTouchMove, { passive: true });
window.addEventListener('touchend', onTouchEnd, { passive: true });
window.addEventListener('pagehide', () => {
window.removeEventListener('touchstart', onTouchStart);
window.removeEventListener('touchmove', onTouchMove);
window.removeEventListener('touchend', onTouchEnd);
});
</script>
''';
}
+22
View File
@@ -1,6 +1,7 @@
import 'package:core/utils/app_logger.dart';
import 'package:core/utils/web_renderer/canvas_kit.dart';
import 'package:flutter/foundation.dart';
import 'package:universal_html/html.dart' as universal_html;
abstract class PlatformInfo {
@visibleForTesting
@@ -44,4 +45,25 @@ abstract class PlatformInfo {
log('PlatformInfo::platformNameOS(): $platformName');
return platformName;
}
static String get userAgent =>
isWeb ? universal_html.window.navigator.userAgent.toLowerCase() : '';
/// Web browser on a mobile phone
static bool get isWebMobile =>
isWeb && (userAgent.contains('iphone') ||
(userAgent.contains('android') && userAgent.contains('mobile')));
/// Web browser on a tablet device
static bool get isWebTablet =>
isWeb && (userAgent.contains('ipad') ||
(userAgent.contains('android') && !userAgent.contains('mobile')));
/// Web browser on a desktop (PC/Mac)
static bool get isWebDesktop =>
isWeb && !isWebMobile && !isWebTablet;
/// Touch devices
static bool get isWebTouchDevice =>
isWeb && (isWebMobile || isWebTablet);
}