Skip to content

armgit / ente

Public Imported from GitHub
0

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

[locker] Only show scanner wait hints after a real wait

laurenspriem578ee1b27f7d
diff --git a/mobile/apps/locker/lib/ui/pages/scanner/delayed_reveal.dart b/mobile/apps/locker/lib/ui/pages/scanner/delayed_reveal.dart
new file mode 100644
index 0000000000..f130d06b38
--- /dev/null
+++ b/mobile/apps/locker/lib/ui/pages/scanner/delayed_reveal.dart
@@ -0,0 +1,70 @@
+import 'dart:async';
+
+import 'package:ente_components/ente_components.dart';
+import 'package:flutter/material.dart';
+
+class DelayedReveal extends StatefulWidget {
+ const DelayedReveal({
+ super.key,
+ required this.visible,
+ required this.child,
+ this.delay = const Duration(milliseconds: 700),
+ });
+
+ final bool visible;
+ final Widget child;
+ final Duration delay;
+
+ @override
+ State<DelayedReveal> createState() => _DelayedRevealState();
+}
+
+class _DelayedRevealState extends State<DelayedReveal> {
+ Timer? _timer;
+ bool _shown = false;
+
+ @override
+ void initState() {
+ super.initState();
+ _sync();
+ }
+
+ @override
+ void didUpdateWidget(DelayedReveal oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (oldWidget.visible != widget.visible) _sync();
+ }
+
+ void _sync() {
+ _timer?.cancel();
+ _timer = null;
+ if (widget.visible) {
+ _timer = Timer(widget.delay, () {
+ if (mounted) setState(() => _shown = true);
+ });
+ } else if (_shown) {
+ setState(() => _shown = false);
+ }
+ }
+
+ @override
+ void dispose() {
+ _timer?.cancel();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return AnimatedSize(
+ duration: Motion.standard,
+ curve: Curves.easeInOut,
+ child: _shown
+ ? AnimatedOpacity(
+ opacity: 1,
+ duration: Motion.standard,
+ child: widget.child,
+ )
+ : const SizedBox.shrink(),
+ );
+ }
+}
diff --git a/mobile/apps/locker/lib/ui/pages/scanner/scanner_capture_page.dart b/mobile/apps/locker/lib/ui/pages/scanner/scanner_capture_page.dart
index b5fe470385..be84962cf6 100644
--- a/mobile/apps/locker/lib/ui/pages/scanner/scanner_capture_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/scanner/scanner_capture_page.dart
@@ -15,6 +15,7 @@ import 'package:locker/services/scanner/scan_geometry.dart';
import 'package:locker/services/scanner/scan_session_controller.dart';
import 'package:locker/services/scanner/scanner_models.dart';
import 'package:locker/ui/pages/scanner/capture_flight.dart';
+import 'package:locker/ui/pages/scanner/delayed_reveal.dart';
import 'package:locker/ui/pages/scanner/scan_quad_overlay.dart';
import 'package:locker/ui/pages/scanner/scanner_review_page.dart';
import 'package:logging/logging.dart';
@@ -786,44 +787,39 @@ class _PreparingHint extends StatelessWidget {
@override
Widget build(BuildContext context) {
final colors = context.componentColors;
- return AnimatedSize(
- duration: Motion.standard,
- curve: Curves.easeInOut,
- child: visible
- ? Padding(
- padding: const EdgeInsets.only(bottom: Spacing.md),
- child: Container(
- padding: const EdgeInsets.symmetric(
- horizontal: Spacing.md,
- vertical: Spacing.sm,
- ),
- decoration: BoxDecoration(
- color: Colors.black.withValues(alpha: 0.4),
- borderRadius: BorderRadius.circular(22),
- ),
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- SizedBox(
- width: 14,
- height: 14,
- child: CircularProgressIndicator(
- strokeWidth: 2,
- color: colors.specialWhite,
- ),
- ),
- const SizedBox(width: Spacing.sm),
- Text(
- context.strings.scannerPreparing,
- style: TextStyles.mini.copyWith(
- color: colors.specialWhite,
- ),
- ),
- ],
+ return DelayedReveal(
+ visible: visible,
+ child: Padding(
+ padding: const EdgeInsets.only(bottom: Spacing.md),
+ child: Container(
+ padding: const EdgeInsets.symmetric(
+ horizontal: Spacing.md,
+ vertical: Spacing.sm,
+ ),
+ decoration: BoxDecoration(
+ color: Colors.black.withValues(alpha: 0.4),
+ borderRadius: BorderRadius.circular(22),
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ SizedBox(
+ width: 14,
+ height: 14,
+ child: CircularProgressIndicator(
+ strokeWidth: 2,
+ color: colors.specialWhite,
),
),
- )
- : const SizedBox.shrink(),
+ const SizedBox(width: Spacing.sm),
+ Text(
+ context.strings.scannerPreparing,
+ style: TextStyles.mini.copyWith(color: colors.specialWhite),
+ ),
+ ],
+ ),
+ ),
+ ),
);
}
}
diff --git a/mobile/apps/locker/lib/ui/pages/scanner/scanner_review_page.dart b/mobile/apps/locker/lib/ui/pages/scanner/scanner_review_page.dart
index 90d02fc4cd..f650cf2627 100644
--- a/mobile/apps/locker/lib/ui/pages/scanner/scanner_review_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/scanner/scanner_review_page.dart
@@ -13,6 +13,7 @@ import 'package:locker/services/scanner/scan_geometry.dart';
import 'package:locker/services/scanner/scan_session_controller.dart';
import 'package:locker/services/scanner/scanner_models.dart';
import 'package:locker/ui/components/text_input_sheet.dart';
+import 'package:locker/ui/pages/scanner/delayed_reveal.dart';
import 'package:locker/ui/pages/scanner/scanner_crop_page.dart';
import 'package:share_plus/share_plus.dart';
@@ -364,20 +365,23 @@ class _ScannerReviewPageState extends State<ScannerReviewPage>
Widget _buildProcessingState(ColorTokens colors) {
return Center(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- const SizedBox(
- width: 28,
- height: 28,
- child: CircularProgressIndicator(strokeWidth: 2.5),
- ),
- const SizedBox(height: Spacing.lg),
- Text(
- context.strings.scanProcessing,
- style: TextStyles.body.copyWith(color: colors.textLighter),
- ),
- ],
+ child: DelayedReveal(
+ visible: true,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ const SizedBox(
+ width: 28,
+ height: 28,
+ child: CircularProgressIndicator(strokeWidth: 2.5),
+ ),
+ const SizedBox(height: Spacing.lg),
+ Text(
+ context.strings.scanProcessing,
+ style: TextStyles.body.copyWith(color: colors.textLighter),
+ ),
+ ],
+ ),
),
);
}