Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes CupertinoModalPopupRoute #147823

Merged
merged 20 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 36 additions & 22 deletions packages/flutter/lib/src/cupertino/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ class CupertinoModalPopupRoute<T> extends PopupRoute<T> {
@override
Duration get transitionDuration => _kModalPopupTransitionDuration;

Animation<double>? _animation;
CurvedAnimation? _animation;

late Tween<Offset> _offsetTween;

Expand Down Expand Up @@ -1142,6 +1142,12 @@ class CupertinoModalPopupRoute<T> extends PopupRoute<T> {
),
);
}

@override
void dispose() {
_animation?.dispose();
super.dispose();
}
}

/// Shows a modal iOS-style popup that slides up from the bottom of the screen.
Expand Down Expand Up @@ -1238,26 +1244,6 @@ Future<T?> showCupertinoModalPopup<T>({
final Animatable<double> _dialogScaleTween = Tween<double>(begin: 1.3, end: 1.0)
.chain(CurveTween(curve: Curves.linearToEaseOut));

Widget _buildCupertinoDialogTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You moved this method to other place, that made it hard to see diff. Can you move it back to make code review easier?

final CurvedAnimation fadeAnimation = CurvedAnimation(
parent: animation,
curve: Curves.easeInOut,
);
if (animation.status == AnimationStatus.reverse) {
return FadeTransition(
opacity: fadeAnimation,
child: child,
);
}
return FadeTransition(
opacity: fadeAnimation,
child: ScaleTransition(
scale: animation.drive(_dialogScaleTween),
child: child,
),
);
}

/// Displays an iOS-style dialog above the current contents of the app, with
/// iOS-style entrance and exit animations, modal barrier color, and modal
/// barrier behavior (by default, the dialog is not dismissible with a tap on
Expand Down Expand Up @@ -1382,7 +1368,6 @@ class CupertinoDialogRoute<T> extends RawDialogRoute<T> {
String? barrierLabel,
// This transition duration was eyeballed comparing with iOS
super.transitionDuration = const Duration(milliseconds: 250),
super.transitionBuilder = _buildCupertinoDialogTransitions,
super.settings,
super.anchorPoint,
}) : super(
Expand All @@ -1392,4 +1377,33 @@ class CupertinoDialogRoute<T> extends RawDialogRoute<T> {
barrierLabel: barrierLabel ?? CupertinoLocalizations.of(context).modalBarrierDismissLabel,
barrierColor: barrierColor ?? CupertinoDynamicColor.resolve(kCupertinoModalBarrierColor, context),
);

CurvedAnimation? _fadeAnimation;

@override
Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
_fadeAnimation ??= CurvedAnimation(
parent: animation,
curve: Curves.easeInOut,
);
if (animation.status == AnimationStatus.reverse) {
return FadeTransition(
opacity: _fadeAnimation!,
child: child,
);
}
return FadeTransition(
opacity: _fadeAnimation!,
child: ScaleTransition(
scale: animation.drive(_dialogScaleTween),
child: child,
),
);
}

@override
void dispose() {
_fadeAnimation?.dispose();
super.dispose();
}
}
55 changes: 55 additions & 0 deletions packages/flutter/test/cupertino/route_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2479,6 +2479,61 @@ void main() {

await tester.pump(const Duration(milliseconds: 400));
});

testWidgets('CupertinoModalPopupRoute and CupertinoDialogRoute does not leak CurveAnimation',
// TODO(polina-c): remove when fixed https://github.com/flutter/flutter/issues/145600 [leak-tracking-opt-in]
experimentalLeakTesting: LeakTesting.settings.withTracked(classes: <String>['CurvedAnimation']),
(WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Navigator(
onGenerateRoute: (RouteSettings settings) {
return PageRouteBuilder<dynamic>(
pageBuilder: (BuildContext context, Animation<double> _, Animation<double> __) {
return GestureDetector(
onTap: () async {
await showCupertinoModalPopup<void>(
context: context,
semanticsDismissible: true,
builder: (BuildContext context) => const SizedBox(),
);
},
child: const Text('tap'),
);
},
);
},
),
));

// Push the route.
await tester.tap(find.text('tap'));
await tester.pumpAndSettle();

await tester.pumpWidget(MaterialApp(
home: Navigator(
onGenerateRoute: (RouteSettings settings) {
return PageRouteBuilder<dynamic>(
pageBuilder: (BuildContext context, Animation<double> _, Animation<double> __) {
return GestureDetector(
onTap: () async {
await showCupertinoDialog<void>(
context: context,
useRootNavigator: false,
builder: (BuildContext context) => const SizedBox(),
);
},
child: const Text('tap'),
);
},
);
},
),
));

// Open the dialog.
await tester.tap(find.text('tap'));
await tester.pumpAndSettle();
});
}

class MockNavigatorObserver extends NavigatorObserver {
Expand Down