π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Smooth subscription plan selection animations
r4khul5d605941a4d7
diff --git a/mobile/apps/photos/lib/ui/payment/subscription_plan_widget.dart b/mobile/apps/photos/lib/ui/payment/subscription_plan_widget.dartindex 1ad35dd87c..ab3be614ac 100644--- a/mobile/apps/photos/lib/ui/payment/subscription_plan_widget.dart+++ b/mobile/apps/photos/lib/ui/payment/subscription_plan_widget.dart@@ -96,24 +96,35 @@ class _LockerAllowanceState extends State<_LockerAllowance> {final label = context.strings.subscriptionLockerItems(count: widget.count, appName: "\uFFFC").split("\uFFFC");- return Text.rich(- TextSpan(- children: [- TextSpan(text: label[0]),- TextSpan(- text: "Locker",- recognizer: widget.isActive ? _lockerTap : null,- style: TextStyle(- decoration: widget.isActive- ? TextDecoration.underline- : TextDecoration.none,- decorationColor: widget.color,+ return AnimatedDefaultTextStyle(+ duration: MediaQuery.disableAnimationsOf(context)+ ? Duration.zero+ : Motion.slow,+ curve: Curves.easeOutCubic,+ style: DefaultTextStyle.of(context).style.merge(+ TextStyles.mini.copyWith(+ color: widget.color,+ decorationColor: widget.color,+ height: 18 / 12,+ ),+ ),+ child: Text.rich(+ TextSpan(+ children: [+ TextSpan(text: label[0]),+ TextSpan(+ text: "Locker",+ recognizer: widget.isActive ? _lockerTap : null,+ style: TextStyle(+ decoration: widget.isActive+ ? TextDecoration.underline+ : TextDecoration.none,+ ),),- ),- TextSpan(text: label[1]),- ],+ TextSpan(text: label[1]),+ ],+ ),),- style: TextStyles.mini.copyWith(color: widget.color, height: 18 / 12),);}}diff --git a/mobile/packages/ui/lib/components/subscription/plan_card.dart b/mobile/packages/ui/lib/components/subscription/plan_card.dartindex d00b225a12..826e70500a 100644--- a/mobile/packages/ui/lib/components/subscription/plan_card.dart+++ b/mobile/packages/ui/lib/components/subscription/plan_card.dart@@ -1,3 +1,6 @@+import 'dart:ui' show lerpDouble;++import 'package:ente_components/theme/motion.dart';import 'package:ente_components/theme/radii.dart';import 'package:ente_components/theme/spacing.dart';import 'package:ente_components/theme/text_styles.dart';@@ -17,6 +20,7 @@ class SubscriptionPlanCard extends StatelessWidget {});static const double height = 96;+ static const double _selectedAllowanceSize = 46.4522;static const Color _selectionDepth = Color(0xFF009B18);static const Color _selectionStroke = Color(0xFF46E35E);static const Color _badgeColor = Color(0xFFFFD525);@@ -33,36 +37,48 @@ class SubscriptionPlanCard extends StatelessWidget {@overrideWidget build(BuildContext context) {+ final selection = isSelected ? 1.0 : 0.0;+ return TweenAnimationBuilder<double>(+ tween: Tween(begin: selection, end: selection),+ duration: MediaQuery.disableAnimationsOf(context)+ ? Duration.zero+ : Motion.slow,+ curve: Curves.easeOutCubic,+ child: _allowance(context),+ builder: (context, progress, child) =>+ _buildCard(context, progress, child!),+ );+ }++ Widget _buildCard(+ BuildContext context,+ double selection,+ Widget allowanceText,+ ) {final colors = context.componentColors;final hasBadge = badgeLabel != null;- final foreground = isSelected ? colors.specialWhite : colors.textBase;- final allowanceSize = isSelected- ? 46.4522- : isFree- ? 36.9512- : 36.0;- final unitSize = allowanceSize * 4 / 9;- final allowanceLineHeight = allowanceSize * 7 / 9;- final topInset = hasBadge- ? MediaQuery.textScalerOf(context).scale(22)- : isSelected- ? 6.0- : 0.0;+ final textScaler = MediaQuery.textScalerOf(context);+ final background = Color.lerp(colors.fillLight, colors.green, selection)!;+ final baseAllowanceSize = isFree ? 36.9512 : 36.0;+ final visualAllowanceSize = textScaler.scale(+ lerpDouble(baseAllowanceSize, _selectedAllowanceSize, selection)!,+ );+ final topInset = hasBadge ? textScaler.scale(22) : 6 * selection;return Stack(clipBehavior: Clip.none,children: [- if (isSelected)- for (final layer in [(16.0, 1.0, 3.0), (17.0, 10.0, 2.0)])- Positioned.fill(- top: topInset - 22 + layer.$1,- left: -6,- right: -6,- bottom: layer.$2,+ for (final layer in [(16.0, 1.0, 3.0), (17.0, 10.0, 2.0)])+ Positioned.fill(+ top: topInset + (layer.$1 - 22) * selection,+ left: -6 * selection,+ right: -6 * selection,+ bottom: layer.$2 * selection,+ child: IgnorePointer(child: DecoratedBox(decoration: BoxDecoration(- color: _selectionDepth,+ color: _selectionDepth.withValues(alpha: selection),border: Border.all(- color: _outline,+ color: _outline.withValues(alpha: selection),width: layer.$3,strokeAlign: BorderSide.strokeAlignCenter,),@@ -70,98 +86,142 @@ class SubscriptionPlanCard extends StatelessWidget {),),),+ ),Padding(- padding: EdgeInsets.only(top: topInset, bottom: isSelected ? 16 : 0),+ padding: EdgeInsets.only(top: topInset, bottom: 16 * selection),child: DecoratedBox(decoration: BoxDecoration(- color: isSelected ? colors.green : colors.fillLight,+ color: background,borderRadius: BorderRadius.circular(Radii.button),border: Border.all(- color: isSelected ? _selectionStroke : colors.strokeDark,- width: isSelected ? 4.7878 : 3,+ color: Color.lerp(+ colors.strokeDark,+ _selectionStroke,+ selection,+ )!,+ width: lerpDouble(3, 4.7878, selection)!,strokeAlign: BorderSide.strokeAlignOutside,),),- child: ConstrainedBox(- constraints: const BoxConstraints(minHeight: height),- child: Padding(- padding: const EdgeInsets.symmetric(- horizontal: Spacing.xl,- vertical: Spacing.md,- ),- child: LayoutBuilder(- builder: (context, constraints) {- final allowance = Column(- crossAxisAlignment: CrossAxisAlignment.start,- mainAxisSize: MainAxisSize.min,- children: [- Text.rich(- TextSpan(- style: TextStyles.display1.copyWith(- color: foreground,- fontWeight: FontWeight.w700,- ),- children: [- TextSpan(- text: "$value ",- style: TextStyle(- fontSize: allowanceSize,- height: allowanceLineHeight / allowanceSize,- letterSpacing: -allowanceSize * 0.05,- ),- ),- TextSpan(- text: unit,- style: TextStyle(- fontSize: unitSize,- height: allowanceLineHeight / unitSize,- letterSpacing: -unitSize * 0.05,- fontWeight: FontWeight.w700,- ),- ),- ],- ),- strutStyle: StrutStyle(- fontFamily: TextStyles.outfitFontFamily,- package: TextStyles.fontPackage,- fontWeight: FontWeight.w700,- fontSize: allowanceSize,- height:- allowanceLineHeight.ceilToDouble() /- allowanceSize,- forceStrutHeight: true,- ),- ),- const SizedBox(height: Spacing.xs),- includedAllowance,- ],- );- if (constraints.maxWidth < 260 ||- MediaQuery.textScalerOf(context).scale(12) > 16) {- return Column(- mainAxisSize: MainAxisSize.min,+ child: _SelectionShimmer(+ isSelected: isSelected,+ child: ConstrainedBox(+ constraints: const BoxConstraints(minHeight: height),+ child: Padding(+ padding: const EdgeInsets.symmetric(+ horizontal: Spacing.xl,+ vertical: Spacing.md,+ ),+ child: LayoutBuilder(+ builder: (context, constraints) {+ final allowance = Column(crossAxisAlignment: CrossAxisAlignment.start,+ mainAxisSize: MainAxisSize.min,children: [- allowance,- const SizedBox(height: Spacing.sm),- Align(alignment: Alignment.centerRight, child: price),+ if (MediaQuery.disableAnimationsOf(context))+ allowanceText+ else+ ClipRect(+ clipper: const _AllowanceClipper(),+ clipBehavior: selection > 0 && selection < 1+ ? Clip.hardEdge+ : Clip.none,+ child: AnimatedSize(+ duration: Motion.slow,+ curve: Curves.easeOutCubic,+ alignment: AlignmentDirectional.centerStart,+ clipBehavior: Clip.none,+ child: SizedBox(+ width: double.infinity,+ child: AnimatedSwitcher(+ duration: Motion.slow,+ switchInCurve: Curves.easeOutCubic,+ switchOutCurve: Curves.easeInCubic,+ transitionBuilder: (child, animation) {+ final size =+ child.key == const ValueKey(true)+ ? _selectedAllowanceSize+ : baseAllowanceSize;+ return FadeTransition(+ opacity: animation,+ child: Transform.scale(+ filterQuality: animation.isAnimating+ ? FilterQuality.medium+ : null,+ scale:+ visualAllowanceSize /+ textScaler.scale(size),+ alignment:+ AlignmentDirectional.centerStart,+ child: RepaintBoundary(child: child),+ ),+ );+ },+ layoutBuilder:+ (currentChild, previousChildren) {+ return Stack(+ alignment: AlignmentDirectional+ .centerStart,+ clipBehavior: Clip.none,+ children: [+ for (final child+ in previousChildren)+ Positioned.fill(+ child: OverflowBox(+ minWidth: 0,+ minHeight: 0,+ maxHeight: double.infinity,+ alignment:+ AlignmentDirectional+ .centerStart,+ child: ExcludeSemantics(+ child: child,+ ),+ ),+ ),+ ?currentChild,+ ],+ );+ },+ child: allowanceText,+ ),+ ),+ ),+ ),+ const SizedBox(height: Spacing.xs),+ includedAllowance,],);- }- return Row(- mainAxisAlignment: MainAxisAlignment.spaceBetween,- children: [- Expanded(child: allowance),- const SizedBox(width: Spacing.xs),- ConstrainedBox(- constraints: BoxConstraints(- maxWidth: constraints.maxWidth / 2,+ if (constraints.maxWidth < 260 ||+ textScaler.scale(12) > 16) {+ return Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ allowance,+ const SizedBox(height: Spacing.sm),+ Align(+ alignment: Alignment.centerRight,+ child: price,+ ),+ ],+ );+ }+ return Row(+ mainAxisAlignment: MainAxisAlignment.spaceBetween,+ children: [+ Expanded(child: allowance),+ const SizedBox(width: Spacing.xs),+ ConstrainedBox(+ constraints: BoxConstraints(+ maxWidth: constraints.maxWidth / 2,+ ),+ child: price,),- child: price,- ),- ],- );- },+ ],+ );+ },+ ),),),),@@ -169,7 +229,7 @@ class SubscriptionPlanCard extends StatelessWidget {),if (hasBadge)Positioned(- right: isSelected ? -9 : -4,+ right: lerpDouble(-4, -9, selection),top: 0,child: Container(constraints: const BoxConstraints(@@ -216,6 +276,53 @@ class SubscriptionPlanCard extends StatelessWidget {);}+ Widget _allowance(BuildContext context) {+ final colors = context.componentColors;+ final size = isSelected+ ? _selectedAllowanceSize+ : isFree+ ? 36.9512+ : 36.0;+ final unitSize = size * 4 / 9;+ final lineHeight = size * 7 / 9;+ return Text.rich(+ TextSpan(+ style: TextStyles.display1.copyWith(+ color: isSelected ? colors.specialWhite : colors.textBase,+ fontWeight: FontWeight.w700,+ ),+ children: [+ TextSpan(+ text: "$value ",+ style: TextStyle(+ fontSize: size,+ height: lineHeight / size,+ letterSpacing: -size * 0.05,+ ),+ ),+ TextSpan(+ text: unit,+ style: TextStyle(+ fontSize: unitSize,+ height: lineHeight / unitSize,+ letterSpacing: -unitSize * 0.05,+ fontWeight: FontWeight.w700,+ ),+ ),+ ],+ ),+ key: ValueKey(isSelected),+ strutStyle: StrutStyle(+ fontFamily: TextStyles.outfitFontFamily,+ package: TextStyles.fontPackage,+ fontWeight: FontWeight.w700,+ fontSize: size,+ height: lineHeight.ceilToDouble() / size,+ forceStrutHeight: true,+ ),+ );+ }+Widget _highlight(double width) => Container(width: width,height: 5,@@ -226,6 +333,98 @@ class SubscriptionPlanCard extends StatelessWidget {);}+class _AllowanceClipper extends CustomClipper<Rect> {+ const _AllowanceClipper();++ @override+ Rect getClip(Size size) => (Offset.zero & size).inflate(Spacing.xs);++ @override+ bool shouldReclip(_AllowanceClipper oldClipper) => false;+}++class _SelectionShimmer extends StatefulWidget {+ const _SelectionShimmer({required this.isSelected, required this.child});++ final bool isSelected;+ final Widget child;++ @override+ State<_SelectionShimmer> createState() => _SelectionShimmerState();+}++class _SelectionShimmerState extends State<_SelectionShimmer>+ with SingleTickerProviderStateMixin {+ late final AnimationController _controller;++ @override+ void initState() {+ super.initState();+ _controller = AnimationController(+ vsync: this,+ duration: Motion.slow * 2,+ value: 1,+ );+ }++ @override+ void didChangeDependencies() {+ super.didChangeDependencies();+ if (MediaQuery.disableAnimationsOf(context)) _controller.value = 1;+ }++ @override+ void didUpdateWidget(covariant _SelectionShimmer oldWidget) {+ super.didUpdateWidget(oldWidget);+ if (oldWidget.isSelected == widget.isSelected) return;+ if (widget.isSelected && !MediaQuery.disableAnimationsOf(context)) {+ _controller.forward(from: 0);+ } else {+ _controller.value = 1;+ }+ }++ @override+ void dispose() {+ _controller.dispose();+ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ final white = context.componentColors.specialWhite;+ return AnimatedBuilder(+ animation: _controller,+ child: widget.child,+ builder: (context, child) {+ final progress = const Interval(0.12, 1).transform(_controller.value);+ final sweep = progress * 4 - 2;+ return DecoratedBox(+ position: DecorationPosition.foreground,+ decoration: BoxDecoration(+ borderRadius: BorderRadius.circular(Radii.button),+ gradient: progress > 0 && progress < 1+ ? LinearGradient(+ begin: Alignment(sweep - 1, -1),+ end: Alignment(sweep + 1, 1),+ colors: [+ white.withValues(alpha: 0),+ white.withValues(+ alpha: 0.40 * 4 * progress * (1 - progress),+ ),+ white.withValues(alpha: 0),+ ],+ stops: const [0.35, 0.5, 0.65],+ )+ : null,+ ),+ child: child,+ );+ },+ );+ }+}+class SubscriptionPlanList extends StatelessWidget {const SubscriptionPlanList({super.key, required this.children});diff --git a/mobile/packages/ui/lib/components/subscription/plan_price.dart b/mobile/packages/ui/lib/components/subscription/plan_price.dartindex dadf5ea87f..67c2705e84 100644--- a/mobile/packages/ui/lib/components/subscription/plan_price.dart+++ b/mobile/packages/ui/lib/components/subscription/plan_price.dart@@ -1,3 +1,6 @@+import 'dart:ui' show lerpDouble;++import 'package:ente_components/theme/motion.dart';import 'package:ente_components/theme/text_styles.dart';import 'package:ente_components/theme/theme.dart';import 'package:flutter/material.dart';@@ -20,16 +23,38 @@ class SubscriptionPrice extends StatelessWidget {@overrideWidget build(BuildContext context) {+ final selection = isSelected ? 1.0 : 0.0;+ return TweenAnimationBuilder<double>(+ tween: Tween(begin: selection, end: selection),+ duration: MediaQuery.disableAnimationsOf(context)+ ? Duration.zero+ : Motion.slow,+ curve: Curves.easeOutCubic,+ builder: (context, progress, _) => _buildPrice(context, progress),+ );+ }++ Widget _buildPrice(BuildContext context, double selection) {final colors = context.componentColors;- final lineHeight = isSelected || periodLabel == null ? 20.0 : 28.0;+ final lineHeight = periodLabel == null+ ? 20.0+ : lerpDouble(28, 20, selection)!;+ final foreground = Color.lerp(+ colors.textBase,+ colors.specialWhite,+ selection,+ );+ final secondaryForeground = Color.lerp(+ colors.textLight,+ colors.specialWhite.withValues(alpha: 0.6),+ selection,+ );final amountStyle = TextStyles.large.copyWith(- color: isSelected ? colors.specialWhite : colors.textBase,+ color: foreground,height: lineHeight / 16,);final periodStyle = TextStyles.mini.copyWith(- color: isSelected- ? colors.specialWhite.withValues(alpha: 0.6)- : colors.textLight,+ color: secondaryForeground,height: lineHeight / 12,fontWeight: FontWeight.w600,);@@ -50,9 +75,7 @@ class SubscriptionPrice extends StatelessWidget {}final perMonthStyle = TextStyles.tiny.copyWith(- color: isSelected- ? colors.specialWhite.withValues(alpha: 0.6)- : colors.textLight,+ color: secondaryForeground,height: 16.8067 / 10,);return Column(@@ -78,7 +101,7 @@ class SubscriptionPrice extends StatelessWidget {Align(alignment: Alignment.bottomRight,widthFactor: 1,- heightFactor: isSelected ? 1 : 15 / 17,+ heightFactor: lerpDouble(15 / 17, 1, selection),child: Text.rich(TextSpan(children: [@@ -87,9 +110,11 @@ class SubscriptionPrice extends StatelessWidget {text: originalMonthlyPrice!,style: perMonthStyle.copyWith(decoration: TextDecoration.lineThrough,- decorationColor: isSelected- ? colors.specialWhite- : colors.textLight,+ decorationColor: Color.lerp(+ colors.textLight,+ colors.specialWhite,+ selection,+ ),),),const TextSpan(text: " β "),