From a00811f16499974c2f251cb92ccee9944923a4ed Mon Sep 17 00:00:00 2001 From: Saif Addin Date: Sun, 22 Mar 2026 18:15:43 +0100 Subject: [PATCH 1/2] feat(callbacks): add onLayerInteractionEnd --- .../main_editor/main_editor_callbacks.dart | 20 +++++++++++++++++++ lib/features/main_editor/main_editor.dart | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/lib/core/models/editor_callbacks/main_editor/main_editor_callbacks.dart b/lib/core/models/editor_callbacks/main_editor/main_editor_callbacks.dart index f40a4e97d..84a6f4ab3 100644 --- a/lib/core/models/editor_callbacks/main_editor/main_editor_callbacks.dart +++ b/lib/core/models/editor_callbacks/main_editor/main_editor_callbacks.dart @@ -41,6 +41,7 @@ class MainEditorCallbacks extends StandaloneEditorCallbacks { this.onLayerTapUp, this.onImportHistoryStart, this.onImportHistoryEnd, + this.onLayerInteractionEnd, this.onHoverRemoveAreaChange, this.onStateHistoryChange, this.onImageDecoded, @@ -79,6 +80,13 @@ class MainEditorCallbacks extends StandaloneEditorCallbacks { /// The [Layer] parameter provides information about the removed layer. final Function(Layer layer)? onRemoveLayer; + /// A callback triggered when a layer interaction (drag/scale/rotate) ends. + /// + /// The [List] parameter provides the layers that were being + /// interacted with. This is useful for applying final adjustments like + /// snap-to-grid on release. + final Function(List layers)? onLayerInteractionEnd; + /// A callback function that is triggered when a sub-editor is opened. /// /// The [SubEditor] parameter provides information about the opened @@ -383,6 +391,15 @@ class MainEditorCallbacks extends StandaloneEditorCallbacks { handleUpdateUI(); } + /// Handles the end of a layer interaction (drag/scale/rotate). + /// + /// This method calls the [onLayerInteractionEnd] callback with the + /// provided [layers] and then calls [handleUpdateUI]. + void handleLayerInteractionEnd(List layers) { + onLayerInteractionEnd?.call(layers); + handleUpdateUI(); + } + /// Handles the opening of a sub-editor. /// /// This method calls the [onOpenSubEditor] callback with the provided @@ -480,6 +497,7 @@ class MainEditorCallbacks extends StandaloneEditorCallbacks { Function()? onImageDecoded, Future Function(TextLayer layer)? onEditTextLayer, Future Function()? onCreateTextLayer, + Function(List layers)? onLayerInteractionEnd, Function(ProImageEditorState state, ImportStateHistory import)? onImportHistoryStart, Function(ProImageEditorState state, ImportStateHistory import)? @@ -530,6 +548,8 @@ class MainEditorCallbacks extends StandaloneEditorCallbacks { onCreateTextLayer: onCreateTextLayer ?? this.onCreateTextLayer, onImportHistoryStart: onImportHistoryStart ?? this.onImportHistoryStart, onImportHistoryEnd: onImportHistoryEnd ?? this.onImportHistoryEnd, + onLayerInteractionEnd: + onLayerInteractionEnd ?? this.onLayerInteractionEnd, onHoverRemoveAreaChange: onHoverRemoveAreaChange ?? this.onHoverRemoveAreaChange, onStateHistoryChange: onStateHistoryChange ?? this.onStateHistoryChange, diff --git a/lib/features/main_editor/main_editor.dart b/lib/features/main_editor/main_editor.dart index cc702d0fe..4eefe7b2e 100644 --- a/lib/features/main_editor/main_editor.dart +++ b/lib/features/main_editor/main_editor.dart @@ -1340,6 +1340,10 @@ class ProImageEditorState extends State /// lines and flags. void _onScaleEnd(ScaleEndDetails details) async { mainEditorCallbacks?.handleScaleEnd(details); + if (selectedLayers.isNotEmpty) { + mainEditorCallbacks + ?.handleLayerInteractionEnd(List.of(selectedLayers)); + } layerInteractionManager.activeInteractionLayer = null; /// Check if layers should be removed. From acd8be40206a213057d84207031c75ba74581260 Mon Sep 17 00:00:00 2001 From: hm21 Date: Mon, 23 Mar 2026 13:40:12 +0100 Subject: [PATCH 2/2] style: run dart format --- lib/features/main_editor/main_editor.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/features/main_editor/main_editor.dart b/lib/features/main_editor/main_editor.dart index 4eefe7b2e..5699a78b5 100644 --- a/lib/features/main_editor/main_editor.dart +++ b/lib/features/main_editor/main_editor.dart @@ -1341,8 +1341,7 @@ class ProImageEditorState extends State void _onScaleEnd(ScaleEndDetails details) async { mainEditorCallbacks?.handleScaleEnd(details); if (selectedLayers.isNotEmpty) { - mainEditorCallbacks - ?.handleLayerInteractionEnd(List.of(selectedLayers)); + mainEditorCallbacks?.handleLayerInteractionEnd(List.of(selectedLayers)); } layerInteractionManager.activeInteractionLayer = null;