Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Smooth onboarding keyboard transitions

r4khul22de3b86f796
diff --git a/mobile/apps/photos/lib/ui/account/email_entry_page.dart b/mobile/apps/photos/lib/ui/account/email_entry_page.dart
index ad1f8b14aa..ebeb220dd7 100644
--- a/mobile/apps/photos/lib/ui/account/email_entry_page.dart
+++ b/mobile/apps/photos/lib/ui/account/email_entry_page.dart
@@ -273,8 +273,6 @@ class _EmailEntryPageState extends State<EmailEntryPage> {
isCreateAccountScreen: true,
purpose: "signup",
);
- if (!mounted) return;
- FocusScope.of(context).unfocus();
}
Future<void> _updateReferralSourceFieldVisibility() async {
diff --git a/mobile/apps/photos/lib/ui/account/login_page.dart b/mobile/apps/photos/lib/ui/account/login_page.dart
index ce63437663..2a1c29f960 100644
--- a/mobile/apps/photos/lib/ui/account/login_page.dart
+++ b/mobile/apps/photos/lib/ui/account/login_page.dart
@@ -24,6 +24,7 @@ class LoginPage extends StatefulWidget {
class _LoginPageState extends State<LoginPage> {
final _emailController = TextEditingController();
bool _emailIsValid = false;
+ bool _isSubmitting = false;
bool _showValidationMessage = false;
String? _email;
Timer? _validationTimer;
@@ -62,12 +63,15 @@ class _LoginPageState extends State<LoginPage> {
showDeveloperSettingsTapArea: true,
body: _getBody(),
actions: [
- ButtonComponent(
- key: const ValueKey("logInButton"),
- label: context.strings.continueLabel,
- shouldShowSuccessState: false,
- isDisabled: !_emailIsValid,
- onTap: _emailIsValid ? _submitLoginEmail : null,
+ TextFieldTapRegion(
+ groupId: _emailController,
+ child: ButtonComponent(
+ key: const ValueKey("logInButton"),
+ label: context.strings.continueLabel,
+ shouldShowSuccessState: false,
+ isDisabled: !_emailIsValid,
+ onTap: _emailIsValid ? _submitLoginEmail : null,
+ ),
),
OnboardingAccountPrompt(
question: context.strings.dontHaveAnAccount,
@@ -94,12 +98,12 @@ class _LoginPageState extends State<LoginPage> {
label: context.strings.email,
hintText: context.strings.emailHint,
controller: _emailController,
+ groupId: _emailController,
keyboardType: TextInputType.emailAddress,
autofillHints: const [AutofillHints.email],
autocorrect: false,
autofocus: true,
isRequired: true,
- shouldUnfocusOnClearOrSubmit: true,
onSubmit: (_) => _submitLoginEmail(),
onChanged: _onEmailChanged,
message: _showValidationMessage
@@ -143,6 +147,7 @@ class _LoginPageState extends State<LoginPage> {
}
Future<void> _submitLoginEmail() async {
+ if (_isSubmitting) return;
final trimmed = _emailController.text.trim();
final isValid = EmailValidator.validate(trimmed);
if (!isValid) {
@@ -154,16 +159,21 @@ class _LoginPageState extends State<LoginPage> {
return;
}
_email = trimmed;
- await _onLoginPressed();
+ _isSubmitting = true;
+ try {
+ await _onLoginPressed(trimmed);
+ } finally {
+ _isSubmitting = false;
+ }
}
- Future<void> _onLoginPressed() async {
- await UserService.instance.setEmail(_email!);
+ Future<void> _onLoginPressed(String email) async {
+ await UserService.instance.setEmail(email);
Configuration.instance.resetVolatilePassword();
SrpAttributes? attr;
bool isEmailVerificationEnabled = true;
try {
- attr = await UserService.instance.getSrpAttributes(_email!);
+ attr = await UserService.instance.getSrpAttributes(email);
isEmailVerificationEnabled = attr.isEmailMFAEnabled;
} catch (e) {
if (e is! SrpSetupNotCompleteError) {
@@ -184,12 +194,10 @@ class _LoginPageState extends State<LoginPage> {
if (!mounted) return;
await UserService.instance.sendOtt(
context,
- _email!,
+ email,
isCreateAccountScreen: false,
purpose: "login",
);
}
- if (!mounted) return;
- FocusScope.of(context).unfocus();
}
}
diff --git a/mobile/apps/photos/lib/ui/account/login_pwd_verification_page.dart b/mobile/apps/photos/lib/ui/account/login_pwd_verification_page.dart
index 62e36106ce..233ca9710b 100644
--- a/mobile/apps/photos/lib/ui/account/login_pwd_verification_page.dart
+++ b/mobile/apps/photos/lib/ui/account/login_pwd_verification_page.dart
@@ -4,6 +4,7 @@ import "package:ente_crypto/ente_crypto.dart";
import "package:ente_strings/ente_strings.dart";
import "package:flutter/foundation.dart";
import 'package:flutter/material.dart';
+import "package:flutter/services.dart";
import "package:logging/logging.dart";
import 'package:photos/core/configuration.dart';
import "package:photos/gateways/users/models/srp.dart";
@@ -27,6 +28,8 @@ class LoginPasswordVerificationPage extends StatefulWidget {
class _LoginPasswordVerificationPageState
extends State<LoginPasswordVerificationPage> {
final _passwordController = TextEditingController();
+ final _passwordFocusNode = FocusNode();
+ bool _isSubmitting = false;
String? email;
bool _hasPassword = false;
bool _isPasswordIncorrect = false;
@@ -44,6 +47,7 @@ class _LoginPasswordVerificationPageState
@override
void dispose() {
+ _passwordFocusNode.dispose();
_passwordController.dispose();
super.dispose();
}
@@ -67,15 +71,21 @@ class _LoginPasswordVerificationPageState
}
Future<void> _verifyEnteredPassword() async {
- if (!_hasPassword) {
+ if (!_hasPassword || _isSubmitting) {
return;
}
- FocusScope.of(context).unfocus();
- await verifyPassword(context, _passwordController.text);
+ _isSubmitting = true;
+ _passwordFocusNode.unfocus();
+ try {
+ await verifyPassword(context, _passwordController.text);
+ } finally {
+ _isSubmitting = false;
+ }
}
Widget _getBody() {
return AutofillGroup(
+ onDisposeAction: AutofillContextAction.cancel,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
@@ -95,6 +105,7 @@ class _LoginPasswordVerificationPageState
label: context.strings.password,
hintText: context.strings.enterYourPassword,
controller: _passwordController,
+ focusNode: _passwordFocusNode,
isPasswordInput: true,
isRequired: true,
autocorrect: false,
@@ -164,6 +175,7 @@ class _LoginPasswordVerificationPageState
password,
dialog,
);
+ if (mounted) TextInput.finishAutofillContext();
} on DioException catch (e, s) {
await dialog.hide();
if (e.response != null && e.response!.statusCode == 401) {
diff --git a/mobile/apps/photos/lib/ui/account/onboarding_page_scaffold.dart b/mobile/apps/photos/lib/ui/account/onboarding_page_scaffold.dart
index 3c9da018df..1b8974ef2e 100644
--- a/mobile/apps/photos/lib/ui/account/onboarding_page_scaffold.dart
+++ b/mobile/apps/photos/lib/ui/account/onboarding_page_scaffold.dart
@@ -2,6 +2,7 @@ import "dart:async";
import "dart:math" as math;
import "package:ente_components/ente_components.dart";
+import "package:flutter/foundation.dart";
import "package:flutter/material.dart";
import "package:flutter_svg/flutter_svg.dart";
import "package:hugeicons/hugeicons.dart";
@@ -47,6 +48,7 @@ class OnboardingPageScaffold extends StatefulWidget {
required this.body,
this.actions = const [],
this.headerHeight = defaultHeaderHeight,
+ this.minimumKeyboardHeaderHeight = 0,
this.showBackButton = true,
this.titleBarStyle = OnboardingTitleBarStyle.card,
this.headerTrailing,
@@ -65,6 +67,7 @@ class OnboardingPageScaffold extends StatefulWidget {
final Widget body;
final List<Widget> actions;
final double headerHeight;
+ final double minimumKeyboardHeaderHeight;
final bool showBackButton;
final OnboardingTitleBarStyle titleBarStyle;
final Widget? headerTrailing;
@@ -80,6 +83,7 @@ class OnboardingPageScaffold extends StatefulWidget {
class OnboardingPageScaffoldState extends State<OnboardingPageScaffold> {
static const double _cardRadius = Radii.bottomSheet;
+ static const double _cardBorderWidth = 1;
static const double _titleBarHeight = 48;
static const double _titleBarTopInset = 33;
static const double _titleBarBottomInset = 17;
@@ -92,20 +96,52 @@ class OnboardingPageScaffoldState extends State<OnboardingPageScaffold> {
static const double _footerInset = Spacing.xxl;
rive.FileLoader? _fileLoader;
+ late final Widget _illustrationWidget;
rive.ViewModelInstance? _viewModel;
String? _latestTrigger;
Timer? _deferredTrigger;
DateTime _entryCompletesAt = DateTime.now();
+ DateTime? _illustrationPausedAt;
ModalRoute<dynamic>? _route;
- bool _isIllustrationHidden = false;
- bool _hasBuilt = false;
- bool _hasExited = false;
- int _illustrationGeneration = 0;
+ ValueNotifier<bool>? _userGestureInProgress;
+ final _titleKey = GlobalKey();
+ final _bodyKey = GlobalKey();
+ final _footerKey = GlobalKey();
+ final _scrollKey = GlobalKey();
+ EdgeInsets _viewInsets = EdgeInsets.zero;
+ double? _contentHeight;
+ double _measuredTitleHeight = _titleBarHeight;
+ double _measuredFooterHeight = 0;
+ double _footerSafeArea = 0;
+ bool _measurementScheduled = false;
+
+ bool get _isTransitioning =>
+ (_route?.animation?.isAnimating ?? false) ||
+ (_route?.secondaryAnimation?.isAnimating ?? false) ||
+ (_userGestureInProgress?.value ?? false);
+
+ double get _titleTopInset =>
+ widget.titleBarStyle == OnboardingTitleBarStyle.card
+ ? _titleBarTopInset
+ : _inlineTitleTopInset;
+
+ double get _keyboardProgress =>
+ (_viewInsets.bottom / OnboardingPageScaffold.defaultHeaderHeight).clamp(
+ 0.0,
+ 1.0,
+ );
+
+ double get _titleBottomInset {
+ final inset = widget.titleBarStyle == OnboardingTitleBarStyle.card
+ ? _titleBarBottomInset
+ : _inlineTitleBottomInset;
+ return inset + (Spacing.sm - inset) * _keyboardProgress;
+ }
// Wait for entry to finish; interrupting it can freeze the pose.
void trigger(String name) {
_latestTrigger = name;
- if (_viewModel == null) {
+ if (_viewModel == null || _illustrationPausedAt != null) {
return;
}
_deferredTrigger?.cancel();
@@ -123,6 +159,8 @@ class OnboardingPageScaffoldState extends State<OnboardingPageScaffold> {
void initState() {
super.initState();
_fileLoader = _loadIllustration();
+ _illustrationWidget = _buildIllustration();
+ _scheduleContentMeasurement();
}
// Keep onboarding usable when the native Rive runtime is unavailable.
@@ -140,13 +178,27 @@ class OnboardingPageScaffoldState extends State<OnboardingPageScaffold> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
+ if (!TickerMode.valuesOf(context).enabled) {
+ _illustrationPausedAt ??= DateTime.now();
+ _deferredTrigger?.cancel();
+ } else if (_illustrationPausedAt != null) {
+ _entryCompletesAt = _entryCompletesAt.add(
+ DateTime.now().difference(_illustrationPausedAt!),
+ );
+ _illustrationPausedAt = null;
+ final latest = _latestTrigger;
+ if (latest != null) trigger(latest);
+ }
final route = ModalRoute.of(context);
if (route != _route) {
_route?.animation?.removeStatusListener(_onRouteAnimationStatus);
_route?.secondaryAnimation?.removeStatusListener(
_onSecondaryAnimationStatus,
);
+ _userGestureInProgress?.removeListener(_onUserGestureChanged);
_route = route;
+ _userGestureInProgress = route?.navigator?.userGestureInProgressNotifier;
+ _userGestureInProgress?.addListener(_onUserGestureChanged);
route?.animation?.addStatusListener(_onRouteAnimationStatus);
route?.secondaryAnimation?.addStatusListener(_onSecondaryAnimationStatus);
}
@@ -158,6 +210,7 @@ class OnboardingPageScaffoldState extends State<OnboardingPageScaffold> {
_route?.secondaryAnimation?.removeStatusListener(
_onSecondaryAnimationStatus,
);
+ _userGestureInProgress?.removeListener(_onUserGestureChanged);
_deferredTrigger?.cancel();
_viewModel = null;
_fileLoader?.dispose();
@@ -165,30 +218,50 @@ class OnboardingPageScaffoldState extends State<OnboardingPageScaffold> {
}
void _onRouteAnimationStatus(AnimationStatus status) {
- if (status == AnimationStatus.reverse) {
- _triggerExit();
- } else if (status == AnimationStatus.forward) {
- _restartIllustration();
+ if (status == AnimationStatus.completed) {
+ setState(() {});
+ _revealFocusedInput();
}
}
void _onSecondaryAnimationStatus(AnimationStatus status) {
- if (status == AnimationStatus.forward) {
- _triggerExit();
- } else if (status == AnimationStatus.reverse ||
- status == AnimationStatus.dismissed) {
- _restartIllustration();
+ if (status == AnimationStatus.dismissed ||
+ status == AnimationStatus.completed) {
+ setState(() {});
+ _revealFocusedInput();
}
}
- void _restartIllustration() {
- if (!_hasExited) return;
- _hasExited = false;
- _deferredTrigger?.cancel();
- if (_viewModel == null) return;
- _viewModel = null;
- setState(() {
- _illustrationGeneration++;
+ void _onUserGestureChanged() {
+ if (!(_userGestureInProgress?.value ?? false)) {
+ setState(() {});
+ _revealFocusedInput();
+ }
+ }
+
+ void _revealFocusedInput() {
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (!mounted || !(_route?.isCurrent ?? true) || _isTransitioning) {
+ return;
+ }
+ final focusContext = FocusManager.instance.primaryFocus?.context;
+ if (focusContext == null || !focusContext.mounted) return;
+ if (focusContext.findAncestorStateOfType<OnboardingPageScaffoldState>() !=
+ this) {
+ return;
+ }
+ final input = focusContext.findAncestorStateOfType<EditableTextState>();
+ if (input == null || !input.textEditingValue.selection.isValid) return;
+ if (input.widget.maxLines == 1) {
+ unawaited(
+ Scrollable.ensureVisible(
+ focusContext,
+ alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd,
+ ),
+ );
+ } else {
+ input.bringIntoView(input.textEditingValue.selection.extent);
+ }
});
}
@@ -212,64 +285,144 @@ class OnboardingPageScaffoldState extends State<OnboardingPageScaffold> {
Duration _entryDuration = const Duration(seconds: 5);
void _playEntry() {
- _entryCompletesAt = DateTime.now().add(_entryDuration);
+ _entryCompletesAt = (_illustrationPausedAt ?? DateTime.now()).add(
+ _entryDuration,
+ );
_trigger("entry");
}
- void _triggerExit() {
- if (_hasExited) return;
- _hasExited = true;
- _trigger("exit");
- }
-
void _trigger(String name) {
_viewModel?.trigger(name)?.trigger();
}
void _onHeaderAnimationEnd() {
- if (!mounted) return;
- final isKeyboardOpen = MediaQuery.viewInsetsOf(context).bottom > 0;
- if (_isIllustrationHidden == isKeyboardOpen) return;
- setState(() {
- _isIllustrationHidden = isKeyboardOpen;
+ if (_viewInsets.bottom > 0) _revealFocusedInput();
+ }
+
+ void _scheduleContentMeasurement() {
+ if (_measurementScheduled) return;
+ _measurementScheduled = true;
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ _measurementScheduled = false;
+ if (!mounted) return;
+ final titleSize = _titleKey.currentContext?.size;
+ final bodySize = _bodyKey.currentContext?.size;
+ if (titleSize == null || bodySize == null) return;
+ final footerSize = _footerKey.currentContext?.size;
+ final contentHeight =
+ _cardBorderWidth * 2 +
+ titleSize.height +
+ bodySize.height +
+ (footerSize == null
+ ? 0
+ : footerSize.height - _footerSafeArea - _footerInset * 2);
+ final footerHeight = footerSize?.height ?? 0;
+ if (_contentHeight != null &&
+ (_contentHeight! - contentHeight).abs() < precisionErrorTolerance &&
+ (_measuredTitleHeight - titleSize.height).abs() <
+ precisionErrorTolerance &&
+ (_measuredFooterHeight - footerHeight).abs() <
+ precisionErrorTolerance) {
+ return;
+ }
+ setState(() {
+ _contentHeight = contentHeight;
+ _measuredTitleHeight = titleSize.height;
+ _measuredFooterHeight = footerHeight;
+ });
});
}
+ Widget _measureContent(GlobalKey key, Widget child) {
+ return SizeChangedLayoutNotifier(key: key, child: child);
+ }
+
@override
Widget build(BuildContext context) {
final colors = context.componentColors;
final mediaQuery = MediaQuery.of(context);
+ final keyboardChanged = _viewInsets != mediaQuery.viewInsets;
+ _viewInsets = mediaQuery.viewInsets;
final isKeyboardOpen = mediaQuery.viewInsets.bottom > 0;
- final headerHeight =
- mediaQuery.padding.top + (isKeyboardOpen ? 0 : widget.headerHeight);
- if (!isKeyboardOpen) {
- _isIllustrationHidden = false;
- } else if (!_hasBuilt) {
- _isIllustrationHidden = true;
- }
- _hasBuilt = true;
-
- return Scaffold(
- backgroundColor: colors.green,
- resizeToAvoidBottomInset: true,
- body: LayoutBuilder(
- builder: (context, constraints) {
- return Column(
- children: [
- ConstrainedBox(
- constraints: BoxConstraints(maxHeight: constraints.maxHeight),
- child: AnimatedContainer(
- duration: Motion.slow,
- curve: Curves.easeOutCubic,
- height: headerHeight,
- onEnd: _onHeaderAnimationEnd,
- child: _buildHeader(colors, mediaQuery),
+
+ return NotificationListener<SizeChangedLayoutNotification>(
+ onNotification: (_) {
+ _scheduleContentMeasurement();
+ return false;
+ },
+ child: Scaffold(
+ backgroundColor: colors.backgroundBase,
+ resizeToAvoidBottomInset: true,
+ body: LayoutBuilder(
+ builder: (context, constraints) {
+ final availableHeaderHeight = _contentHeight == null
+ ? widget.headerHeight
+ : constraints.maxHeight -
+ mediaQuery.padding.top -
+ _contentHeight! -
+ _titleTopInset -
+ _titleBottomInset -
+ (widget.actions.isEmpty
+ ? 0
+ : _footerInset * 2 + mediaQuery.padding.bottom);
+ final minimumHeaderHeight =
+ widget.titleBarStyle == OnboardingTitleBarStyle.header
+ ? math.min(
+ widget.headerHeight,
+ _headerBarCenter + _titleBarHeight / 2,
+ )
+ : math.min(
+ widget.minimumKeyboardHeaderHeight,
+ math.max(
+ 0,
+ constraints.maxHeight -
+ mediaQuery.padding.top -
+ _measuredFooterHeight -
+ _titleTopInset -
+ _titleBottomInset -
+ _measuredTitleHeight -
+ _titleBarHeight,
+ ),
+ );
+ final keyboardHeaderHeight = availableHeaderHeight.clamp(
+ minimumHeaderHeight,
+ widget.headerHeight,
+ );
+ final headerHeight =
+ mediaQuery.padding.top +
+ (isKeyboardOpen ? keyboardHeaderHeight : widget.headerHeight);
+ return Column(
+ children: [
+ ConstrainedBox(
+ constraints: BoxConstraints(maxHeight: constraints.maxHeight),
+ child: AnimatedContainer(
+ duration:
+ _isTransitioning ||
+ _contentHeight == null ||
+ keyboardChanged ||
+ mediaQuery.disableAnimations
+ ? Duration.zero
+ : Motion.slow,
+ curve: Curves.easeOutCubic,
+ height: headerHeight,
+ onEnd: _onHeaderAnimationEnd,
+ child: _buildHeader(colors, mediaQuery),
+ ),
),
- ),
- Expanded(child: _buildCard(context, colors, mediaQuery)),
- ],
- );
- },
+ Expanded(
+ child: LayoutBuilder(
+ builder: (context, constraints) => _buildCard(
+ context,
+ colors,
+ mediaQuery,
+ constraints.maxHeight,
+ ),
+ ),
+ ),
+ ],
+ );
+ },
+ ),
),
);
}
@@ -278,83 +431,125 @@ class OnboardingPageScaffoldState extends State<OnboardingPageScaffold> {
final illustration = widget.illustration;
final hasHeaderBar = widget.titleBarStyle == OnboardingTitleBarStyle.header;
final canPop = widget.showBackButton && (_route?.canPop ?? false);
- return Stack(
- clipBehavior: Clip.none,
- children: [
- Positioned.fill(
- bottom: -_cardRadius,
- child: _OnboardingBackdrop(color: colors.green),
- ),
- if (hasHeaderBar)
- Positioned(
- top:
- mediaQuery.padding.top + _headerBarCenter - _titleBarHeight / 2,
- left: mediaQuery.padding.left + _headerBarLeftInset,
- right: mediaQuery.padding.right + _headerBarRightInset,
- height: _titleBarHeight,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- SizedBox(
- width: _titleBarHeight,
- child: canPop
- ? _backButton(context, colors.specialWhite)
- : null,
- ),
- SizedBox(width: _titleBarHeight, child: widget.headerTrailing),
- ],
+ return LayoutBuilder(
+ builder: (context, constraints) {
+ final illustrationScale = widget.headerHeight > 0
+ ? ((constraints.maxHeight - mediaQuery.padding.top) /
+ widget.headerHeight)
+ .clamp(0.0, 1.0)
+ : 0.0;
+ return Stack(
+ clipBehavior: Clip.none,
+ children: [
+ Positioned.fill(
+ bottom: -_cardRadius,
+ child: _OnboardingBackdrop(color: colors.green),
),
- ),
- if (_fileLoader != null)
- Positioned(
- top: mediaQuery.padding.top + illustration.topOffset,
- left: 0,
- right: 0,
- height: illustration.height,
- child: IgnorePointer(
- child: Visibility(
- visible: !_isIllustrationHidden,
- maintainState: true,
- child: Align(
- alignment: Alignment.topCenter,
- child: Transform.translate(
- offset: Offset(illustration.centerOffset, 0),
- child: SizedBox(
- width: illustration.width,
- height: illustration.height,
- child: rive.RiveWidgetBuilder(
- key: ValueKey(_illustrationGeneration),
- fileLoader: _fileLoader!,
- dataBind: rive.DataBind.auto(),
- onLoaded: _onLoaded,
- builder: (BuildContext context, rive.RiveState state) {
- if (state is rive.RiveLoaded) {
- return rive.RiveWidget(
- controller: state.controller,
- fit: rive.Fit.contain,
- );
- }
- return const SizedBox.shrink();
- },
+ if (hasHeaderBar)
+ Positioned(
+ top:
+ mediaQuery.padding.top +
+ _headerBarCenter -
+ _titleBarHeight / 2,
+ left: mediaQuery.padding.left + _headerBarLeftInset,
+ right: mediaQuery.padding.right + _headerBarRightInset,
+ height: _titleBarHeight,
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ SizedBox(
+ width: _titleBarHeight,
+ child: canPop
+ ? _backButton(context, colors.specialWhite)
+ : null,
+ ),
+ SizedBox(
+ width: _titleBarHeight,
+ child: widget.headerTrailing,
+ ),
+ ],
+ ),
+ ),
+ if (_fileLoader != null)
+ Positioned(
+ top:
+ mediaQuery.padding.top +
+ illustration.topOffset * illustrationScale,
+ left: 0,
+ right: 0,
+ height: illustration.height,
+ child: IgnorePointer(
+ child: Visibility(
+ visible: illustrationScale > 0,
+ maintainState: true,
+ child: Align(
+ alignment: Alignment.topCenter,
+ child: Transform.translate(
+ offset: Offset(
+ illustration.centerOffset * illustrationScale,
+ 0,
+ ),
+ child: Transform.scale(
+ scale: illustrationScale,
+ alignment: Alignment.topCenter,
+ child: _illustrationWidget,
+ ),
),
),
),
),
),
- ),
- ),
- ],
+ ],
+ );
+ },
+ );
+ }
+
+ Widget _buildIllustration() {
+ if (_fileLoader == null) return const SizedBox.shrink();
+ return RepaintBoundary(
+ child: SizedBox(
+ width: widget.illustration.width,
+ height: widget.illustration.height,
+ child: rive.RiveWidgetBuilder(
+ fileLoader: _fileLoader!,
+ dataBind: rive.DataBind.auto(),
+ onLoaded: _onLoaded,
+ builder: (context, state) {
+ if (state is rive.RiveLoaded) {
+ return rive.RiveWidget(
+ controller: state.controller,
+ fit: rive.Fit.contain,
+ );
+ }
+ return const SizedBox.shrink();
+ },
+ ),
+ ),
);
}
Widget _backButton(BuildContext context, Color color) {
- return IconButtonComponent(
- variant: IconButtonComponentVariant.unfilled,
- size: _titleBarHeight,
- iconSize: IconSizes.medium,
- icon: HugeIcon(icon: HugeIcons.strokeRoundedArrowLeft02, color: color),
- tooltip: MaterialLocalizations.of(context).backButtonTooltip,
- onTap: () => Navigator.of(context).maybePop(),
+ return ListenableBuilder(
+ listenable: FocusManager.instance,
+ builder: (context, child) {
+ final focusContext = FocusManager.instance.primaryFocus?.context;
+ final input = focusContext
+ ?.findAncestorStateOfType<EditableTextState>();
+ return TextFieldTapRegion(
+ key: ValueKey(input?.widget.groupId),
+ groupId: input?.widget.groupId ?? EditableText,
+ child: child!,
+ );
+ },
+ child: IconButtonComponent(
+ variant: IconButtonComponentVariant.unfilled,
+ size: _titleBarHeight,
+ iconSize: IconSizes.medium,
+ icon: HugeIcon(icon: HugeIcons.strokeRoundedArrowLeft02, color: color),
+ tooltip: MaterialLocalizations.of(context).backButtonTooltip,
+ onTap: () => Navigator.of(context).maybePop(),
+ ),
);
}
@@ -362,6 +557,7 @@ class OnboardingPageScaffoldState extends State<OnboardingPageScaffold> {
BuildContext context,
ColorTokens colors,
MediaQueryData mediaQuery,
+ double availableHeight,
) {
final hasCardTitleBar =
widget.titleBarStyle == OnboardingTitleBarStyle.card;
@@ -380,15 +576,17 @@ class OnboardingPageScaffoldState extends State<OnboardingPageScaffold> {
child: title,
)
: title;
- final hasPinnedFooter = widget.actions.isNotEmpty && widget.pinActions;
- final hasScrollingFooter = widget.actions.isNotEmpty && !widget.pinActions;
+ final isKeyboardOpen = mediaQuery.viewInsets.bottom > 0;
+ final hasPinnedFooter =
+ widget.actions.isNotEmpty && (widget.pinActions || isKeyboardOpen);
+ final hasScrollingFooter = widget.actions.isNotEmpty && !hasPinnedFooter;
return Container(
width: double.infinity,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
color: colors.backgroundBase,
- border: Border.all(color: colors.strokeDark),
+ border: Border.all(color: colors.strokeDark, width: _cardBorderWidth),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(_cardRadius),
),
@@ -396,91 +594,125 @@ class OnboardingPageScaffoldState extends State<OnboardingPageScaffold> {
child: Column(
children: [
Expanded(
- child: CustomScrollView(
- slivers: [
- if (hasCardTitleBar)
- SliverPadding(
- padding: EdgeInsets.fromLTRB(
- mediaQuery.padding.left +
- OnboardingPageScaffold.horizontalPadding -
- Spacing.md,
- _titleBarTopInset,
- mediaQuery.padding.right +
- OnboardingPageScaffold.horizontalPadding -
- Spacing.md,
- _titleBarBottomInset,
- ),
- sliver: SliverToBoxAdapter(
- child: Row(
- children: [
- SizedBox(
- width: _titleBarHeight,
- height: _titleBarHeight,
- child: canPop
- ? _backButton(context, colors.textBase)
- : null,
+ child: ListenableBuilder(
+ listenable: FocusManager.instance,
+ builder: (context, child) {
+ final input = FocusManager.instance.primaryFocus?.context
+ ?.findAncestorStateOfType<EditableTextState>();
+ return TextFieldTapRegion(
+ key: ValueKey(input?.widget.groupId),
+ groupId: input?.widget.groupId ?? EditableText,
+ child: GestureDetector(
+ behavior: HitTestBehavior.translucent,
+ onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
+ child: child!,
+ ),
+ );
+ },
+ child: CustomScrollView(
+ key: _scrollKey,
+ slivers: [
+ if (hasCardTitleBar)
+ SliverPadding(
+ padding: EdgeInsets.fromLTRB(
+ mediaQuery.padding.left +
+ OnboardingPageScaffold.horizontalPadding -
+ Spacing.md,
+ _titleTopInset,
+ mediaQuery.padding.right +
+ OnboardingPageScaffold.horizontalPadding -
+ Spacing.md,
+ _titleBottomInset,
+ ),
+ sliver: SliverToBoxAdapter(
+ child: _measureContent(
+ _titleKey,
+ Row(
+ children: [
+ SizedBox(
+ width: _titleBarHeight,
+ height: _titleBarHeight,
+ child: canPop
+ ? _backButton(context, colors.textBase)
+ : null,
+ ),
+ Expanded(child: titleContent),
+ const SizedBox(width: _titleBarHeight),
+ ],
),
- Expanded(child: titleContent),
- const SizedBox(width: _titleBarHeight),
- ],
+ ),
+ ),
+ )
+ else
+ SliverPadding(
+ padding: EdgeInsets.fromLTRB(
+ mediaQuery.padding.left +
+ OnboardingPageScaffold.horizontalPadding,
+ _titleTopInset,
+ mediaQuery.padding.right +
+ OnboardingPageScaffold.horizontalPadding,
+ _titleBottomInset,
+ ),
+ sliver: SliverToBoxAdapter(
+ child: _measureContent(_titleKey, titleContent),
),
),
- )
- else
SliverPadding(
- padding: EdgeInsets.fromLTRB(
- mediaQuery.padding.left +
+ padding: EdgeInsets.only(
+ left:
+ mediaQuery.padding.left +
OnboardingPageScaffold.horizontalPadding,
- _inlineTitleTopInset,
- mediaQuery.padding.right +
+ right:
+ mediaQuery.padding.right +
OnboardingPageScaffold.horizontalPadding,
- _inlineTitleBottomInset,
),
- sliver: SliverToBoxAdapter(child: titleContent),
- ),
- SliverPadding(
- padding: EdgeInsets.only(
- left:
- mediaQuery.padding.left +
- OnboardingPageScaffold.horizontalPadding,
- right:
- mediaQuery.padding.right +
- OnboardingPageScaffold.horizontalPadding,
- ),
- sliver: SliverLayoutBuilder(
- builder: (context, constraints) {
- final remaining =
- constraints.viewportMainAxisExtent -
- constraints.precedingScrollExtent;
- return SliverToBoxAdapter(
- child: ConstrainedBox(
- constraints: BoxConstraints(
- minHeight: math.max(0, remaining),
- ),
- child: Column(
- mainAxisAlignment: hasScrollingFooter
- ? MainAxisAlignment.spaceBetween
- : widget.isBodyCentered
- ? MainAxisAlignment.center
- : MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: [
- if (widget.isBodyCentered)
- const SizedBox.shrink(),
- widget.body,
- if (hasScrollingFooter)
- _buildFooter(mediaQuery, inline: true),
- ],
+ sliver: SliverLayoutBuilder(
+ builder: (context, constraints) {
+ if (_contentHeight == null) {
+ _scheduleContentMeasurement();
+ }
+ final remaining =
+ constraints.viewportMainAxisExtent -
+ constraints.precedingScrollExtent;
+ return SliverToBoxAdapter(
+ child: ConstrainedBox(
+ constraints: BoxConstraints(
+ minHeight: math.max(0, remaining),
+ ),
+ child: Column(
+ mainAxisAlignment: hasScrollingFooter
+ ? MainAxisAlignment.spaceBetween
+ : widget.isBodyCentered
+ ? MainAxisAlignment.center
+ : MainAxisAlignment.start,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ if (widget.isBodyCentered)
+ const SizedBox.shrink(),
+ _measureContent(_bodyKey, widget.body),
+ if (hasScrollingFooter)
+ _buildFooter(mediaQuery, inline: true),
+ ],
+ ),
),
- ),
- );
- },
+ );
+ },
+ ),
),
- ),
- ],
+ ],
+ ),
),
),
- if (hasPinnedFooter) _buildFooter(mediaQuery, inline: false),
+ if (hasPinnedFooter)
+ if (isKeyboardOpen)
+ ConstrainedBox(
+ constraints: BoxConstraints(maxHeight: availableHeight / 2),
+ child: SingleChildScrollView(
+ child: _buildFooter(mediaQuery, inline: false),
+ ),
+ )
+ else
+ _buildFooter(mediaQuery, inline: false),
],
),
);
@@ -488,22 +720,25 @@ class OnboardingPageScaffoldState extends State<OnboardingPageScaffold> {
Widget _buildFooter(MediaQueryData mediaQuery, {required bool inline}) {
final horizontalInset = inline ? 0.0 : _footerInset;
- return Padding(
- padding: EdgeInsets.fromLTRB(
- horizontalInset + (inline ? 0 : mediaQuery.padding.left),
- _footerInset,
- horizontalInset + (inline ? 0 : mediaQuery.padding.right),
- _footerInset +
- (mediaQuery.viewInsets.bottom > 0 ? 0 : mediaQuery.padding.bottom),
- ),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: [
- for (var i = 0; i < widget.actions.length; i++) ...[
- if (i > 0) const SizedBox(height: _footerSpacing),
- widget.actions[i],
+ _footerSafeArea = mediaQuery.padding.bottom;
+ return _measureContent(
+ _footerKey,
+ Padding(
+ padding: EdgeInsets.fromLTRB(
+ horizontalInset + (inline ? 0 : mediaQuery.padding.left),
+ _footerInset,
+ horizontalInset + (inline ? 0 : mediaQuery.padding.right),
+ _footerInset + _footerSafeArea,
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ for (var i = 0; i < widget.actions.length; i++) ...[
+ if (i > 0) const SizedBox(height: _footerSpacing),
+ widget.actions[i],
+ ],
],
- ],
+ ),
),
);
}
diff --git a/mobile/apps/photos/lib/ui/account/password_reentry_page.dart b/mobile/apps/photos/lib/ui/account/password_reentry_page.dart
index 741bf76f8e..ed6d448db6 100644
--- a/mobile/apps/photos/lib/ui/account/password_reentry_page.dart
+++ b/mobile/apps/photos/lib/ui/account/password_reentry_page.dart
@@ -5,6 +5,7 @@ import "package:ente_components/ente_components.dart";
import "package:ente_crypto/ente_crypto.dart";
import "package:ente_strings/ente_strings.dart";
import 'package:flutter/material.dart';
+import "package:flutter/services.dart" show TextInput;
import 'package:logging/logging.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/core/errors.dart';
@@ -30,6 +31,8 @@ class PasswordReentryPage extends StatefulWidget {
class _PasswordReentryPageState extends State<PasswordReentryPage> {
final _logger = Logger((_PasswordReentryPageState).toString());
final _passwordController = TextEditingController();
+ final _passwordFocusNode = FocusNode();
+ bool _isSubmitting = false;
String? email;
String? _volatilePassword;
bool _isPasswordIncorrect = false;
@@ -41,12 +44,15 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {
_volatilePassword = Configuration.instance.getVolatilePassword();
if (_volatilePassword != null) {
_passwordController.text = _volatilePassword!;
- Future.delayed(Duration.zero, () => verifyPassword(_volatilePassword!));
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (mounted) unawaited(_onVerifyPasswordPressed());
+ });
}
}
@override
void dispose() {
+ _passwordFocusNode.dispose();
_passwordController.dispose();
super.dispose();
}
@@ -72,15 +78,19 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {
}
Future<void> _onVerifyPasswordPressed() async {
- if (_passwordController.text.isEmpty) {
+ if (_passwordController.text.isEmpty || _isSubmitting) {
return;
}
- FocusScope.of(context).unfocus();
- await verifyPassword(_passwordController.text);
+ _isSubmitting = true;
+ try {
+ await verifyPassword(_passwordController.text);
+ } finally {
+ _isSubmitting = false;
+ }
}
Future<void> verifyPassword(String password) async {
- FocusScope.of(context).unfocus();
+ _passwordFocusNode.unfocus();
setState(() {
_isPasswordIncorrect = false;
});
@@ -133,6 +143,7 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {
);
return;
}
+ if (mounted) TextInput.finishAutofillContext();
await dialog.hide();
Configuration.instance.resetVolatilePassword();
await flagService.tryRefreshFlags();
@@ -190,6 +201,7 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {
Widget _getBody() {
return AutofillGroup(
+ onDisposeAction: AutofillContextAction.cancel,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
@@ -211,6 +223,7 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {
isRequired: true,
hintText: context.strings.enterYourPassword,
controller: _passwordController,
+ focusNode: _passwordFocusNode,
isPasswordInput: true,
autocorrect: false,
shouldUnfocusOnClearOrSubmit: true,
diff --git a/mobile/apps/photos/test/ui/account/onboarding_pages_test.dart b/mobile/apps/photos/test/ui/account/onboarding_pages_test.dart
index eb0c113709..44dd0e5c16 100644
--- a/mobile/apps/photos/test/ui/account/onboarding_pages_test.dart
+++ b/mobile/apps/photos/test/ui/account/onboarding_pages_test.dart
@@ -132,7 +132,7 @@ void main() {
tester.view.viewInsets = const FakeViewPadding(bottom: 291);
await settle(tester);
- expect(tester.getTopLeft(title).dy, lessThan(100));
+ expect(tester.getTopLeft(title).dy, greaterThan(200));
tester.view.viewInsets = FakeViewPadding.zero;
await settle(tester);
diff --git a/mobile/packages/ente_components/lib/components/text_input_component.dart b/mobile/packages/ente_components/lib/components/text_input_component.dart
index 4194ced188..602ab612aa 100644
--- a/mobile/packages/ente_components/lib/components/text_input_component.dart
+++ b/mobile/packages/ente_components/lib/components/text_input_component.dart
@@ -19,6 +19,7 @@ class TextInputComponent extends StatefulWidget {
super.key,
this.controller,
this.focusNode,
+ this.groupId,
this.label,
this.message,
this.hintText,
@@ -58,6 +59,7 @@ class TextInputComponent extends StatefulWidget {
final TextEditingController? controller;
final FocusNode? focusNode;
+ final Object? groupId;
final String? label;
final String? message;
final String? hintText;
@@ -146,7 +148,8 @@ class _TextInputComponentState extends State<TextInputComponent> {
@override
void didUpdateWidget(covariant TextInputComponent oldWidget) {
super.didUpdateWidget(oldWidget);
- if (oldWidget.isDisabled != widget.isDisabled) {
+ if (oldWidget.isDisabled != widget.isDisabled ||
+ oldWidget.groupId != widget.groupId) {
_configureGroupId();
}
if (oldWidget.submitNotifier != widget.submitNotifier) {
@@ -210,7 +213,7 @@ class _TextInputComponentState extends State<TextInputComponent> {
}
void _configureGroupId() {
- _groupId = _defaultGroupId;
+ _groupId = widget.groupId ?? _defaultGroupId;
if (widget.isDisabled) {
_groupId = _disabledGroupId;
}
@@ -347,26 +350,20 @@ class _TextInputComponentState extends State<TextInputComponent> {
),
),
if (message != null) ...[
- const SizedBox(height: Spacing.xs),
- ConstrainedBox(
- constraints: const BoxConstraints(minHeight: Spacing.lg),
- child: Row(
- children: [
- if (messageIcon != null) ...[
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: Spacing.xs),
- child: messageIcon,
- ),
- const SizedBox(width: Spacing.xs),
- ],
- Expanded(
- child: Text(
- message,
- style: TextStyles.tiny.copyWith(color: messageColor),
- ),
- ),
+ const SizedBox(height: Spacing.sm),
+ Row(
+ children: [
+ if (messageIcon != null) ...[
+ messageIcon,
+ const SizedBox(width: Spacing.sm),
],
- ),
+ Expanded(
+ child: Text(
+ message,
+ style: TextStyles.mini.copyWith(color: messageColor),
+ ),
+ ),
+ ],
),
],
],
@@ -479,7 +476,7 @@ class _TextInputComponentState extends State<TextInputComponent> {
return () {
_controller.clear();
if (widget.shouldUnfocusOnClearOrSubmit) {
- FocusScope.of(context).unfocus();
+ _focusNode.unfocus();
}
};
}
@@ -520,17 +517,17 @@ class _TextInputComponentState extends State<TextInputComponent> {
Widget? _messageIcon(Color color) {
if (widget.messageIcon != null) {
- return Icon(widget.messageIcon, size: IconSizes.tiny, color: color);
+ return Icon(widget.messageIcon, size: IconSizes.small, color: color);
}
return switch (widget.messageType) {
TextInputComponentMessageType.alert => HugeIcon(
icon: HugeIcons.strokeRoundedAlert02,
- size: IconSizes.tiny,
+ size: IconSizes.small,
color: color,
),
TextInputComponentMessageType.success => HugeIcon(
icon: HugeIcons.strokeRoundedTick02,
- size: IconSizes.tiny,
+ size: IconSizes.small,
color: color,
),
TextInputComponentMessageType.error ||
@@ -582,7 +579,7 @@ class _TextInputComponentState extends State<TextInputComponent> {
if (widget.textInputAction == TextInputAction.next) {
_focusNode.nextFocus();
} else if (widget.shouldUnfocusOnClearOrSubmit) {
- FocusScope.of(context).unfocus();
+ _focusNode.unfocus();
}
return;
}
@@ -604,7 +601,7 @@ class _TextInputComponentState extends State<TextInputComponent> {
});
if (widget.shouldUnfocusOnClearOrSubmit) {
- FocusScope.of(context).unfocus();
+ _focusNode.unfocus();
}
try {