π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Preserve text layout across rotation and edits
r4khul1c0f30119888
diff --git a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_layer_selection.dart b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_layer_selection.dartindex 43c3615054..26745179d7 100644--- a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_layer_selection.dart+++ b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_layer_selection.dart@@ -6,6 +6,7 @@ import "package:flutter/gestures.dart";import "package:flutter/material.dart";import "package:hugeicons/hugeicons.dart";import "package:photos/ui/tools/editor/image_editor/image_editor_constants.dart";+import "package:photos/ui/tools/editor/image_editor/image_editor_text_bar.dart";import "package:pro_image_editor/features/main_editor/services/layer_copy_manager.dart";import "package:pro_image_editor/pro_image_editor.dart";@@ -14,6 +15,7 @@ const _frameGap = 6.0;const _handleRadius = 5.0;const _handleTapSize = 32.0;const _actionSize = 44.0;+const _textEditorWidthInset = 34.0;LayerInteractionConfigs imageEditorLayerInteractionConfigs(BuildContext context,@@ -181,7 +183,7 @@ Future<TextLayer?> imageEditorCreateTextLayer(if (state == null || state.isSubEditorOpen) return null;final id = UniqueKey().toString();final layer = await state.openPage<TextLayer>(- TextEditor(+ ImageEditorTextPage(key: state.textEditor,heroTag: id,configs: state.configs,@@ -218,23 +220,36 @@ void _selectLayerAfterClose(ProImageEditorState state, String id) {Future<void> _editTextLayer(ProImageEditorState editor, TextLayer layer) async {if (editor.isSubEditorOpen) return;final layerWidth = layer.keyInternalSize.currentContext?.size?.width;- final availableWidth = editor.sizesManager.bodySize.width - 34;+ final wrapWidth =+ layer.maxTextWidth ??+ (layerWidth == null ? null : layerWidth / layer.scale);+ final availableWidth =+ editor.sizesManager.bodySize.width - _textEditorWidthInset;final displayScale = min(layer.scale,- layerWidth == null || layerWidth <= 0+ wrapWidth == null || wrapWidth <= 0? layer.scale- : layer.scale * availableWidth / layerWidth,+ : availableWidth / wrapWidth,);final updated = await editor.openPage<TextLayer>(- TextEditor(+ ImageEditorTextPage(key: editor.textEditor,layer: (LayerCopyManager().copyLayer(layer) as TextLayer)..fontScale = layer.fontScale * displayScale,heroTag: layer.rotation == 0 ? layer.id : null,- configs: editor.configs,+ configs: editor.configs.copyWith(+ textEditor: editor.configs.textEditor.copyWith(+ enableImageBoundaryTextWrap: layer.maxTextWidth != null,+ ),+ ),theme: editor.configs.theme ?? Theme.of(editor.context),callbacks: editor.callbacks,- imageSize: editor.sizesManager.decodedImageSize,+ imageSize: layer.maxTextWidth == null+ ? editor.sizesManager.decodedImageSize+ : Size(+ layer.maxTextWidth! * displayScale + _textEditorWidthInset,+ editor.sizesManager.decodedImageSize.height,+ ),),duration: const Duration(milliseconds: 250),);@@ -257,9 +272,7 @@ Future<void> _editTextLayer(ProImageEditorState editor, TextLayer layer) async {..rotation = layer.rotation..boxConstraints = layer.boxConstraints..fontScale = updated.fontScale / displayScale- ..maxTextWidth = updated.maxTextWidth == null- ? null- : updated.maxTextWidth! / displayScale+ ..maxTextWidth = layer.maxTextWidth..groupId = layer.groupId..interaction = layer.interaction..meta = layer.metadiff --git a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_text_bar.dart b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_text_bar.dartindex aba2170f47..a290e18773 100644--- a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_text_bar.dart+++ b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_text_bar.dart@@ -50,11 +50,6 @@ TextEditorConfigs imageEditorTextConfigs(BuildContext context) {inputCursorColor: colors.primary,inputHintColor: Colors.white70,textFieldMargin: EdgeInsets.zero,- textFieldPadding: EdgeInsets.only(- top: MediaQuery.orientationOf(context) == Orientation.landscape- ? 0- : MediaQuery.sizeOf(context).height * _textFieldTopFraction,- ),),widgets: TextEditorWidgets(appBar: (editor, rebuildStream) => ReactiveAppbar(@@ -83,6 +78,43 @@ TextEditorConfigs imageEditorTextConfigs(BuildContext context) {);}+class ImageEditorTextPage extends TextEditor {+ const ImageEditorTextPage({+ super.key,+ super.heroTag,+ super.layer,+ super.configs,+ super.callbacks,+ super.imageSize,+ required super.theme,+ });++ @override+ TextEditorState createState() => _ImageEditorTextPageState();+}++class _ImageEditorTextPageState extends TextEditorState {+ late TextEditorConfigs _textConfigs = widget.configs.textEditor;++ @override+ TextEditorConfigs get textEditorConfigs => _textConfigs;++ @override+ Widget build(BuildContext context) {+ final configs = widget.configs.textEditor;+ _textConfigs = configs.copyWith(+ style: configs.style.copyWith(+ textFieldPadding: EdgeInsets.only(+ top: MediaQuery.orientationOf(context) == Orientation.landscape+ ? 0+ : MediaQuery.sizeOf(context).height * _textFieldTopFraction,+ ),+ ),+ );+ return super.build(context);+ }+}+const _textFieldTopFraction = 0.12;const _controlSize = 48.0;const _rowHeight = 48.0;diff --git a/mobile/apps/photos/test/ui/tools/editor/image_editor_text_test.dart b/mobile/apps/photos/test/ui/tools/editor/image_editor_text_test.dartindex 8ba0f90a3b..4f6c0604a9 100644--- a/mobile/apps/photos/test/ui/tools/editor/image_editor_text_test.dart+++ b/mobile/apps/photos/test/ui/tools/editor/image_editor_text_test.dart@@ -97,14 +97,16 @@ void main() {final layer = find.byKey(editor.activeLayers.single.keyInternalSize);await _tap(tester, layer);- expect(find.byType(TextEditor), findsNothing);+ expect(find.bySubtype<TextEditor>(), findsNothing);now = now.add(kDoubleTapTimeout + const Duration(milliseconds: 1));await tester.tap(layer);await tester.pump(const Duration(milliseconds: 50));- expect(find.byType(TextEditor), findsNothing);+ expect(find.bySubtype<TextEditor>(), findsNothing);now = now.add(const Duration(milliseconds: 50));await _tap(tester, layer);- final reopened = tester.state<TextEditorState>(find.byType(TextEditor));+ final reopened = tester.state<TextEditorState>(+ find.bySubtype<TextEditor>(),+ );expect(reopened.textCtrl.text, 'Hello');expect(reopened.focusNode.hasFocus, isTrue);expect(tester.testTextInput.isVisible, isTrue);@@ -126,7 +128,7 @@ void main() {await tester.tap(layer);await tester.tap(layer);await tester.pumpAndSettle();- expect(find.byType(TextEditor), findsNothing);+ expect(find.bySubtype<TextEditor>(), findsNothing);expect(editor.activeLayers, hasLength(1));editor.undoAction();@@ -168,23 +170,24 @@ void main() {await first.up();await second.up();await tester.pumpAndSettle();- expect(find.byType(TextEditor), findsNothing);+ expect(find.bySubtype<TextEditor>(), findsNothing);await tester.tapAt(center);await tester.dragFrom(center, const Offset(45, 0));await tester.dragFrom(center + const Offset(45, 0), const Offset(-45, 0));await tester.pumpAndSettle();- expect(find.byType(TextEditor), findsNothing);+ expect(find.bySubtype<TextEditor>(), findsNothing);});- testWidgets('typed text remains visible above the bar in landscape', (+ testWidgets('typed text remains visible after rotating to landscape', (tester,) async {- tester.view.physicalSize = const Size(874, 402);+ tester.view.physicalSize = const Size(402, 874);tester.view.devicePixelRatio = 1;- tester.view.viewInsets = const FakeViewPadding(bottom: 250);addTearDown(tester.view.reset);await _openEditor(tester);+ tester.view.physicalSize = const Size(874, 402);+ tester.view.viewInsets = const FakeViewPadding(bottom: 250);await tester.pumpAndSettle();final fieldBottom = tester.getBottomLeft(find.byType(TextField)).dy;