TF-3399 Fix can not click on body of composer in Samsung A3

This commit is contained in:
dab246
2025-01-09 16:08:53 +07:00
committed by Dat H. Pham
parent 2212bae095
commit 248b6b6ac4
6 changed files with 75 additions and 112 deletions
@@ -9,7 +9,7 @@ import 'package:universal_html/html.dart' hide VoidCallback;
typedef OnChangeContentEditorAction = Function(String? text);
typedef OnInitialContentEditorAction = Function(String text);
typedef OnMouseDownEditorAction = Function(BuildContext context);
typedef OnMouseDownEditorAction = Function();
typedef OnEditorSettingsChange = Function(EditorSettings settings);
typedef OnEditorTextSizeChanged = Function(int? size);
typedef OnDragEnterListener = Function(List<dynamic>? types);
@@ -32,7 +32,6 @@ class WebEditorWidget extends StatefulWidget {
final OnMouseDownEditorAction? onMouseDown;
final OnEditorSettingsChange? onEditorSettings;
final OnEditorTextSizeChanged? onEditorTextSizeChanged;
final double? width;
final double? height;
final OnDragEnterListener? onDragEnter;
final OnPasteImageSuccessAction? onPasteImageSuccessAction;
@@ -51,7 +50,6 @@ class WebEditorWidget extends StatefulWidget {
this.onMouseDown,
this.onEditorSettings,
this.onEditorTextSizeChanged,
this.width,
this.height,
this.onDragEnter,
this.onPasteImageSuccessAction,
@@ -65,14 +63,9 @@ class WebEditorWidget extends StatefulWidget {
class _WebEditorState extends State<WebEditorWidget> {
static const double _offsetHeight = 50;
static const double _offsetWidth = 90;
static const double _defaultHtmlEditorHeight = 550;
late HtmlEditorController _editorController;
double? dropZoneWidth;
double? dropZoneHeight;
final ValueNotifier<double> _htmlEditorHeight = ValueNotifier(_defaultHtmlEditorHeight);
bool _dropListenerRegistered = false;
Function(Event)? _dropListener;
@@ -80,16 +73,6 @@ class _WebEditorState extends State<WebEditorWidget> {
void initState() {
super.initState();
_editorController = widget.editorController;
log('_WebEditorState::initState:height: ${widget.height} | width: ${widget.width}');
if (widget.height != null) {
dropZoneHeight = widget.height! - _offsetHeight;
_htmlEditorHeight.value = widget.height ?? _defaultHtmlEditorHeight;
}
if (widget.width != null) {
dropZoneWidth = widget.width! - _offsetWidth;
}
log('_WebEditorState::initState:dropZoneWidth: $dropZoneWidth | dropZoneHeight: $dropZoneHeight');
_dropListener = (event) {
if (event is MessageEvent) {
if (jsonDecode(event.data)['name'] == HtmlUtils.registerDropListener.name) {
@@ -108,18 +91,11 @@ class _WebEditorState extends State<WebEditorWidget> {
if (oldWidget.direction != widget.direction) {
_editorController.updateBodyDirection(widget.direction.name);
}
log('_EmailEditorState::didUpdateWidget():Old: ${oldWidget.height} | current: ${widget.height}');
if (oldWidget.height != widget.height) {
_htmlEditorHeight.value = widget.height ?? _defaultHtmlEditorHeight;
}
super.didUpdateWidget(oldWidget);
}
@override
void dispose() {
_htmlEditorHeight.dispose();
_editorController.evaluateJavascriptWeb(
HtmlUtils.unregisterDropListener.name);
if (_dropListener != null) {
@@ -131,72 +107,64 @@ class _WebEditorState extends State<WebEditorWidget> {
@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: _htmlEditorHeight,
builder: (context, height, _) {
return HtmlEditor(
key: Key('web_editor_$height'),
controller: _editorController,
htmlEditorOptions: HtmlEditorOptions(
shouldEnsureVisible: true,
hint: '',
darkMode: false,
initialText: widget.content,
customBodyCssStyle: HtmlUtils.customCssStyleHtmlEditor(direction: widget.direction),
spellCheck: true,
disableDragAndDrop: true,
webInitialScripts: UnmodifiableListView([
WebScript(
name: HtmlUtils.lineHeight100Percent.name,
script: HtmlUtils.lineHeight100Percent.script,
),
WebScript(
name: HtmlUtils.registerDropListener.name,
script: HtmlUtils.registerDropListener.script,
),
WebScript(
name: HtmlUtils.unregisterDropListener.name,
script: HtmlUtils.unregisterDropListener.script,
)
])
return HtmlEditor(
controller: _editorController,
htmlEditorOptions: HtmlEditorOptions(
shouldEnsureVisible: true,
hint: '',
darkMode: false,
initialText: widget.content,
customBodyCssStyle: HtmlUtils.customCssStyleHtmlEditor(direction: widget.direction),
spellCheck: true,
disableDragAndDrop: true,
webInitialScripts: UnmodifiableListView([
WebScript(
name: HtmlUtils.lineHeight100Percent.name,
script: HtmlUtils.lineHeight100Percent.script,
),
htmlToolbarOptions: const HtmlToolbarOptions(
toolbarType: ToolbarType.hide,
defaultToolbarButtons: [],
WebScript(
name: HtmlUtils.registerDropListener.name,
script: HtmlUtils.registerDropListener.script,
),
otherOptions: OtherOptions(
height: height,
// dropZoneWidth: dropZoneWidth,
// dropZoneHeight: dropZoneHeight,
),
callbacks: Callbacks(
onBeforeCommand: widget.onChangeContent,
onChangeContent: widget.onChangeContent,
onInit: () {
widget.onInitial?.call(widget.content);
if (!_dropListenerRegistered) {
_editorController.evaluateJavascriptWeb(
HtmlUtils.registerDropListener.name);
_dropListenerRegistered = true;
}
},
onFocus: widget.onFocus,
onBlur: widget.onUnFocus,
onMouseDown: () => widget.onMouseDown?.call(context),
onChangeSelection: widget.onEditorSettings,
onChangeCodeview: widget.onChangeContent,
onTextFontSizeChanged: widget.onEditorTextSizeChanged,
onPaste: () => _editorController.evaluateJavascriptWeb(
HtmlUtils.lineHeight100Percent.name
),
onDragEnter: widget.onDragEnter,
onDragLeave: (_) {},
onImageUpload: widget.onPasteImageSuccessAction,
onImageUploadError: widget.onPasteImageFailureAction,
onInitialTextLoadComplete: widget.onInitialContentLoadComplete,
),
);
}
WebScript(
name: HtmlUtils.unregisterDropListener.name,
script: HtmlUtils.unregisterDropListener.script,
)
])
),
htmlToolbarOptions: const HtmlToolbarOptions(
toolbarType: ToolbarType.hide,
defaultToolbarButtons: [],
),
otherOptions: OtherOptions(
height: widget.height ?? _defaultHtmlEditorHeight,
),
callbacks: Callbacks(
onBeforeCommand: widget.onChangeContent,
onChangeContent: widget.onChangeContent,
onInit: () {
widget.onInitial?.call(widget.content);
if (!_dropListenerRegistered) {
_editorController.evaluateJavascriptWeb(
HtmlUtils.registerDropListener.name);
_dropListenerRegistered = true;
}
},
onFocus: widget.onFocus,
onUnFocus: widget.onUnFocus,
onMouseDown:widget.onMouseDown,
onChangeSelection: widget.onEditorSettings,
onChangeCodeview: widget.onChangeContent,
onTextFontSizeChanged: widget.onEditorTextSizeChanged,
onPaste: () => _editorController.evaluateJavascriptWeb(
HtmlUtils.lineHeight100Percent.name
),
onDragEnter: widget.onDragEnter,
onDragLeave: (_) {},
onImageUpload: widget.onPasteImageSuccessAction,
onImageUploadError: widget.onPasteImageFailureAction,
onInitialTextLoadComplete: widget.onInitialContentLoadComplete,
),
);
}
}