Animation API improvements (#21540)
This commit is contained in:
@@ -318,18 +318,15 @@ class _BackdropDemoState extends State<BackdropDemo> with SingleTickerProviderSt
|
||||
final Size panelSize = constraints.biggest;
|
||||
final double panelTop = panelSize.height - panelTitleHeight;
|
||||
|
||||
final Animation<RelativeRect> panelAnimation = RelativeRectTween(
|
||||
begin: RelativeRect.fromLTRB(
|
||||
0.0,
|
||||
panelTop - MediaQuery.of(context).padding.bottom,
|
||||
0.0,
|
||||
panelTop - panelSize.height,
|
||||
),
|
||||
end: const RelativeRect.fromLTRB(0.0, 0.0, 0.0, 0.0),
|
||||
).animate(
|
||||
CurvedAnimation(
|
||||
parent: _controller,
|
||||
curve: Curves.linear,
|
||||
final Animation<RelativeRect> panelAnimation = _controller.drive(
|
||||
RelativeRectTween(
|
||||
begin: RelativeRect.fromLTRB(
|
||||
0.0,
|
||||
panelTop - MediaQuery.of(context).padding.bottom,
|
||||
0.0,
|
||||
panelTop - panelSize.height,
|
||||
),
|
||||
end: const RelativeRect.fromLTRB(0.0, 0.0, 0.0, 0.0),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -24,10 +24,9 @@ class NavigationIconView {
|
||||
duration: kThemeAnimationDuration,
|
||||
vsync: vsync,
|
||||
) {
|
||||
_animation = CurvedAnimation(
|
||||
parent: controller,
|
||||
_animation = controller.drive(CurveTween(
|
||||
curve: const Interval(0.5, 1.0, curve: Curves.fastOutSlowIn),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
final Widget _icon;
|
||||
@@ -35,7 +34,7 @@ class NavigationIconView {
|
||||
final String _title;
|
||||
final BottomNavigationBarItem item;
|
||||
final AnimationController controller;
|
||||
CurvedAnimation _animation;
|
||||
Animation<double> _animation;
|
||||
|
||||
FadeTransition transition(BottomNavigationBarType type, BuildContext context) {
|
||||
Color iconColor;
|
||||
@@ -51,10 +50,12 @@ class NavigationIconView {
|
||||
return FadeTransition(
|
||||
opacity: _animation,
|
||||
child: SlideTransition(
|
||||
position: Tween<Offset>(
|
||||
begin: const Offset(0.0, 0.02), // Slightly down.
|
||||
end: Offset.zero,
|
||||
).animate(_animation),
|
||||
position: _animation.drive(
|
||||
Tween<Offset>(
|
||||
begin: const Offset(0.0, 0.02), // Slightly down.
|
||||
end: Offset.zero,
|
||||
),
|
||||
),
|
||||
child: IconTheme(
|
||||
data: IconThemeData(
|
||||
color: iconColor,
|
||||
|
||||
@@ -23,6 +23,13 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
|
||||
'A', 'B', 'C', 'D', 'E',
|
||||
];
|
||||
|
||||
static final Animatable<Offset> _drawerDetailsTween = Tween<Offset>(
|
||||
begin: const Offset(0.0, -1.0),
|
||||
end: Offset.zero,
|
||||
).chain(CurveTween(
|
||||
curve: Curves.fastOutSlowIn,
|
||||
));
|
||||
|
||||
AnimationController _controller;
|
||||
Animation<double> _drawerContentsOpacity;
|
||||
Animation<Offset> _drawerDetailsPosition;
|
||||
@@ -39,13 +46,7 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
|
||||
parent: ReverseAnimation(_controller),
|
||||
curve: Curves.fastOutSlowIn,
|
||||
);
|
||||
_drawerDetailsPosition = Tween<Offset>(
|
||||
begin: const Offset(0.0, -1.0),
|
||||
end: Offset.zero,
|
||||
).animate(CurvedAnimation(
|
||||
parent: _controller,
|
||||
curve: Curves.fastOutSlowIn,
|
||||
));
|
||||
_drawerDetailsPosition = _controller.drive(_drawerDetailsTween);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -117,10 +117,10 @@ class _GridPhotoViewerState extends State<GridPhotoViewer> with SingleTickerProv
|
||||
return;
|
||||
final Offset direction = details.velocity.pixelsPerSecond / magnitude;
|
||||
final double distance = (Offset.zero & context.size).shortestSide;
|
||||
_flingAnimation = Tween<Offset>(
|
||||
_flingAnimation = _controller.drive(Tween<Offset>(
|
||||
begin: _offset,
|
||||
end: _clampOffset(_offset + direction * distance)
|
||||
).animate(_controller);
|
||||
));
|
||||
_controller
|
||||
..value = 0.0
|
||||
..fling(velocity: magnitude / 1000.0);
|
||||
|
||||
@@ -35,7 +35,7 @@ class _CustomThumbShape extends SliderComponentShape {
|
||||
return isEnabled ? const Size.fromRadius(_thumbSize) : const Size.fromRadius(_disabledThumbSize);
|
||||
}
|
||||
|
||||
static final Tween<double> sizeTween = Tween<double>(
|
||||
static final Animatable<double> sizeTween = Tween<double>(
|
||||
begin: _disabledThumbSize,
|
||||
end: _thumbSize,
|
||||
);
|
||||
@@ -74,7 +74,7 @@ class _CustomValueIndicatorShape extends SliderComponentShape {
|
||||
return Size.fromRadius(isEnabled ? _indicatorSize : _disabledIndicatorSize);
|
||||
}
|
||||
|
||||
static final Tween<double> sizeTween = Tween<double>(
|
||||
static final Animatable<double> sizeTween = Tween<double>(
|
||||
begin: _disabledIndicatorSize,
|
||||
end: _indicatorSize,
|
||||
);
|
||||
|
||||
@@ -120,7 +120,7 @@ class _RecipeGridPageState extends State<RecipeGridPage> {
|
||||
final Size size = constraints.biggest;
|
||||
final double appBarHeight = size.height - statusBarHeight;
|
||||
final double t = (appBarHeight - kToolbarHeight) / (_kAppBarHeight - kToolbarHeight);
|
||||
final double extraPadding = Tween<double>(begin: 10.0, end: 24.0).lerp(t);
|
||||
final double extraPadding = Tween<double>(begin: 10.0, end: 24.0).transform(t);
|
||||
final double logoHeight = appBarHeight - 1.5 * extraPadding;
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
|
||||
@@ -12,7 +12,7 @@ const double _kFrontClosedHeight = 92.0; // front layer height when closed
|
||||
const double _kBackAppBarHeight = 56.0; // back layer (options) appbar height
|
||||
|
||||
// The size of the front layer heading's left and right beveled corners.
|
||||
final Tween<BorderRadius> _kFrontHeadingBevelRadius = BorderRadiusTween(
|
||||
final Animatable<BorderRadius> _kFrontHeadingBevelRadius = BorderRadiusTween(
|
||||
begin: const BorderRadius.only(
|
||||
topLeft: Radius.circular(12.0),
|
||||
topRight: Radius.circular(12.0),
|
||||
@@ -199,6 +199,9 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
|
||||
AnimationController _controller;
|
||||
Animation<double> _frontOpacity;
|
||||
|
||||
static final Animatable<double> _frontOpacityTween = Tween<double>(begin: 0.2, end: 1.0)
|
||||
.chain(CurveTween(curve: const Interval(0.0, 0.4, curve: Curves.easeInOut)));
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -207,14 +210,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
|
||||
value: 1.0,
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
_frontOpacity =
|
||||
Tween<double>(begin: 0.2, end: 1.0).animate(
|
||||
CurvedAnimation(
|
||||
parent: _controller,
|
||||
curve: const Interval(0.0, 0.4, curve: Curves.easeInOut),
|
||||
),
|
||||
);
|
||||
_frontOpacity = _controller.drive(_frontOpacityTween);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -254,10 +250,10 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
|
||||
}
|
||||
|
||||
Widget _buildStack(BuildContext context, BoxConstraints constraints) {
|
||||
final Animation<RelativeRect> frontRelativeRect = RelativeRectTween(
|
||||
final Animation<RelativeRect> frontRelativeRect = _controller.drive(RelativeRectTween(
|
||||
begin: RelativeRect.fromLTRB(0.0, constraints.biggest.height - _kFrontClosedHeight, 0.0, 0.0),
|
||||
end: const RelativeRect.fromLTRB(0.0, _kBackAppBarHeight, 0.0, 0.0),
|
||||
).animate(_controller);
|
||||
));
|
||||
|
||||
final List<Widget> layers = <Widget>[
|
||||
// Back layer
|
||||
@@ -301,7 +297,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
|
||||
color: Theme.of(context).canvasColor,
|
||||
clipper: ShapeBorderClipper(
|
||||
shape: BeveledRectangleBorder(
|
||||
borderRadius: _kFrontHeadingBevelRadius.lerp(_controller.value),
|
||||
borderRadius: _kFrontHeadingBevelRadius.transform(_controller.value),
|
||||
),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
|
||||
Reference in New Issue
Block a user