Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix: dynamically position text detection button to avoid layout overlap (#9283)

benny10benaf9f81b7851b
diff --git a/mobile/apps/photos/lib/ui/viewer/file/text_detection_overlay_button.dart b/mobile/apps/photos/lib/ui/viewer/file/text_detection_overlay_button.dart
index 415c2ab43d..81922cc80b 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/text_detection_overlay_button.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/text_detection_overlay_button.dart
@@ -184,7 +184,30 @@ class _TextDetectionOverlayButtonState
if (shouldHide) {
return const SizedBox.shrink();
}
- final double bottomOffset = MediaQuery.paddingOf(context).bottom + 72.0;
+
+ double bottomOffset = MediaQuery.paddingOf(context).bottom + 72.0;
+
+ final caption = widget.file.caption;
+ if (caption != null && caption.trim().isNotEmpty) {
+ // 1. Configure the text engine with a 3-line maximum
+ final textPainter = TextPainter(
+ text: TextSpan(
+ text: caption.trim(),
+ style: getEnteTextTheme(context).small,
+ ),
+ textDirection: TextDirection.ltr,
+ textScaler: MediaQuery.textScalerOf(context),
+ maxLines: 3,
+ );
+
+ // 2. Measure against the available screen width (assuming ~16px padding on each side)
+ final double maxWidth = MediaQuery.sizeOf(context).width - 32.0;
+ textPainter.layout(maxWidth: maxWidth);
+
+ // 3. Add the exact calculated text height (capped at 3 lines) + 24px safe padding buffer
+ bottomOffset += textPainter.height + 24.0;
+ }
+
return Positioned(
bottom: bottomOffset,
left: 0,
@@ -271,4 +294,4 @@ class _DetectionResult {
final String? localPath;
const _DetectionResult({required this.hasText, this.localPath});
-}
+}
\ No newline at end of file