Skip to content

Commit d55a7d8

Browse files
authored
Revert "fix a bug when android uses CupertinoPageTransitionsBuilder..." (flutter#130144)
Reverts flutter#114303 The breaking API change in flutter#114303 broke internal tests/apps (Google internal link b/290154304) as well as external dependents: flutter#130062. Fixes flutter#130062
1 parent d5b8db3 commit d55a7d8

File tree

3 files changed

+9
-154
lines changed

3 files changed

+9
-154
lines changed

packages/flutter/lib/src/material/page.dart

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ class MaterialPageRoute<T> extends PageRoute<T> with MaterialRouteTransitionMixi
8080
/// * [CupertinoPageTransitionsBuilder], which is the default page transition
8181
/// for iOS and macOS.
8282
mixin MaterialRouteTransitionMixin<T> on PageRoute<T> {
83-
TargetPlatform? _effectiveTargetPlatform;
84-
8583
/// Builds the primary contents of the route.
8684
@protected
8785
Widget buildContent(BuildContext context);
@@ -118,20 +116,8 @@ mixin MaterialRouteTransitionMixin<T> on PageRoute<T> {
118116

119117
@override
120118
Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
121-
return ValueListenableBuilder<bool>(
122-
valueListenable: navigator!.userGestureInProgressNotifier,
123-
builder: (BuildContext context, bool useGestureInProgress, Widget? _) {
124-
final ThemeData themeData = Theme.of(context);
125-
126-
if (useGestureInProgress) {
127-
// The platform should be kept unchanged during an user gesture.
128-
_effectiveTargetPlatform ??= themeData.platform;
129-
} else {
130-
_effectiveTargetPlatform = themeData.platform;
131-
}
132-
return themeData.pageTransitionsTheme.buildTransitions<T>(this, context, animation, secondaryAnimation, child, _effectiveTargetPlatform!);
133-
},
134-
);
119+
final PageTransitionsTheme theme = Theme.of(context).pageTransitionsTheme;
120+
return theme.buildTransitions<T>(this, context, animation, secondaryAnimation, child);
135121
}
136122
}
137123

packages/flutter/lib/src/material/page_transitions_theme.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ class PageTransitionsTheme with Diagnosticable {
741741
Map<TargetPlatform, PageTransitionsBuilder> get builders => _builders;
742742
final Map<TargetPlatform, PageTransitionsBuilder> _builders;
743743

744-
/// Delegates to the builder for the current [platform].
744+
/// Delegates to the builder for the current [ThemeData.platform].
745745
/// If a builder for the current platform is not found, then the
746746
/// [ZoomPageTransitionsBuilder] is used.
747747
///
@@ -752,8 +752,13 @@ class PageTransitionsTheme with Diagnosticable {
752752
Animation<double> animation,
753753
Animation<double> secondaryAnimation,
754754
Widget child,
755-
TargetPlatform platform,
756755
) {
756+
TargetPlatform platform = Theme.of(context).platform;
757+
758+
if (CupertinoRouteTransitionMixin.isPopGestureInProgress(route)) {
759+
platform = TargetPlatform.iOS;
760+
}
761+
757762
final PageTransitionsBuilder matchingBuilder =
758763
builders[platform] ?? const ZoomPageTransitionsBuilder();
759764
return matchingBuilder.buildTransitions<T>(route, context, animation, secondaryAnimation, child);

packages/flutter/test/material/page_transitions_theme_test.dart

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -350,140 +350,4 @@ void main() {
350350
await tester.pumpAndSettle();
351351
expect(builtCount, 1);
352352
}, variant: TargetPlatformVariant.only(TargetPlatform.android));
353-
354-
testWidgets('android can use CupertinoPageTransitionsBuilder', (WidgetTester tester) async {
355-
int builtCount = 0;
356-
357-
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
358-
'/': (BuildContext context) => Material(
359-
child: TextButton(
360-
child: const Text('push'),
361-
onPressed: () { Navigator.of(context).pushNamed('/b'); },
362-
),
363-
),
364-
'/b': (BuildContext context) => StatefulBuilder(
365-
builder: (BuildContext context, StateSetter setState) {
366-
builtCount++;
367-
return TextButton(
368-
child: const Text('pop'),
369-
onPressed: () { Navigator.pop(context); },
370-
);
371-
},
372-
),
373-
};
374-
375-
await tester.pumpWidget(
376-
MaterialApp(
377-
theme: ThemeData(
378-
pageTransitionsTheme: const PageTransitionsTheme(
379-
builders: <TargetPlatform, PageTransitionsBuilder>{
380-
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
381-
// iOS uses different PageTransitionsBuilder
382-
TargetPlatform.iOS: FadeUpwardsPageTransitionsBuilder(),
383-
},
384-
),
385-
),
386-
routes: routes,
387-
),
388-
);
389-
390-
// No matter push or pop was called, the child widget should built only once.
391-
await tester.tap(find.text('push'));
392-
await tester.pumpAndSettle();
393-
expect(builtCount, 1);
394-
395-
final Size size = tester.getSize(find.byType(MaterialApp));
396-
await tester.flingFrom(Offset(0, size.height / 2), Offset(size.width * 2 / 3, 0), 500);
397-
398-
await tester.pumpAndSettle();
399-
expect(find.text('push'), findsOneWidget);
400-
expect(builtCount, 1);
401-
}, variant: TargetPlatformVariant.only(TargetPlatform.android));
402-
403-
testWidgets('back gesture while TargetPlatform changes', (WidgetTester tester) async {
404-
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
405-
'/': (BuildContext context) => Material(
406-
child: TextButton(
407-
child: const Text('PUSH'),
408-
onPressed: () { Navigator.of(context).pushNamed('/b'); },
409-
),
410-
),
411-
'/b': (BuildContext context) => const Text('HELLO'),
412-
};
413-
const PageTransitionsTheme pageTransitionsTheme = PageTransitionsTheme(
414-
builders: <TargetPlatform, PageTransitionsBuilder>{
415-
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
416-
// iOS uses different PageTransitionsBuilder
417-
TargetPlatform.iOS: FadeUpwardsPageTransitionsBuilder(),
418-
},
419-
);
420-
await tester.pumpWidget(
421-
MaterialApp(
422-
theme: ThemeData(
423-
platform: TargetPlatform.android,
424-
pageTransitionsTheme: pageTransitionsTheme,
425-
),
426-
routes: routes,
427-
),
428-
);
429-
await tester.tap(find.text('PUSH'));
430-
expect(await tester.pumpAndSettle(const Duration(minutes: 1)), 2);
431-
expect(find.text('PUSH'), findsNothing);
432-
expect(find.text('HELLO'), findsOneWidget);
433-
434-
final Offset helloPosition1 = tester.getCenter(find.text('HELLO'));
435-
final TestGesture gesture = await tester.startGesture(const Offset(2.5, 300.0));
436-
await tester.pump(const Duration(milliseconds: 20));
437-
await gesture.moveBy(const Offset(100.0, 0.0));
438-
expect(find.text('PUSH'), findsNothing);
439-
expect(find.text('HELLO'), findsOneWidget);
440-
await tester.pump(const Duration(milliseconds: 20));
441-
expect(find.text('PUSH'), findsOneWidget);
442-
expect(find.text('HELLO'), findsOneWidget);
443-
final Offset helloPosition2 = tester.getCenter(find.text('HELLO'));
444-
expect(helloPosition1.dx, lessThan(helloPosition2.dx));
445-
expect(helloPosition1.dy, helloPosition2.dy);
446-
expect(Theme.of(tester.element(find.text('HELLO'))).platform, TargetPlatform.android);
447-
448-
await tester.pumpWidget(
449-
MaterialApp(
450-
theme: ThemeData(
451-
platform: TargetPlatform.iOS,
452-
pageTransitionsTheme: pageTransitionsTheme,
453-
),
454-
routes: routes,
455-
),
456-
);
457-
// Now, let the theme animation run through.
458-
// This takes three frames (including the first one above):
459-
// 1. Start the Theme animation. It's at t=0 so everything else is identical.
460-
// 2. Start any animations that are informed by the Theme, for example, the
461-
// DefaultTextStyle, on the first frame that the theme is not at t=0. In
462-
// this case, it's at t=1.0 of the theme animation, so this is also the
463-
// frame in which the theme animation ends.
464-
// 3. End all the other animations.
465-
expect(await tester.pumpAndSettle(const Duration(minutes: 1)), 2);
466-
expect(Theme.of(tester.element(find.text('HELLO'))).platform, TargetPlatform.iOS);
467-
final Offset helloPosition3 = tester.getCenter(find.text('HELLO'));
468-
expect(helloPosition3, helloPosition2);
469-
expect(find.text('PUSH'), findsOneWidget);
470-
expect(find.text('HELLO'), findsOneWidget);
471-
await gesture.moveBy(const Offset(100.0, 0.0));
472-
await tester.pump(const Duration(milliseconds: 20));
473-
expect(find.text('PUSH'), findsOneWidget);
474-
expect(find.text('HELLO'), findsOneWidget);
475-
final Offset helloPosition4 = tester.getCenter(find.text('HELLO'));
476-
expect(helloPosition3.dx, lessThan(helloPosition4.dx));
477-
expect(helloPosition3.dy, helloPosition4.dy);
478-
await gesture.moveBy(const Offset(500.0, 0.0));
479-
await gesture.up();
480-
expect(await tester.pumpAndSettle(const Duration(minutes: 1)), 3);
481-
expect(find.text('PUSH'), findsOneWidget);
482-
expect(find.text('HELLO'), findsNothing);
483-
484-
await tester.tap(find.text('PUSH'));
485-
expect(await tester.pumpAndSettle(const Duration(minutes: 1)), 2);
486-
expect(find.text('PUSH'), findsNothing);
487-
expect(find.text('HELLO'), findsOneWidget);
488-
});
489353
}

0 commit comments

Comments
 (0)