π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile] Fix popup menu opening animation (#13741)
aman-pilot5249a8c43241
diff --git a/mobile/apps/auth/changes/popup-menu-animation.md b/mobile/apps/auth/changes/popup-menu-animation.mdnew file mode 100644index 0000000000..93e4211c32--- /dev/null+++ b/mobile/apps/auth/changes/popup-menu-animation.md@@ -0,0 +1 @@+- Fixed jerky popup menu opening animations.diff --git a/mobile/apps/auth/lib/ente_theme_data.dart b/mobile/apps/auth/lib/ente_theme_data.dartindex e130332975..e92c02376f 100644--- a/mobile/apps/auth/lib/ente_theme_data.dart+++ b/mobile/apps/auth/lib/ente_theme_data.dart@@ -1,10 +1,12 @@import 'package:ente_auth/theme/colors.dart';import 'package:ente_auth/theme/ente_theme.dart';+import 'package:ente_components/theme/colors.dart' show ColorTokens;import 'package:flutter/material.dart';final lightThemeData = ThemeData(fontFamily: 'Inter',brightness: Brightness.light,+ popupMenuTheme: PopupMenuThemeData(color: ColorTokens.light.fillLight),dividerTheme: const DividerThemeData(color: Colors.black12),hintColor: const Color.fromRGBO(158, 158, 158, 1),primaryColor: const Color.fromRGBO(255, 110, 64, 1),@@ -119,6 +121,7 @@ final lightThemeData = ThemeData(final darkThemeData = ThemeData(fontFamily: 'Inter',brightness: Brightness.dark,+ popupMenuTheme: PopupMenuThemeData(color: ColorTokens.dark.fillLight),dividerTheme: const DividerThemeData(color: Colors.white12),primaryColorLight: const Color.fromRGBO(255, 255, 255, 0.702),iconTheme: const IconThemeData(color: Colors.white),diff --git a/mobile/apps/locker/changes/popup-menu-animation.md b/mobile/apps/locker/changes/popup-menu-animation.mdnew file mode 100644index 0000000000..93e4211c32--- /dev/null+++ b/mobile/apps/locker/changes/popup-menu-animation.md@@ -0,0 +1 @@+- Fixed jerky popup menu opening animations.diff --git a/mobile/apps/photos/changes/popup-menu-animation.md b/mobile/apps/photos/changes/popup-menu-animation.mdnew file mode 100644index 0000000000..93e4211c32--- /dev/null+++ b/mobile/apps/photos/changes/popup-menu-animation.md@@ -0,0 +1 @@+- Fixed jerky popup menu opening animations.diff --git a/mobile/apps/photos/lib/ente_theme_data.dart b/mobile/apps/photos/lib/ente_theme_data.dartindex 1ea88e41cf..1c8843c484 100644--- a/mobile/apps/photos/lib/ente_theme_data.dart+++ b/mobile/apps/photos/lib/ente_theme_data.dart@@ -1,4 +1,5 @@-import 'package:ente_components/theme/colors.dart' show ComponentApp;+import 'package:ente_components/theme/colors.dart'+ show ColorTokens, ComponentApp;import 'package:ente_components/theme/text_styles.dart' as component;import 'package:ente_components/theme/theme.dart'show ComponentColorTokens, ComponentTheme;@@ -9,6 +10,7 @@ import 'package:photos/theme/ente_theme.dart';final lightThemeData = ThemeData(fontFamily: 'Inter',brightness: Brightness.light,+ popupMenuTheme: PopupMenuThemeData(color: ColorTokens.light.fillLight),hintColor: const Color.fromRGBO(158, 158, 158, 1),primaryColor: const Color.fromRGBO(255, 110, 64, 1),primaryColorLight: const Color.fromRGBO(0, 0, 0, 0.541),@@ -96,6 +98,7 @@ final lightThemeData = ThemeData(final darkThemeData = ThemeData(fontFamily: 'Inter',brightness: Brightness.dark,+ popupMenuTheme: PopupMenuThemeData(color: ColorTokens.dark.fillLight),primaryColorLight: const Color.fromRGBO(255, 255, 255, 0.702),iconTheme: const IconThemeData(color: Colors.white),primaryIconTheme: const IconThemeData(diff --git a/mobile/packages/ente_components/lib/components/popup_menu_component.dart b/mobile/packages/ente_components/lib/components/popup_menu_component.dartindex 7f32824215..431fb6fcd0 100644--- a/mobile/packages/ente_components/lib/components/popup_menu_component.dart+++ b/mobile/packages/ente_components/lib/components/popup_menu_component.dart@@ -128,7 +128,6 @@ Future<T?> showEntePopupMenu<T>({return showMenu<T>(context: context,- color: Colors.transparent,elevation: elevation,surfaceTintColor: Colors.transparent,menuPadding: EdgeInsets.zero,@@ -151,35 +150,28 @@ Future<T?> showEntePopupMenu<T>({final borderSide = BorderSide(color: colors.strokeFaint);final isFirst = index == 0;final isLast = index == options.length - 1;- return Ink(- color: colors.fillLight,- child: Container(- key: ValueKey('ente-popup-menu-item-$index'),- height: itemHeight,- padding: EdgeInsets.symmetric(- horizontal: itemHorizontalPadding,- ),- decoration: BoxDecoration(- border: option.showDivider && !isLast- ? Border(bottom: borderSide)- : null,+ return Container(+ key: ValueKey('ente-popup-menu-item-$index'),+ height: itemHeight,+ padding: EdgeInsets.symmetric(horizontal: itemHorizontalPadding),+ decoration: BoxDecoration(+ border: option.showDivider && !isLast+ ? Border(bottom: borderSide)+ : null,+ ),+ foregroundDecoration: BoxDecoration(+ border: Border(+ top: isFirst ? borderSide : BorderSide.none,+ bottom: isLast ? borderSide : BorderSide.none,+ left: borderSide,+ right: borderSide,),- foregroundDecoration: BoxDecoration(- border: Border(- top: isFirst ? borderSide : BorderSide.none,- bottom: isLast ? borderSide : BorderSide.none,- left: borderSide,- right: borderSide,- ),- borderRadius: BorderRadius.vertical(- top: isFirst ? Radius.circular(borderRadius) : Radius.zero,- bottom: isLast- ? Radius.circular(borderRadius)- : Radius.zero,- ),+ borderRadius: BorderRadius.vertical(+ top: isFirst ? Radius.circular(borderRadius) : Radius.zero,+ bottom: isLast ? Radius.circular(borderRadius) : Radius.zero,),- child: _EntePopupMenuRow(option: option),),+ child: _EntePopupMenuRow(option: option),);},),diff --git a/mobile/packages/ente_components/lib/theme/theme.dart b/mobile/packages/ente_components/lib/theme/theme.dartindex f152e3de96..b7e7ba8c9a 100644--- a/mobile/packages/ente_components/lib/theme/theme.dart+++ b/mobile/packages/ente_components/lib/theme/theme.dart@@ -67,6 +67,7 @@ class ComponentTheme {labelMedium: TextStyles.mini,labelSmall: TextStyles.tiny,),+ popupMenuTheme: PopupMenuThemeData(color: colors.fillLight),dialogTheme: DialogThemeData(backgroundColor: colors.fillLight,surfaceTintColor: Colors.transparent,diff --git a/mobile/packages/ente_components/test/components/popup_menu_component_test.dart b/mobile/packages/ente_components/test/components/popup_menu_component_test.dartindex 8b5f3db865..83486e4018 100644--- a/mobile/packages/ente_components/test/components/popup_menu_component_test.dart+++ b/mobile/packages/ente_components/test/components/popup_menu_component_test.dart@@ -1,7 +1,9 @@import 'dart:async';+import 'dart:ui' as ui;import 'package:ente_components/ente_components.dart';import 'package:flutter/material.dart';+import 'package:flutter/rendering.dart';import 'package:flutter_test/flutter_test.dart';import 'package:hugeicons/hugeicons.dart';@@ -25,53 +27,108 @@ Future<void> pumpPopupMenu(}void main() {+ for (final mode in [ThemeMode.light, ThemeMode.dark]) {+ testWidgets('popup surface is continuous while opening in $mode', (+ tester,+ ) async {+ final boundaryKey = GlobalKey();+ await tester.pumpWidget(+ RepaintBoundary(+ key: boundaryKey,+ child: MaterialApp(+ theme: ComponentTheme.lightTheme(),+ darkTheme: ComponentTheme.darkTheme(),+ themeMode: mode,+ home: Scaffold(+ backgroundColor: Colors.blue,+ body: Align(+ alignment: Alignment.topLeft,+ child: EntePopupMenuButton<int>(+ optionsBuilder: () => const [+ EntePopupMenuOption(value: 0, label: 'First'),+ EntePopupMenuOption(value: 1, label: 'Second'),+ EntePopupMenuOption(value: 2, label: 'Third'),+ EntePopupMenuOption(value: 3, label: 'Fourth'),+ ],+ onSelected: (_) {},+ ),+ ),+ ),+ ),+ ),+ );+ await tester.tap(find.byType(EntePopupMenuButton<int>));+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 160));++ // The surface has expanded into the third row before its label fades in.+ final thirdRow = tester.getTopLeft(+ find.byKey(const ValueKey('ente-popup-menu-item-2')),+ );+ expect(+ await pixelColor(tester, boundaryKey, thirdRow + const Offset(8, 8)),+ mode == ThemeMode.dark+ ? ColorTokens.dark.fillLight+ : ColorTokens.light.fillLight,+ );+ await tester.pumpAndSettle();+ });+ }+testWidgets('open popup icons follow theme changes without changing sizes', (tester,) async {var optionsBuildCount = 0;+ final boundaryKey = GlobalKey();Widget app(ThemeMode themeMode) {- return MaterialApp(- theme: ComponentTheme.lightTheme().copyWith(- iconTheme: const IconThemeData(size: 30),- ),- darkTheme: ComponentTheme.darkTheme().copyWith(- iconTheme: const IconThemeData(size: 30),- ),- themeMode: themeMode,- home: Scaffold(- body: Align(- alignment: Alignment.topLeft,- child: EntePopupMenuButton<String>(- optionsBuilder: () {- optionsBuildCount++;- return const [- EntePopupMenuOption(- value: 'sort',- label: 'Sort',- secondaryLabel: 'Count',- leadingWidget: Icon(Icons.sort),- secondaryTrailingWidget: Icon(Icons.info_outline, size: 12),- isActive: true,- activeTrailingWidget: HugeIcon(- icon: HugeIcons.strokeRoundedArrowUp02,- size: 12,- strokeWidth: 3,+ return RepaintBoundary(+ key: boundaryKey,+ child: MaterialApp(+ theme: ComponentTheme.lightTheme().copyWith(+ iconTheme: const IconThemeData(size: 30),+ ),+ darkTheme: ComponentTheme.darkTheme().copyWith(+ iconTheme: const IconThemeData(size: 30),+ ),+ themeMode: themeMode,+ home: Scaffold(+ body: Align(+ alignment: Alignment.topLeft,+ child: EntePopupMenuButton<String>(+ optionsBuilder: () {+ optionsBuildCount++;+ return const [+ EntePopupMenuOption(+ value: 'sort',+ label: 'Sort',+ secondaryLabel: 'Count',+ leadingWidget: Icon(Icons.sort),+ secondaryTrailingWidget: Icon(+ Icons.info_outline,+ size: 12,+ ),+ isActive: true,+ activeTrailingWidget: HugeIcon(+ icon: HugeIcons.strokeRoundedArrowUp02,+ size: 12,+ strokeWidth: 3,+ ),),- ),- EntePopupMenuOption(- value: 'delete',- label: 'Delete',- leadingWidget: Icon(- Icons.delete,- color: Colors.red,- size: 20,+ EntePopupMenuOption(+ value: 'delete',+ label: 'Delete',+ leadingWidget: Icon(+ Icons.delete,+ color: Colors.red,+ size: 20,+ ),+ trailingWidget: Icon(Icons.chevron_right),),- trailingWidget: Icon(Icons.chevron_right),- ),- ];- },- onSelected: (_) {},+ ];+ },+ onSelected: (_) {},+ ),),),),@@ -100,6 +157,13 @@ void main() {final colors = mode == ThemeMode.dark? ColorTokens.dark: ColorTokens.light;+ final firstRow = tester.getTopLeft(+ find.byKey(const ValueKey('ente-popup-menu-item-0')),+ );+ expect(+ await pixelColor(tester, boundaryKey, firstRow + const Offset(100, 8)),+ colors.fillLight,+ );for (final icon in [Icons.sort,@@ -191,3 +255,25 @@ void main() {expect(find.text('Creating stream'), findsOneWidget);});}++Future<Color> pixelColor(+ WidgetTester tester,+ GlobalKey boundaryKey,+ Offset point,+) async {+ final boundary =+ boundaryKey.currentContext!.findRenderObject()! as RenderRepaintBoundary;+ return (await tester.runAsync(() async {+ final image = await boundary.toImage();+ final bytes = (await image.toByteData(format: ui.ImageByteFormat.rawRgba))!;+ final offset = (point.dy.toInt() * image.width + point.dx.toInt()) * 4;+ final color = Color.fromARGB(+ bytes.getUint8(offset + 3),+ bytes.getUint8(offset),+ bytes.getUint8(offset + 1),+ bytes.getUint8(offset + 2),+ );+ image.dispose();+ return color;+ }))!;+}