Skip to content

Commit

Permalink
Reland "Android Q transition by default (#82670)" (#88409)
Browse files Browse the repository at this point in the history
* Reland "Android Q transition by default (#82670)"

This reverts commit 4053b4b.

* Fix `overall_experience_test.dart` for flutter_tools
  • Loading branch information
AlexV525 committed Aug 18, 2021
1 parent bfd4282 commit df399f9
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 97 deletions.
15 changes: 8 additions & 7 deletions packages/flutter/lib/src/material/page.dart
Expand Up @@ -63,13 +63,14 @@ class MaterialPageRoute<T> extends PageRoute<T> with MaterialRouteTransitionMixi
/// A mixin that provides platform-adaptive transitions for a [PageRoute].
///
/// {@template flutter.material.materialRouteTransitionMixin}
/// For Android, the entrance transition for the page slides the route upwards
/// and fades it in. The exit transition is the same, but in reverse.
///
/// The transition is adaptive to the platform and on iOS, the route slides in
/// from the right and exits in reverse. The route also shifts to the left in
/// parallax when another page enters to cover it. (These directions are flipped
/// in environments with a right-to-left reading direction.)
/// For Android, the entrance transition for the page zooms in while the
/// exiting page zooms and fades out. The exit transition is similar, but in
/// reverse.
///
/// For iOS, the page slides in from the right and exits in reverse. The page
/// also shifts to the left in parallax when another page enters to cover it.
/// (These directions are flipped in environments with a right-to-left reading
/// direction.)
/// {@endtemplate}
///
/// See also:
Expand Down
86 changes: 44 additions & 42 deletions packages/flutter/lib/src/material/page_transitions_theme.dart
Expand Up @@ -9,7 +9,8 @@ import 'colors.dart';
import 'theme.dart';

// Slides the page upwards and fades it in, starting from 1/4 screen
// below the top.
// below the top. The transition is intended to match the default for
// Android O.
class _FadeUpwardsPageTransition extends StatelessWidget {
_FadeUpwardsPageTransition({
Key? key,
Expand Down Expand Up @@ -146,7 +147,7 @@ class _OpenUpwardsPageTransition extends StatelessWidget {
}

// Zooms and fades a new page in, zooming out the previous page. This transition
// is designed to match the Android 10 activity transition.
// is designed to match the Android Q activity transition.
class _ZoomPageTransition extends StatelessWidget {
/// Creates a [_ZoomPageTransition].
///
Expand Down Expand Up @@ -291,16 +292,16 @@ class _ZoomEnterTransition extends StatelessWidget {
@override
Widget build(BuildContext context) {
double opacity = 0;
// The transition's scrim opacity only increases on the forward transition. In the reverse
// transition, the opacity should always be 0.0.
// The transition's scrim opacity only increases on the forward transition.
// In the reverse transition, the opacity should always be 0.0.
//
// Therefore, we need to only apply the scrim opacity animation when the transition
// is running forwards.
// Therefore, we need to only apply the scrim opacity animation when
// the transition is running forwards.
//
// The reason that we check that the animation's status is not `completed` instead
// of checking that it is `forward` is that this allows the interrupted reversal of the
// forward transition to smoothly fade the scrim away. This prevents a disjointed
// removal of the scrim.
// The reason that we check that the animation's status is not `completed`
// instead of checking that it is `forward` is that this allows
// the interrupted reversal of the forward transition to smoothly fade
// the scrim away. This prevents a disjointed removal of the scrim.
if (!reverse && animation.status != AnimationStatus.completed) {
opacity = _scrimOpacityTween.evaluate(animation)!;
}
Expand All @@ -317,17 +318,14 @@ class _ZoomEnterTransition extends StatelessWidget {
return AnimatedBuilder(
animation: animation,
builder: (BuildContext context, Widget? child) {
return Container(
return ColoredBox(
color: Colors.black.withOpacity(opacity),
child: child,
);
},
child: FadeTransition(
opacity: fadeTransition,
child: ScaleTransition(
scale: scaleTransition,
child: child,
),
child: ScaleTransition(scale: scaleTransition, child: child),
),
);
}
Expand Down Expand Up @@ -374,10 +372,7 @@ class _ZoomExitTransition extends StatelessWidget {

return FadeTransition(
opacity: fadeTransition,
child: ScaleTransition(
scale: scaleTransition,
child: child,
),
child: ScaleTransition(scale: scaleTransition, child: child),
);
}
}
Expand All @@ -391,11 +386,12 @@ class _ZoomExitTransition extends StatelessWidget {
///
/// See also:
///
/// * [FadeUpwardsPageTransitionsBuilder], which defines a default page transition.
/// * [FadeUpwardsPageTransitionsBuilder], which defines a page transition
/// that's similar to the one provided by Android O.
/// * [OpenUpwardsPageTransitionsBuilder], which defines a page transition
/// that's similar to the one provided by Android P.
/// * [ZoomPageTransitionsBuilder], which defines a page transition similar
/// to the one provided in Android 10.
/// * [ZoomPageTransitionsBuilder], which defines the default page transition
/// that's similar to the one provided in Android Q.
/// * [CupertinoPageTransitionsBuilder], which defines a horizontal page
/// transition that matches native iOS page transitions.
abstract class PageTransitionsBuilder {
Expand All @@ -419,18 +415,19 @@ abstract class PageTransitionsBuilder {
);
}

/// Used by [PageTransitionsTheme] to define a default [MaterialPageRoute] page
/// transition animation.
/// Used by [PageTransitionsTheme] to define a vertically fading
/// [MaterialPageRoute] page transition animation that looks like
/// the default page transition used on Android O.
///
/// The default animation fades the new page in while translating it upwards,
/// The animation fades the new page in while translating it upwards,
/// starting from about 25% below the top of the screen.
///
/// See also:
///
/// * [OpenUpwardsPageTransitionsBuilder], which defines a page transition
/// that's similar to the one provided by Android P.
/// * [ZoomPageTransitionsBuilder], which defines a page transition similar
/// to the one provided in Android 10.
/// * [ZoomPageTransitionsBuilder], which defines the default page transition
/// that's similar to the one provided in Android Q.
/// * [CupertinoPageTransitionsBuilder], which defines a horizontal page
/// transition that matches native iOS page transitions.
class FadeUpwardsPageTransitionsBuilder extends PageTransitionsBuilder {
Expand All @@ -455,9 +452,10 @@ class FadeUpwardsPageTransitionsBuilder extends PageTransitionsBuilder {
///
/// See also:
///
/// * [FadeUpwardsPageTransitionsBuilder], which defines a default page transition.
/// * [ZoomPageTransitionsBuilder], which defines a page transition similar
/// to the one provided in Android 10.
/// * [FadeUpwardsPageTransitionsBuilder], which defines a page transition
/// that's similar to the one provided by Android O.
/// * [ZoomPageTransitionsBuilder], which defines the default page transition
/// that's similar to the one provided in Android Q.
/// * [CupertinoPageTransitionsBuilder], which defines a horizontal page
/// transition that matches native iOS page transitions.
class OpenUpwardsPageTransitionsBuilder extends PageTransitionsBuilder {
Expand All @@ -483,18 +481,19 @@ class OpenUpwardsPageTransitionsBuilder extends PageTransitionsBuilder {

/// Used by [PageTransitionsTheme] to define a zooming [MaterialPageRoute] page
/// transition animation that looks like the default page transition used on
/// Android 10.
/// Android Q.
///
/// See also:
///
/// * [FadeUpwardsPageTransitionsBuilder], which defines a default page transition.
/// * [FadeUpwardsPageTransitionsBuilder], which defines a page transition
/// that's similar to the one provided by Android O.
/// * [OpenUpwardsPageTransitionsBuilder], which defines a page transition
/// similar to the one provided by Android P.
/// that's similar to the one provided by Android P.
/// * [CupertinoPageTransitionsBuilder], which defines a horizontal page
/// transition that matches native iOS page transitions.
class ZoomPageTransitionsBuilder extends PageTransitionsBuilder {
/// Constructs a page transition animation that matches the transition used on
/// Android 10.
/// Android Q.
const ZoomPageTransitionsBuilder();

@override
Expand All @@ -518,11 +517,12 @@ class ZoomPageTransitionsBuilder extends PageTransitionsBuilder {
///
/// See also:
///
/// * [FadeUpwardsPageTransitionsBuilder], which defines a default page transition.
/// * [FadeUpwardsPageTransitionsBuilder], which defines a page transition
/// that's similar to the one provided by Android O.
/// * [OpenUpwardsPageTransitionsBuilder], which defines a page transition
/// that's similar to the one provided by Android P.
/// * [ZoomPageTransitionsBuilder], which defines a page transition similar
/// to the one provided in Android 10.
/// * [ZoomPageTransitionsBuilder], which defines the default page transition
/// that's similar to the one provided in Android Q.
class CupertinoPageTransitionsBuilder extends PageTransitionsBuilder {
/// Constructs a page transition animation that matches the iOS transition.
const CupertinoPageTransitionsBuilder();
Expand Down Expand Up @@ -554,9 +554,12 @@ class CupertinoPageTransitionsBuilder extends PageTransitionsBuilder {
///
/// * [ThemeData.pageTransitionsTheme], which defines the default page
/// transitions for the overall theme.
/// * [FadeUpwardsPageTransitionsBuilder], which defines a default page transition.
/// * [FadeUpwardsPageTransitionsBuilder], which defines a page transition
/// that's similar to the one provided by Android O.
/// * [OpenUpwardsPageTransitionsBuilder], which defines a page transition
/// that's similar to the one provided by Android P.
/// * [ZoomPageTransitionsBuilder], which defines the default page transition
/// that's similar to the one provided by Android Q.
/// * [CupertinoPageTransitionsBuilder], which defines a horizontal page
/// transition that matches native iOS page transitions.
@immutable
Expand All @@ -574,9 +577,9 @@ class PageTransitionsTheme with Diagnosticable {

static const Map<TargetPlatform, PageTransitionsBuilder> _defaultBuilders = <TargetPlatform, PageTransitionsBuilder>{
// Only have default transitions for mobile platforms
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
TargetPlatform.fuchsia: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.fuchsia: ZoomPageTransitionsBuilder(),
};

static const Map<TargetPlatform, PageTransitionsBuilder> _defaultWebBuilders = <TargetPlatform, PageTransitionsBuilder>{
Expand All @@ -587,8 +590,7 @@ class PageTransitionsTheme with Diagnosticable {
Map<TargetPlatform, PageTransitionsBuilder> get builders => _builders;
final Map<TargetPlatform, PageTransitionsBuilder> _builders;

/// Delegates to the builder for the current [ThemeData.platform]
/// or [FadeUpwardsPageTransitionsBuilder].
/// Delegates to the builder for the current [ThemeData.platform].
///
/// [MaterialPageRoute.buildTransitions] delegates to this method.
Widget buildTransitions<T>(
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/test/material/data_table_test.dart
Expand Up @@ -459,7 +459,7 @@ void main() {
home: Material(child: buildTable(sortAscending: true)),
));
// The `tester.widget` ensures that there is exactly one upward arrow.
Transform transformOfArrow = tester.widget<Transform>(find.widgetWithIcon(Transform, Icons.arrow_upward));
Transform transformOfArrow = tester.firstWidget<Transform>(find.widgetWithIcon(Transform, Icons.arrow_upward));
expect(
transformOfArrow.transform.getRotation(),
equals(Matrix3.identity()),
Expand All @@ -471,7 +471,7 @@ void main() {
));
await tester.pumpAndSettle();
// The `tester.widget` ensures that there is exactly one upward arrow.
transformOfArrow = tester.widget<Transform>(find.widgetWithIcon(Transform, Icons.arrow_upward));
transformOfArrow = tester.firstWidget<Transform>(find.widgetWithIcon(Transform, Icons.arrow_upward));
expect(
transformOfArrow.transform.getRotation(),
equals(Matrix3.rotationZ(math.pi)),
Expand Down
7 changes: 6 additions & 1 deletion packages/flutter/test/material/flexible_space_bar_test.dart
Expand Up @@ -98,7 +98,12 @@ void main() {
);

final RenderBox clipRect = tester.renderObject(find.byType(ClipRect).first);
final Transform transform = tester.firstWidget(find.byType(Transform));
final Transform transform = tester.firstWidget(
find.descendant(
of: find.byType(FlexibleSpaceBar),
matching: find.byType(Transform),
),
);

// The current (200) is half way between the min (100) and max (300) and the
// lerp values used to calculate the scale are 1 and 1.5, so we check for 1.25.
Expand Down

0 comments on commit df399f9

Please sign in to comment.