Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
ecb72f97
Commit
ecb72f97
authored
Jan 20, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1318 from abarth/finish_port
Port the remainder of the framework to AnimationController
parents
aabd1ce4
b988a875
Changes
38
Hide whitespace changes
Inline
Side-by-side
Showing
38 changed files
with
579 additions
and
1539 deletions
+579
-1539
page_selector_demo.dart
examples/material_gallery/lib/demo/page_selector_demo.dart
+1
-1
progress_indicator_demo.dart
...es/material_gallery/lib/demo/progress_indicator_demo.dart
+3
-3
smooth_resize.dart
examples/widgets/smooth_resize.dart
+6
-6
animation.dart
packages/flutter/lib/animation.dart
+2
-2
animated_value.dart
packages/flutter/lib/src/animation/animated_value.dart
+0
-129
animation.dart
packages/flutter/lib/src/animation/animation.dart
+98
-0
animation_controller.dart
packages/flutter/lib/src/animation/animation_controller.dart
+157
-0
animations.dart
packages/flutter/lib/src/animation/animations.dart
+117
-36
listener_helpers.dart
packages/flutter/lib/src/animation/listener_helpers.dart
+7
-22
performance.dart
packages/flutter/lib/src/animation/performance.dart
+0
-732
simulation_stepper.dart
packages/flutter/lib/src/animation/simulation_stepper.dart
+15
-14
tween.dart
packages/flutter/lib/src/animation/tween.dart
+23
-293
bottom_sheet.dart
packages/flutter/lib/src/material/bottom_sheet.dart
+1
-1
dialog.dart
packages/flutter/lib/src/material/dialog.dart
+2
-2
drawer.dart
packages/flutter/lib/src/material/drawer.dart
+6
-6
dropdown.dart
packages/flutter/lib/src/material/dropdown.dart
+1
-1
floating_action_button.dart
...ages/flutter/lib/src/material/floating_action_button.dart
+1
-1
material.dart
packages/flutter/lib/src/material/material.dart
+7
-7
page.dart
packages/flutter/lib/src/material/page.dart
+3
-3
popup_menu.dart
packages/flutter/lib/src/material/popup_menu.dart
+2
-2
progress_indicator.dart
packages/flutter/lib/src/material/progress_indicator.dart
+3
-3
scaffold.dart
packages/flutter/lib/src/material/scaffold.dart
+10
-10
slider.dart
packages/flutter/lib/src/material/slider.dart
+2
-2
snack_bar.dart
packages/flutter/lib/src/material/snack_bar.dart
+2
-2
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+9
-9
time_picker.dart
packages/flutter/lib/src/material/time_picker.dart
+1
-1
toggleable.dart
packages/flutter/lib/src/material/toggleable.dart
+4
-4
tooltip.dart
packages/flutter/lib/src/material/tooltip.dart
+6
-6
box.dart
packages/flutter/lib/src/rendering/box.dart
+2
-3
dismissable.dart
packages/flutter/lib/src/widgets/dismissable.dart
+4
-4
enter_exit_transition.dart
packages/flutter/lib/src/widgets/enter_exit_transition.dart
+26
-17
heroes.dart
packages/flutter/lib/src/widgets/heroes.dart
+13
-13
implicit_animations.dart
packages/flutter/lib/src/widgets/implicit_animations.dart
+2
-2
modal_barrier.dart
packages/flutter/lib/src/widgets/modal_barrier.dart
+2
-2
routes.dart
packages/flutter/lib/src/widgets/routes.dart
+17
-17
status_transitions.dart
packages/flutter/lib/src/widgets/status_transitions.dart
+2
-2
transitions.dart
packages/flutter/lib/src/widgets/transitions.dart
+19
-178
page_forward_transitions_test.dart
...es/flutter/test/widget/page_forward_transitions_test.dart
+3
-3
No files found.
examples/material_gallery/lib/demo/page_selector_demo.dart
View file @
ecb72f97
...
...
@@ -18,7 +18,7 @@ class PageSelectorDemo extends StatelessComponent {
builder:
(
BuildContext
context
,
Widget
child
)
{
Color
background
=
selection
.
value
==
iconName
?
_selectedColor
.
end
:
_selectedColor
.
begin
;
if
(
selection
.
valueIsChanging
)
{
// Then the selection's
performance
is animating from previousValue to value.
// Then the selection's
animation
is animating from previousValue to value.
if
(
selection
.
value
==
iconName
)
background
=
_selectedColor
.
evaluate
(
animation
);
else
if
(
selection
.
previousValue
==
iconName
)
...
...
examples/material_gallery/lib/demo/progress_indicator_demo.dart
View file @
ecb72f97
...
...
@@ -21,13 +21,13 @@ class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> {
parent:
controller
,
curve:
new
Interval
(
0.0
,
0.9
,
curve:
Curves
.
ease
),
reverseCurve:
Curves
.
ease
)..
addStatusListener
((
Performance
Status
status
)
{
if
(
status
==
PerformanceStatus
.
dismissed
||
status
==
Performance
Status
.
completed
)
)..
addStatusListener
((
Animation
Status
status
)
{
if
(
status
==
AnimationStatus
.
dismissed
||
status
==
Animation
Status
.
completed
)
reverseValueAnimationDirection
();
});
}
Animat
ed
<
double
>
animation
;
Animat
ion
<
double
>
animation
;
AnimationController
controller
;
void
handleTap
()
{
...
...
examples/widgets/smooth_resize.dart
View file @
ecb72f97
...
...
@@ -33,10 +33,10 @@ class CardTransition extends StatelessComponent {
});
final
Widget
child
;
final
Animat
ed
<
double
>
animation
;
final
Evalu
atable
<
double
>
x
;
final
Evalu
atable
<
double
>
opacity
;
final
Evalu
atable
<
double
>
scale
;
final
Animat
ion
<
double
>
animation
;
final
Anim
atable
<
double
>
x
;
final
Anim
atable
<
double
>
opacity
;
final
Anim
atable
<
double
>
scale
;
Widget
build
(
BuildContext
context
)
{
return
new
AnimatedBuilder
(
...
...
@@ -63,7 +63,7 @@ class SmoothBlockState extends State<SmoothBlock> {
double
_height
=
100.0
;
Widget
_handleEnter
(
Animat
ed
<
double
>
animation
,
Widget
child
)
{
Widget
_handleEnter
(
Animat
ion
<
double
>
animation
,
Widget
child
)
{
return
new
CardTransition
(
x:
new
Tween
<
double
>(
begin:
-
200.0
,
end:
0.0
),
opacity:
new
Tween
<
double
>(
begin:
0.0
,
end:
1.0
),
...
...
@@ -73,7 +73,7 @@ class SmoothBlockState extends State<SmoothBlock> {
);
}
Widget
_handleExit
(
Animat
ed
<
double
>
animation
,
Widget
child
)
{
Widget
_handleExit
(
Animat
ion
<
double
>
animation
,
Widget
child
)
{
return
new
CardTransition
(
x:
new
Tween
<
double
>(
begin:
0.0
,
end:
200.0
),
opacity:
new
Tween
<
double
>(
begin:
1.0
,
end:
0.0
),
...
...
packages/flutter/lib/animation.dart
View file @
ecb72f97
...
...
@@ -7,13 +7,13 @@
/// This library depends only on core Dart libraries and the `newton` package.
library
animation
;
export
'src/animation/animated_value.dart'
;
export
'src/animation/animation.dart'
;
export
'src/animation/animation_controller.dart'
;
export
'src/animation/animations.dart'
;
export
'src/animation/clamped_simulation.dart'
;
export
'src/animation/curves.dart'
;
export
'src/animation/forces.dart'
;
export
'src/animation/listener_helpers.dart'
;
export
'src/animation/performance.dart'
;
export
'src/animation/scroll_behavior.dart'
;
export
'src/animation/simulation_stepper.dart'
;
export
'src/animation/ticker.dart'
;
...
...
packages/flutter/lib/src/animation/animated_value.dart
deleted
100644 → 0
View file @
aabd1ce4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:ui'
show
Color
,
Size
,
Rect
;
import
'curves.dart'
;
/// The direction in which an animation is running.
enum
AnimationDirection
{
/// The animation is running from beginning to end.
forward
,
/// The animation is running backwards, from end to beginning.
reverse
}
/// An interface describing a variable that changes as an animation progresses.
///
/// Animatable objects, by convention, must be cheap to create. This allows them
/// to be used in build functions in Widgets.
abstract
class
Animatable
{
// TODO(ianh): replace mentions of this class with just mentioning AnimatedValue directly
/// Update the variable to a given time in an animation that is running in the given direction
void
setProgress
(
double
t
,
AnimationDirection
direction
);
}
/// An animated variable with a concrete type.
class
AnimatedValue
<
T
extends
dynamic
>
implements
Animatable
{
AnimatedValue
(
this
.
begin
,
{
this
.
end
,
this
.
curve
,
this
.
reverseCurve
})
{
value
=
begin
;
}
/// The current value of this variable.
T
value
;
/// The value this variable has at the beginning of the animation.
T
begin
;
/// The value this variable has at the end of the animation.
T
end
;
/// Returns the value this variable has at the given animation clock value.
T
lerp
(
double
t
)
=>
begin
+
(
end
-
begin
)
*
t
;
/// The curve to use in the forward direction.
Curve
curve
;
/// The curve to use in the reverse direction.
///
/// If this field is null, uses [curve] in both directions.
Curve
reverseCurve
;
Curve
_getActiveCurve
(
AnimationDirection
direction
)
{
if
(
direction
==
AnimationDirection
.
forward
||
reverseCurve
==
null
)
return
curve
;
return
reverseCurve
;
}
double
transform
(
double
t
,
AnimationDirection
direction
)
{
Curve
activeCurve
=
_getActiveCurve
(
direction
);
if
(
activeCurve
==
null
)
return
t
;
if
(
t
==
0.0
||
t
==
1.0
)
{
assert
(
activeCurve
.
transform
(
t
).
round
()
==
t
);
return
t
;
}
return
activeCurve
.
transform
(
t
);
}
/// Updates the value of this variable according to the given animation clock
/// value and direction.
void
setProgress
(
double
t
,
AnimationDirection
direction
)
{
if
(
end
!=
null
)
{
t
=
transform
(
t
,
direction
);
if
(
t
==
0.0
)
value
=
begin
;
else
if
(
t
==
1.0
)
value
=
end
;
else
value
=
lerp
(
t
);
}
}
String
toString
()
=>
'AnimatedValue(begin=
$begin
, end=
$end
, value=
$value
)'
;
}
/// An animated variable containing a color.
///
/// This class specializes the interpolation of AnimatedValue<Color> to be
/// appropriate for colors.
class
AnimatedColorValue
extends
AnimatedValue
<
Color
>
{
AnimatedColorValue
(
Color
begin
,
{
Color
end
,
Curve
curve
,
Curve
reverseCurve
})
:
super
(
begin
,
end:
end
,
curve:
curve
,
reverseCurve:
reverseCurve
);
Color
lerp
(
double
t
)
=>
Color
.
lerp
(
begin
,
end
,
t
);
}
/// An animated variable containing a size.
///
/// This class specializes the interpolation of AnimatedValue<Size> to be
/// appropriate for rectangles.
class
AnimatedSizeValue
extends
AnimatedValue
<
Size
>
{
AnimatedSizeValue
(
Size
begin
,
{
Size
end
,
Curve
curve
,
Curve
reverseCurve
})
:
super
(
begin
,
end:
end
,
curve:
curve
,
reverseCurve:
reverseCurve
);
Size
lerp
(
double
t
)
=>
Size
.
lerp
(
begin
,
end
,
t
);
}
/// An animated variable containing a rectangle.
///
/// This class specializes the interpolation of AnimatedValue<Rect> to be
/// appropriate for rectangles.
class
AnimatedRectValue
extends
AnimatedValue
<
Rect
>
{
AnimatedRectValue
(
Rect
begin
,
{
Rect
end
,
Curve
curve
,
Curve
reverseCurve
})
:
super
(
begin
,
end:
end
,
curve:
curve
,
reverseCurve:
reverseCurve
);
Rect
lerp
(
double
t
)
=>
Rect
.
lerp
(
begin
,
end
,
t
);
}
/// An animated variable containing a int.
class
AnimatedIntValue
extends
AnimatedValue
<
int
>
{
AnimatedIntValue
(
int
begin
,
{
int
end
,
Curve
curve
,
Curve
reverseCurve
})
:
super
(
begin
,
end:
end
,
curve:
curve
,
reverseCurve:
reverseCurve
);
// The inherited lerp() function doesn't work with ints because it multiplies
// the begin and end types by a double, and int * double returns a double.
int
lerp
(
double
t
)
=>
(
begin
+
(
end
-
begin
)
*
t
).
round
();
}
packages/flutter/lib/src/animation/animation.dart
0 → 100644
View file @
ecb72f97
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:ui'
show
Color
,
Size
,
Rect
,
VoidCallback
,
lerpDouble
;
/// The direction in which an animation is running.
enum
AnimationDirection
{
/// The animation is running from beginning to end.
forward
,
/// The animation is running backwards, from end to beginning.
reverse
}
/// The status of an animation
enum
AnimationStatus
{
/// The animation is stopped at the beginning
dismissed
,
/// The animation is running from beginning to end
forward
,
/// The animation is running backwards, from end to beginning
reverse
,
/// The animation is stopped at the end
completed
,
}
typedef
void
AnimationStatusListener
(
AnimationStatus
status
);
abstract
class
Animation
<
T
>
{
const
Animation
();
/// Calls the listener every time the value of the animation changes.
void
addListener
(
VoidCallback
listener
);
/// Stop calling the listener every time the value of the animation changes.
void
removeListener
(
VoidCallback
listener
);
/// Calls listener every time the status of the animation changes.
void
addStatusListener
(
AnimationStatusListener
listener
);
/// Stops calling the listener every time the status of the animation changes.
void
removeStatusListener
(
AnimationStatusListener
listener
);
/// The current status of this animation.
AnimationStatus
get
status
;
/// The current direction of the animation.
AnimationDirection
get
direction
;
/// The current value of the animation.
T
get
value
;
/// Whether this animation is stopped at the beginning.
bool
get
isDismissed
=>
status
==
AnimationStatus
.
dismissed
;
/// Whether this animation is stopped at the end.
bool
get
isCompleted
=>
status
==
AnimationStatus
.
completed
;
String
toString
()
{
return
'
$runtimeType
(
${toStringDetails()}
)'
;
}
String
toStringDetails
()
{
assert
(
status
!=
null
);
assert
(
direction
!=
null
);
String
icon
;
switch
(
status
)
{
case
AnimationStatus
.
forward
:
icon
=
'
\
u25B6'
;
// >
break
;
case
AnimationStatus
.
reverse
:
icon
=
'
\
u25C0'
;
// <
break
;
case
AnimationStatus
.
completed
:
switch
(
direction
)
{
case
AnimationDirection
.
forward
:
icon
=
'
\
u23ED'
;
// >>|
break
;
case
AnimationDirection
.
reverse
:
icon
=
'
\
u29CF'
;
// <|
break
;
}
break
;
case
AnimationStatus
.
dismissed
:
switch
(
direction
)
{
case
AnimationDirection
.
forward
:
icon
=
'
\
u29D0'
;
// |>
break
;
case
AnimationDirection
.
reverse
:
icon
=
'
\
u23EE'
;
// |<<
break
;
}
break
;
}
assert
(
icon
!=
null
);
return
'
$icon
'
;
}
}
packages/flutter/lib/src/animation/animation_controller.dart
0 → 100644
View file @
ecb72f97
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'dart:ui'
show
Color
,
Size
,
Rect
,
VoidCallback
,
lerpDouble
;
import
'package:newton/newton.dart'
;
import
'animation.dart'
;
import
'forces.dart'
;
import
'listener_helpers.dart'
;
import
'simulation_stepper.dart'
;
class
AnimationController
extends
Animation
<
double
>
with
EagerListenerMixin
,
LocalPerformanceListenersMixin
,
LocalPerformanceStatusListenersMixin
{
AnimationController
({
this
.
duration
,
double
value
,
this
.
debugLabel
})
{
_timeline
=
new
SimulationStepper
(
_tick
);
if
(
value
!=
null
)
_timeline
.
value
=
value
.
clamp
(
0.0
,
1.0
);
}
/// A label that is used in the [toString] output. Intended to aid with
/// identifying animation controller instances in debug output.
final
String
debugLabel
;
/// Returns a [Animated<double>] for this animation controller,
/// so that a pointer to this object can be passed around without
/// allowing users of that pointer to mutate the AnimationController state.
Animation
<
double
>
get
view
=>
this
;
/// The length of time this animation should last.
Duration
duration
;
SimulationStepper
_timeline
;
AnimationDirection
get
direction
=>
_direction
;
AnimationDirection
_direction
=
AnimationDirection
.
forward
;
/// The progress of this animation along the timeline.
///
/// Note: Setting this value stops the current animation.
double
get
value
=>
_timeline
.
value
.
clamp
(
0.0
,
1.0
);
void
set
value
(
double
t
)
{
stop
();
_timeline
.
value
=
t
.
clamp
(
0.0
,
1.0
);
_checkStatusChanged
();
}
/// Whether this animation is currently animating in either the forward or reverse direction.
bool
get
isAnimating
=>
_timeline
.
isAnimating
;
AnimationStatus
get
status
{
if
(!
isAnimating
&&
value
==
1.0
)
return
AnimationStatus
.
completed
;
if
(!
isAnimating
&&
value
==
0.0
)
return
AnimationStatus
.
dismissed
;
return
_direction
==
AnimationDirection
.
forward
?
AnimationStatus
.
forward
:
AnimationStatus
.
reverse
;
}
/// Starts running this animation forwards (towards the end).
Future
forward
()
=>
play
(
AnimationDirection
.
forward
);
/// Starts running this animation in reverse (towards the beginning).
Future
reverse
()
=>
play
(
AnimationDirection
.
reverse
);
/// Starts running this animation in the given direction.
Future
play
(
AnimationDirection
direction
)
{
_direction
=
direction
;
return
resume
();
}
/// Resumes this animation in the most recent direction.
Future
resume
()
{
return
_animateTo
(
_direction
==
AnimationDirection
.
forward
?
1.0
:
0.0
);
}
/// Stops running this animation.
void
stop
()
{
_timeline
.
stop
();
}
/// Releases any resources used by this object.
///
/// Same as stop().
void
dispose
()
{
stop
();
}
///
/// Flings the timeline with an optional force (defaults to a critically
/// damped spring) and initial velocity. If velocity is positive, the
/// animation will complete, otherwise it will dismiss.
Future
fling
({
double
velocity:
1.0
,
Force
force
})
{
force
??=
kDefaultSpringForce
;
_direction
=
velocity
<
0.0
?
AnimationDirection
.
reverse
:
AnimationDirection
.
forward
;
return
_timeline
.
animateWith
(
force
.
release
(
value
,
velocity
));
}
/// Starts running this animation in the forward direction, and
/// restarts the animation when it completes.
Future
repeat
({
double
min:
0.0
,
double
max:
1.0
,
Duration
period
})
{
period
??=
duration
;
return
_timeline
.
animateWith
(
new
_RepeatingSimulation
(
min
,
max
,
period
));
}
AnimationStatus
_lastStatus
=
AnimationStatus
.
dismissed
;
void
_checkStatusChanged
()
{
AnimationStatus
currentStatus
=
status
;
if
(
currentStatus
!=
_lastStatus
)
notifyStatusListeners
(
status
);
_lastStatus
=
currentStatus
;
}
Future
_animateTo
(
double
target
)
{
Duration
remainingDuration
=
duration
*
(
target
-
_timeline
.
value
).
abs
();
_timeline
.
stop
();
if
(
remainingDuration
==
Duration
.
ZERO
)
return
new
Future
.
value
();
return
_timeline
.
animateTo
(
target
,
duration:
remainingDuration
);
}
void
_tick
(
double
t
)
{
notifyListeners
();
_checkStatusChanged
();
}
String
toStringDetails
()
{
String
paused
=
_timeline
.
isAnimating
?
''
:
'; paused'
;
String
label
=
debugLabel
==
null
?
''
:
'; for
$debugLabel
'
;
String
more
=
'
${super.toStringDetails()}
${value.toStringAsFixed(3)}
'
;
return
'
$more$paused$label
'
;
}
}
class
_RepeatingSimulation
extends
Simulation
{
_RepeatingSimulation
(
this
.
min
,
this
.
max
,
Duration
period
)
:
_periodInSeconds
=
period
.
inMicroseconds
/
Duration
.
MICROSECONDS_PER_SECOND
{
assert
(
_periodInSeconds
>
0.0
);
}
final
double
min
;
final
double
max
;
final
double
_periodInSeconds
;
double
x
(
double
timeInSeconds
)
{
assert
(
timeInSeconds
>=
0.0
);
final
double
t
=
(
timeInSeconds
/
_periodInSeconds
)
%
1.0
;
return
lerpDouble
(
min
,
max
,
t
);
}
double
dx
(
double
timeInSeconds
)
=>
1.0
;
bool
isDone
(
double
timeInSeconds
)
=>
false
;
}
packages/flutter/lib/src/animation/animations.dart
View file @
ecb72f97
...
...
@@ -4,58 +4,81 @@
import
'dart:ui'
show
VoidCallback
;
import
'animated_value.dart'
;
import
'animation.dart'
;
import
'curves.dart'
;
import
'listener_helpers.dart'
;
import
'tween.dart'
;
class
AlwaysCompleteAnimation
extends
Animat
ed
<
double
>
{
class
AlwaysCompleteAnimation
extends
Animat
ion
<
double
>
{
const
AlwaysCompleteAnimation
();
// this performance never changes state
void
addListener
(
VoidCallback
listener
)
{
}
void
removeListener
(
VoidCallback
listener
)
{
}
void
addStatusListener
(
Performance
StatusListener
listener
)
{
}
void
removeStatusListener
(
Performance
StatusListener
listener
)
{
}
PerformanceStatus
get
status
=>
Performance
Status
.
completed
;
void
addStatusListener
(
Animation
StatusListener
listener
)
{
}
void
removeStatusListener
(
Animation
StatusListener
listener
)
{
}
AnimationStatus
get
status
=>
Animation
Status
.
completed
;
AnimationDirection
get
direction
=>
AnimationDirection
.
forward
;
double
get
value
=>
1.0
;
}
const
AlwaysCompleteAnimation
kAlwaysCompleteAnimation
=
const
AlwaysCompleteAnimation
();
class
AlwaysDismissedAnimation
extends
Animat
ed
<
double
>
{
class
AlwaysDismissedAnimation
extends
Animat
ion
<
double
>
{
const
AlwaysDismissedAnimation
();
// this performance never changes state
void
addListener
(
VoidCallback
listener
)
{
}
void
removeListener
(
VoidCallback
listener
)
{
}
void
addStatusListener
(
Performance
StatusListener
listener
)
{
}
void
removeStatusListener
(
Performance
StatusListener
listener
)
{
}
PerformanceStatus
get
status
=>
Performance
Status
.
dismissed
;
void
addStatusListener
(
Animation
StatusListener
listener
)
{
}
void
removeStatusListener
(
Animation
StatusListener
listener
)
{
}
AnimationStatus
get
status
=>
Animation
Status
.
dismissed
;
AnimationDirection
get
direction
=>
AnimationDirection
.
forward
;
double
get
value
=>
0.0
;
}
const
AlwaysDismissedAnimation
kAlwaysDismissedAnimation
=
const
AlwaysDismissedAnimation
();
class
ProxyAnimation
extends
Animated
<
double
>
class
AlwaysStoppedAnimation
extends
Animation
<
double
>
{
const
AlwaysStoppedAnimation
(
this
.
value
);
final
double
value
;
void
addListener
(
VoidCallback
listener
)
{
}
void
removeListener
(
VoidCallback
listener
)
{
}
void
addStatusListener
(
AnimationStatusListener
listener
)
{
}
void
removeStatusListener
(
AnimationStatusListener
listener
)
{
}
AnimationStatus
get
status
=>
AnimationStatus
.
forward
;
AnimationDirection
get
direction
=>
AnimationDirection
.
forward
;
}
abstract
class
ProxyAnimatedMixin
{
Animation
<
double
>
get
parent
;
void
addListener
(
VoidCallback
listener
)
=>
parent
.
addListener
(
listener
);
void
removeListener
(
VoidCallback
listener
)
=>
parent
.
removeListener
(
listener
);
void
addStatusListener
(
AnimationStatusListener
listener
)
=>
parent
.
addStatusListener
(
listener
);
void
removeStatusListener
(
AnimationStatusListener
listener
)
=>
parent
.
removeStatusListener
(
listener
);
AnimationStatus
get
status
=>
parent
.
status
;
AnimationDirection
get
direction
=>
parent
.
direction
;
}
class
ProxyAnimation
extends
Animation
<
double
>
with
LazyListenerMixin
,
LocalPerformanceListenersMixin
,
LocalPerformanceStatusListenersMixin
{
ProxyAnimation
([
Animat
ed
<
double
>
animation
])
{
ProxyAnimation
([
Animat
ion
<
double
>
animation
])
{
_masterAnimation
=
animation
;
if
(
_masterAnimation
==
null
)
{
_status
=
Performance
Status
.
dismissed
;
_status
=
Animation
Status
.
dismissed
;
_direction
=
AnimationDirection
.
forward
;
_value
=
0.0
;
}
}
Performance
Status
_status
;
Animation
Status
_status
;
AnimationDirection
_direction
;
double
_value
;
Animat
ed
<
double
>
get
masterAnimation
=>
_masterAnimation
;
Animat
ed
<
double
>
_masterAnimation
;
void
set
masterAnimation
(
Animat
ed
<
double
>
value
)
{
Animat
ion
<
double
>
get
masterAnimation
=>
_masterAnimation
;
Animat
ion
<
double
>
_masterAnimation
;
void
set
masterAnimation
(
Animat
ion
<
double
>
value
)
{
if
(
value
==
_masterAnimation
)
return
;
if
(
_masterAnimation
!=
null
)
{
...
...
@@ -93,16 +116,16 @@ class ProxyAnimation extends Animated<double>
}
}
Performance
Status
get
status
=>
_masterAnimation
!=
null
?
_masterAnimation
.
status
:
_status
;
Animation
Status
get
status
=>
_masterAnimation
!=
null
?
_masterAnimation
.
status
:
_status
;
AnimationDirection
get
direction
=>
_masterAnimation
!=
null
?
_masterAnimation
.
direction
:
_direction
;
double
get
value
=>
_masterAnimation
!=
null
?
_masterAnimation
.
value
:
_value
;
}
class
ReverseAnimation
extends
Animat
ed
<
double
>
class
ReverseAnimation
extends
Animat
ion
<
double
>
with
LazyListenerMixin
,
LocalPerformanceStatusListenersMixin
{
ReverseAnimation
(
this
.
masterAnimation
);
final
Animat
ed
<
double
>
masterAnimation
;
final
Animat
ion
<
double
>
masterAnimation
;
void
addListener
(
VoidCallback
listener
)
{
didRegisterListener
();
...
...
@@ -121,20 +144,20 @@ class ReverseAnimation extends Animated<double>
masterAnimation
.
removeStatusListener
(
_statusChangeHandler
);
}
void
_statusChangeHandler
(
Performance
Status
status
)
{
void
_statusChangeHandler
(
Animation
Status
status
)
{
notifyStatusListeners
(
_reverseStatus
(
status
));
}
Performance
Status
get
status
=>
_reverseStatus
(
masterAnimation
.
status
);
Animation
Status
get
status
=>
_reverseStatus
(
masterAnimation
.
status
);
AnimationDirection
get
direction
=>
_reverseDirection
(
masterAnimation
.
direction
);
double
get
value
=>
1.0
-
masterAnimation
.
value
;
PerformanceStatus
_reverseStatus
(
Performance
Status
status
)
{
AnimationStatus
_reverseStatus
(
Animation
Status
status
)
{
switch
(
status
)
{
case
PerformanceStatus
.
forward
:
return
Performance
Status
.
reverse
;
case
PerformanceStatus
.
reverse
:
return
Performance
Status
.
forward
;
case
PerformanceStatus
.
completed
:
return
Performance
Status
.
dismissed
;
case
PerformanceStatus
.
dismissed
:
return
Performance
Status
.
completed
;
case
AnimationStatus
.
forward
:
return
Animation
Status
.
reverse
;
case
AnimationStatus
.
reverse
:
return
Animation
Status
.
forward
;
case
AnimationStatus
.
completed
:
return
Animation
Status
.
dismissed
;
case
AnimationStatus
.
dismissed
:
return
Animation
Status
.
completed
;
}
}
...
...
@@ -146,6 +169,64 @@ class ReverseAnimation extends Animated<double>
}
}
class
CurvedAnimation
extends
Animation
<
double
>
with
ProxyAnimatedMixin
{
CurvedAnimation
({
this
.
parent
,
this
.
curve
:
Curves
.
linear
,
this
.
reverseCurve
})
{
assert
(
parent
!=
null
);
assert
(
curve
!=
null
);
parent
.
addStatusListener
(
_handleStatusChanged
);
}
final
Animation
<
double
>
parent
;
/// The curve to use in the forward direction.
Curve
curve
;
/// The curve to use in the reverse direction.
///
/// If this field is null, uses [curve] in both directions.
Curve
reverseCurve
;
/// The direction used to select the current curve.
///
/// The curve direction is only reset when we hit the beginning or the end of
/// the timeline to avoid discontinuities in the value of any variables this
/// a animation is used to animate.
AnimationDirection
_curveDirection
;
void
_handleStatusChanged
(
AnimationStatus
status
)
{
switch
(
status
)
{
case
AnimationStatus
.
dismissed
:
case
AnimationStatus
.
completed
:
_curveDirection
=
null
;
break
;
case
AnimationStatus
.
forward
:
_curveDirection
??=
AnimationDirection
.
forward
;
break
;
case
AnimationStatus
.
reverse
:
_curveDirection
??=
AnimationDirection
.
reverse
;
break
;
}
}
double
get
value
{
final
bool
useForwardCurve
=
reverseCurve
==
null
||
(
_curveDirection
??
parent
.
direction
)
==
AnimationDirection
.
forward
;
Curve
activeCurve
=
useForwardCurve
?
curve
:
reverseCurve
;
double
t
=
parent
.
value
;
if
(
activeCurve
==
null
)
return
t
;
if
(
t
==
0.0
||
t
==
1.0
)
{
assert
(
activeCurve
.
transform
(
t
).
round
()
==
t
);
return
t
;
}
return
activeCurve
.
transform
(
t
);
}
}
enum
_TrainHoppingMode
{
minimize
,
maximize
}
/// This animation starts by proxying one animation, but can be given a
...
...
@@ -158,7 +239,7 @@ enum _TrainHoppingMode { minimize, maximize }
/// listeners of its own, instead of shutting down when all its listeners are
/// removed, it exposes a [dispose()] method. Call this method to shut this
/// object down.
class
TrainHoppingAnimation
extends
Animat
ed
<
double
>
class
TrainHoppingAnimation
extends
Animat
ion
<
double
>
with
EagerListenerMixin
,
LocalPerformanceListenersMixin
,
LocalPerformanceStatusListenersMixin
{
TrainHoppingAnimation
(
this
.
_currentTrain
,
this
.
_nextTrain
,
{
this
.
onSwitchedTrain
})
{
assert
(
_currentTrain
!=
null
);
...
...
@@ -180,15 +261,15 @@ class TrainHoppingAnimation extends Animated<double>
assert
(
_mode
!=
null
);
}
Animat
ed
<
double
>
get
currentTrain
=>
_currentTrain
;
Animat
ed
<
double
>
_currentTrain
;
Animat
ed
<
double
>
_nextTrain
;
Animat
ion
<
double
>
get
currentTrain
=>
_currentTrain
;
Animat
ion
<
double
>
_currentTrain
;
Animat
ion
<
double
>
_nextTrain
;
_TrainHoppingMode
_mode
;
VoidCallback
onSwitchedTrain
;
Performance
Status
_lastStatus
;
void
_statusChangeHandler
(
Performance
Status
status
)
{
Animation
Status
_lastStatus
;
void
_statusChangeHandler
(
Animation
Status
status
)
{
assert
(
_currentTrain
!=
null
);
if
(
status
!=
_lastStatus
)
{
notifyListeners
();
...
...
@@ -197,7 +278,7 @@ class TrainHoppingAnimation extends Animated<double>
assert
(
_lastStatus
!=
null
);
}
Performance
Status
get
status
=>
_currentTrain
.
status
;
Animation
Status
get
status
=>
_currentTrain
.
status
;
AnimationDirection
get
direction
=>
_currentTrain
.
direction
;
double
_lastValue
;
...
...
packages/flutter/lib/src/animation/listener_helpers.dart
View file @
ecb72f97
...
...
@@ -4,22 +4,7 @@
import
'dart:ui'
show
VoidCallback
;
/// The status of an animation
enum
PerformanceStatus
{
/// The animation is stopped at the beginning
dismissed
,
/// The animation is running from beginning to end
forward
,
/// The animation is running backwards, from end to beginning
reverse
,
/// The animation is stopped at the end
completed
,
}
typedef
void
PerformanceStatusListener
(
PerformanceStatus
status
);
import
'animation.dart'
;
abstract
class
_ListenerMixin
{
void
didRegisterListener
();
...
...
@@ -71,18 +56,18 @@ abstract class LocalPerformanceListenersMixin extends _ListenerMixin {
}
abstract
class
LocalPerformanceStatusListenersMixin
extends
_ListenerMixin
{
final
List
<
PerformanceStatusListener
>
_statusListeners
=
<
Performance
StatusListener
>[];
void
addStatusListener
(
Performance
StatusListener
listener
)
{
final
List
<
AnimationStatusListener
>
_statusListeners
=
<
Animation
StatusListener
>[];
void
addStatusListener
(
Animation
StatusListener
listener
)
{
didRegisterListener
();
_statusListeners
.
add
(
listener
);
}
void
removeStatusListener
(
Performance
StatusListener
listener
)
{
void
removeStatusListener
(
Animation
StatusListener
listener
)
{
_statusListeners
.
remove
(
listener
);
didUnregisterListener
();
}
void
notifyStatusListeners
(
Performance
Status
status
)
{
List
<
PerformanceStatusListener
>
localListeners
=
new
List
<
Performance
StatusListener
>.
from
(
_statusListeners
);
for
(
Performance
StatusListener
listener
in
localListeners
)
void
notifyStatusListeners
(
Animation
Status
status
)
{
List
<
AnimationStatusListener
>
localListeners
=
new
List
<
Animation
StatusListener
>.
from
(
_statusListeners
);
for
(
Animation
StatusListener
listener
in
localListeners
)
listener
(
status
);
}
}
packages/flutter/lib/src/animation/performance.dart
deleted
100644 → 0
View file @
aabd1ce4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'dart:ui'
show
VoidCallback
,
lerpDouble
;
import
'package:newton/newton.dart'
;
import
'animated_value.dart'
;
import
'curves.dart'
;
import
'forces.dart'
;
import
'listener_helpers.dart'
;
import
'simulation_stepper.dart'
;
/// A read-only view of a [Performance].
///
/// This interface is implemented by [Performance].
///
/// Read-only access to [Performance] is used by classes that
/// want to watch a performance but should not be able to change the
/// performance's state.
abstract
class
PerformanceView
{
const
PerformanceView
();
/// Update the given variable according to the current progress of the performance.
void
updateVariable
(
Animatable
variable
);
/// Calls the listener every time the progress of the performance changes.
void
addListener
(
VoidCallback
listener
);
/// Stop calling the listener every time the progress of the performance changes.
void
removeListener
(
VoidCallback
listener
);
/// Calls listener every time the status of the performance changes.
void
addStatusListener
(
PerformanceStatusListener
listener
);
/// Stops calling the listener every time the status of the performance changes.
void
removeStatusListener
(
PerformanceStatusListener
listener
);
/// The current status of this animation.
PerformanceStatus
get
status
;
/// The current direction of the animation.
AnimationDirection
get
direction
;
/// The direction used to select the current curve.
///
/// The curve direction is only reset when we hit the beginning or the end of
/// the timeline to avoid discontinuities in the value of any variables this
/// performance is used to animate.
AnimationDirection
get
curveDirection
;
/// The current progress of this animation (a value from 0.0 to 1.0).
///
/// This is the value that is used to update any variables when using
/// [updateVariable].
double
get
progress
;
/// Whether this animation is stopped at the beginning.
bool
get
isDismissed
=>
status
==
PerformanceStatus
.
dismissed
;
/// Whether this animation is stopped at the end.
bool
get
isCompleted
=>
status
==
PerformanceStatus
.
completed
;
String
toString
()
{
return
'
$runtimeType
(
${toStringDetails()}
)'
;
}
String
toStringDetails
()
{
assert
(
status
!=
null
);
assert
(
direction
!=
null
);
String
icon
;
switch
(
status
)
{
case
PerformanceStatus
.
forward
:
icon
=
'
\
u25B6'
;
// >
break
;
case
PerformanceStatus
.
reverse
:
icon
=
'
\
u25C0'
;
// <
break
;
case
PerformanceStatus
.
completed
:
switch
(
direction
)
{
case
AnimationDirection
.
forward
:
icon
=
'
\
u23ED'
;
// >>|
break
;
case
AnimationDirection
.
reverse
:
icon
=
'
\
u29CF'
;
// <|
break
;
}
break
;
case
PerformanceStatus
.
dismissed
:
switch
(
direction
)
{
case
AnimationDirection
.
forward
:
icon
=
'
\
u29D0'
;
// |>
break
;
case
AnimationDirection
.
reverse
:
icon
=
'
\
u23EE'
;
// |<<
break
;
}
break
;
}
assert
(
icon
!=
null
);
return
'
$icon
${progress.toStringAsFixed(3)}
'
;
}
}
class
AlwaysCompletePerformance
extends
PerformanceView
{
const
AlwaysCompletePerformance
();
void
updateVariable
(
Animatable
variable
)
{
variable
.
setProgress
(
1.0
,
AnimationDirection
.
forward
);
}
// this performance never changes state
void
addListener
(
VoidCallback
listener
)
{
}
void
removeListener
(
VoidCallback
listener
)
{
}
void
addStatusListener
(
PerformanceStatusListener
listener
)
{
}
void
removeStatusListener
(
PerformanceStatusListener
listener
)
{
}
PerformanceStatus
get
status
=>
PerformanceStatus
.
completed
;
AnimationDirection
get
direction
=>
AnimationDirection
.
forward
;
AnimationDirection
get
curveDirection
=>
AnimationDirection
.
forward
;
double
get
progress
=>
1.0
;
}
const
AlwaysCompletePerformance
alwaysCompletePerformance
=
const
AlwaysCompletePerformance
();
class
AlwaysDismissedPerformance
extends
PerformanceView
{
const
AlwaysDismissedPerformance
();
void
updateVariable
(
Animatable
variable
)
{
variable
.
setProgress
(
0.0
,
AnimationDirection
.
forward
);
}
// this performance never changes state
void
addListener
(
VoidCallback
listener
)
{
}
void
removeListener
(
VoidCallback
listener
)
{
}
void
addStatusListener
(
PerformanceStatusListener
listener
)
{
}
void
removeStatusListener
(
PerformanceStatusListener
listener
)
{
}
PerformanceStatus
get
status
=>
PerformanceStatus
.
dismissed
;
AnimationDirection
get
direction
=>
AnimationDirection
.
forward
;
AnimationDirection
get
curveDirection
=>
AnimationDirection
.
forward
;
double
get
progress
=>
0.0
;
}
const
AlwaysDismissedPerformance
alwaysDismissedPerformance
=
const
AlwaysDismissedPerformance
();
class
ReversePerformance
extends
PerformanceView
with
LazyListenerMixin
,
LocalPerformanceStatusListenersMixin
{
ReversePerformance
(
this
.
masterPerformance
);
final
PerformanceView
masterPerformance
;
void
updateVariable
(
Animatable
variable
)
{
variable
.
setProgress
(
progress
,
curveDirection
);
}
void
addListener
(
VoidCallback
listener
)
{
didRegisterListener
();
masterPerformance
.
addListener
(
listener
);
}
void
removeListener
(
VoidCallback
listener
)
{
masterPerformance
.
removeListener
(
listener
);
didUnregisterListener
();
}
void
didStartListening
()
{
masterPerformance
.
addStatusListener
(
_statusChangeHandler
);
}
void
didStopListening
()
{
masterPerformance
.
removeStatusListener
(
_statusChangeHandler
);
}
void
_statusChangeHandler
(
PerformanceStatus
status
)
{
notifyStatusListeners
(
_reverseStatus
(
status
));
}
PerformanceStatus
get
status
=>
_reverseStatus
(
masterPerformance
.
status
);
AnimationDirection
get
direction
=>
_reverseDirection
(
masterPerformance
.
direction
);
AnimationDirection
get
curveDirection
=>
_reverseDirection
(
masterPerformance
.
curveDirection
);
double
get
progress
=>
1.0
-
masterPerformance
.
progress
;
PerformanceStatus
_reverseStatus
(
PerformanceStatus
status
)
{
switch
(
status
)
{
case
PerformanceStatus
.
forward
:
return
PerformanceStatus
.
reverse
;
case
PerformanceStatus
.
reverse
:
return
PerformanceStatus
.
forward
;
case
PerformanceStatus
.
completed
:
return
PerformanceStatus
.
dismissed
;
case
PerformanceStatus
.
dismissed
:
return
PerformanceStatus
.
completed
;
}
}
AnimationDirection
_reverseDirection
(
AnimationDirection
direction
)
{
switch
(
direction
)
{
case
AnimationDirection
.
forward
:
return
AnimationDirection
.
reverse
;
case
AnimationDirection
.
reverse
:
return
AnimationDirection
.
forward
;
}
}
}
class
MeanPerformance
extends
PerformanceView
with
LazyListenerMixin
,
LocalPerformanceListenersMixin
,
LocalPerformanceStatusListenersMixin
{
MeanPerformance
(
this
.
_performances
)
{
assert
(
_performances
!=
null
);
}
// This list is intended to be immutable. Behavior is undefined if you mutate it.
final
List
<
PerformanceView
>
_performances
;
void
didStartListening
()
{
for
(
PerformanceView
performance
in
_performances
)
{
performance
.
addListener
(
notifyListeners
);
performance
.
addStatusListener
(
notifyStatusListeners
);
}
}
void
didStopListening
()
{
for
(
PerformanceView
performance
in
_performances
)
{
performance
.
removeListener
(
notifyListeners
);
performance
.
removeStatusListener
(
notifyStatusListeners
);
}
}
void
updateVariable
(
Animatable
variable
)
{
variable
.
setProgress
(
progress
,
curveDirection
);
}
PerformanceStatus
get
status
{
bool
dismissed
=
true
;
bool
completed
=
true
;
int
direction
=
0
;
for
(
PerformanceView
performance
in
_performances
)
{
switch
(
performance
.
status
)
{
case
PerformanceStatus
.
dismissed
:
completed
=
false
;
break
;
case
PerformanceStatus
.
completed
:
dismissed
=
false
;
break
;
case
PerformanceStatus
.
forward
:
dismissed
=
false
;
completed
=
false
;
direction
+=
1
;
break
;
case
PerformanceStatus
.
reverse
:
dismissed
=
false
;
completed
=
false
;
direction
-=
1
;
break
;
}
}
if
(
direction
>
1
)
return
PerformanceStatus
.
forward
;
if
(
direction
<
1
)
return
PerformanceStatus
.
reverse
;
if
(
dismissed
)
return
PerformanceStatus
.
dismissed
;
// all performances were dismissed, or we had none
if
(
completed
)
return
PerformanceStatus
.
completed
;
// all performances were completed
// Performances were conflicted.
// Either we had an equal non-zero number of forwards and reverse
// transitions, or we had both completed and dismissed transitions.
// We default to whatever our first performance was.
assert
(
_performances
.
isNotEmpty
);
return
_performances
[
0
].
status
;
}
AnimationDirection
get
direction
{
if
(
_performances
.
isEmpty
)
return
AnimationDirection
.
forward
;
int
direction
=
0
;
for
(
PerformanceView
performance
in
_performances
)
{
switch
(
performance
.
direction
)
{
case
AnimationDirection
.
forward
:
direction
+=
1
;
break
;
case
AnimationDirection
.
reverse
:
direction
-=
1
;
break
;
}
}
if
(
direction
>
1
)
return
AnimationDirection
.
forward
;
if
(
direction
<
1
)
return
AnimationDirection
.
reverse
;
// We had an equal (non-zero) number of forwards and reverse transitions.
// Default to the first one.
return
_performances
[
0
].
direction
;
}
AnimationDirection
get
curveDirection
{
if
(
_performances
.
isEmpty
)
return
AnimationDirection
.
forward
;
int
curveDirection
=
0
;
for
(
PerformanceView
performance
in
_performances
)
{
switch
(
performance
.
curveDirection
)
{
case
AnimationDirection
.
forward
:
curveDirection
+=
1
;
break
;
case
AnimationDirection
.
reverse
:
curveDirection
-=
1
;
break
;
}
}
if
(
curveDirection
>
1
)
return
AnimationDirection
.
forward
;
if
(
curveDirection
<
1
)
return
AnimationDirection
.
reverse
;
// We had an equal (non-zero) number of forwards and reverse transitions.
// Default to the first one.
return
_performances
[
0
].
curveDirection
;
}
double
get
progress
{
if
(
_performances
.
isEmpty
)
return
0.0
;
double
result
=
0.0
;
for
(
PerformanceView
performance
in
_performances
)
result
+=
performance
.
progress
;
return
result
/
_performances
.
length
;
}
}
enum
_TrainHoppingMode
{
minimize
,
maximize
}
/// This performance starts by proxying one performance, but can be given a
/// second performance. When their times cross (either because the second is
/// going in the opposite direction, or because the one overtakes the other),
/// the performance hops over to proxying the second performance, and the second
/// performance becomes the new "first" performance.
///
/// Since this object must track the two performances even when it has no
/// listeners of its own, instead of shutting down when all its listeners are
/// removed, it exposes a [dispose()] method. Call this method to shut this
/// object down.
class
TrainHoppingPerformance
extends
PerformanceView
with
EagerListenerMixin
,
LocalPerformanceListenersMixin
,
LocalPerformanceStatusListenersMixin
{
TrainHoppingPerformance
(
this
.
_currentTrain
,
this
.
_nextTrain
,
{
this
.
onSwitchedTrain
})
{
assert
(
_currentTrain
!=
null
);
if
(
_nextTrain
!=
null
)
{
if
(
_currentTrain
.
progress
>
_nextTrain
.
progress
)
{
_mode
=
_TrainHoppingMode
.
maximize
;
}
else
{
_mode
=
_TrainHoppingMode
.
minimize
;
if
(
_currentTrain
.
progress
==
_nextTrain
.
progress
)
{
_currentTrain
=
_nextTrain
;
_nextTrain
=
null
;
}
}
}
_currentTrain
.
addStatusListener
(
_statusChangeHandler
);
_currentTrain
.
addListener
(
_valueChangeHandler
);
if
(
_nextTrain
!=
null
)
_nextTrain
.
addListener
(
_valueChangeHandler
);
assert
(
_mode
!=
null
);
}
PerformanceView
get
currentTrain
=>
_currentTrain
;
PerformanceView
_currentTrain
;
PerformanceView
_nextTrain
;
_TrainHoppingMode
_mode
;
VoidCallback
onSwitchedTrain
;
void
updateVariable
(
Animatable
variable
)
{
assert
(
_currentTrain
!=
null
);
variable
.
setProgress
(
progress
,
curveDirection
);
}
PerformanceStatus
_lastStatus
;
void
_statusChangeHandler
(
PerformanceStatus
status
)
{
assert
(
_currentTrain
!=
null
);
if
(
status
!=
_lastStatus
)
{
notifyListeners
();
_lastStatus
=
status
;
}
assert
(
_lastStatus
!=
null
);
}
PerformanceStatus
get
status
=>
_currentTrain
.
status
;
AnimationDirection
get
direction
=>
_currentTrain
.
direction
;
AnimationDirection
get
curveDirection
=>
_currentTrain
.
curveDirection
;
double
_lastProgress
;
void
_valueChangeHandler
()
{
assert
(
_currentTrain
!=
null
);
bool
hop
=
false
;
if
(
_nextTrain
!=
null
)
{
switch
(
_mode
)
{
case
_TrainHoppingMode
.
minimize
:
hop
=
_nextTrain
.
progress
<=
_currentTrain
.
progress
;
break
;
case
_TrainHoppingMode
.
maximize
:
hop
=
_nextTrain
.
progress
>=
_currentTrain
.
progress
;
break
;
}
if
(
hop
)
{
_currentTrain
.
removeStatusListener
(
_statusChangeHandler
);
_currentTrain
.
removeListener
(
_valueChangeHandler
);
_currentTrain
=
_nextTrain
;
_nextTrain
.
addListener
(
_valueChangeHandler
);
_statusChangeHandler
(
_nextTrain
.
status
);
}
}
double
newProgress
=
progress
;
if
(
newProgress
!=
_lastProgress
)
{
notifyListeners
();
_lastProgress
=
newProgress
;
}
assert
(
_lastProgress
!=
null
);
if
(
hop
&&
onSwitchedTrain
!=
null
)
onSwitchedTrain
();
}
double
get
progress
=>
_currentTrain
.
progress
;
/// Frees all the resources used by this performance.
/// After this is called, this object is no longer usable.
void
dispose
()
{
assert
(
_currentTrain
!=
null
);
_currentTrain
.
removeStatusListener
(
_statusChangeHandler
);
_currentTrain
.
removeListener
(
_valueChangeHandler
);
_currentTrain
=
null
;
if
(
_nextTrain
!=
null
)
{
_nextTrain
.
removeListener
(
_valueChangeHandler
);
_nextTrain
=
null
;
}
}
}
class
ProxyPerformance
extends
PerformanceView
with
LazyListenerMixin
,
LocalPerformanceListenersMixin
,
LocalPerformanceStatusListenersMixin
{
ProxyPerformance
([
PerformanceView
performance
])
{
_masterPerformance
=
performance
;
if
(
_masterPerformance
==
null
)
{
_status
=
PerformanceStatus
.
dismissed
;
_direction
=
AnimationDirection
.
forward
;
_curveDirection
=
AnimationDirection
.
forward
;
_progress
=
0.0
;
}
}
PerformanceStatus
_status
;
AnimationDirection
_direction
;
AnimationDirection
_curveDirection
;
double
_progress
;
PerformanceView
get
masterPerformance
=>
_masterPerformance
;
PerformanceView
_masterPerformance
;
void
set
masterPerformance
(
PerformanceView
value
)
{
if
(
value
==
_masterPerformance
)
return
;
if
(
_masterPerformance
!=
null
)
{
_status
=
_masterPerformance
.
status
;
_direction
=
_masterPerformance
.
direction
;
_curveDirection
=
_masterPerformance
.
curveDirection
;
_progress
=
_masterPerformance
.
progress
;
if
(
isListening
)
didStopListening
();
}
_masterPerformance
=
value
;
if
(
_masterPerformance
!=
null
)
{
if
(
isListening
)
didStartListening
();
if
(
_progress
!=
_masterPerformance
.
progress
)
notifyListeners
();
if
(
_status
!=
_masterPerformance
.
status
)
notifyStatusListeners
(
_masterPerformance
.
status
);
_status
=
null
;
_direction
=
null
;
_curveDirection
=
null
;
_progress
=
null
;
}
}
void
didStartListening
()
{
if
(
_masterPerformance
!=
null
)
{
_masterPerformance
.
addListener
(
notifyListeners
);
_masterPerformance
.
addStatusListener
(
notifyStatusListeners
);
}
}
void
didStopListening
()
{
if
(
_masterPerformance
!=
null
)
{
_masterPerformance
.
removeListener
(
notifyListeners
);
_masterPerformance
.
removeStatusListener
(
notifyStatusListeners
);
}
}
void
updateVariable
(
Animatable
variable
)
{
variable
.
setProgress
(
progress
,
curveDirection
);
}
PerformanceStatus
get
status
=>
_masterPerformance
!=
null
?
_masterPerformance
.
status
:
_status
;
AnimationDirection
get
direction
=>
_masterPerformance
!=
null
?
_masterPerformance
.
direction
:
_direction
;
AnimationDirection
get
curveDirection
=>
_masterPerformance
!=
null
?
_masterPerformance
.
curveDirection
:
_curveDirection
;
double
get
progress
=>
_masterPerformance
!=
null
?
_masterPerformance
.
progress
:
_progress
;
}
class
CurvedPerformance
extends
PerformanceView
{
CurvedPerformance
(
this
.
_performance
,
{
this
.
curve
,
this
.
reverseCurve
});
final
PerformanceView
_performance
;
/// The curve to use in the forward direction
Curve
curve
;
/// The curve to use in the reverse direction
///
/// If this field is null, use [curve] in both directions.
Curve
reverseCurve
;
void
addListener
(
VoidCallback
listener
)
{
_performance
.
addListener
(
listener
);
}
void
removeListener
(
VoidCallback
listener
)
{
_performance
.
removeListener
(
listener
);
}
void
addStatusListener
(
PerformanceStatusListener
listener
)
{
_performance
.
addStatusListener
(
listener
);
}
void
removeStatusListener
(
PerformanceStatusListener
listener
)
{
_performance
.
removeStatusListener
(
listener
);
}
void
updateVariable
(
Animatable
variable
)
{
variable
.
setProgress
(
progress
,
curveDirection
);
}
PerformanceStatus
get
status
=>
_performance
.
status
;
AnimationDirection
get
direction
=>
_performance
.
direction
;
AnimationDirection
get
curveDirection
=>
_performance
.
curveDirection
;
double
get
progress
{
Curve
activeCurve
;
if
(
curveDirection
==
AnimationDirection
.
forward
||
reverseCurve
==
null
)
activeCurve
=
curve
;
else
activeCurve
=
reverseCurve
;
if
(
activeCurve
==
null
)
return
_performance
.
progress
;
if
(
_performance
.
status
==
PerformanceStatus
.
dismissed
)
{
assert
(
_performance
.
progress
==
0.0
);
assert
(
activeCurve
.
transform
(
0.0
).
roundToDouble
()
==
0.0
);
return
0.0
;
}
if
(
_performance
.
status
==
PerformanceStatus
.
completed
)
{
assert
(
_performance
.
progress
==
1.0
);
assert
(
activeCurve
.
transform
(
1.0
).
roundToDouble
()
==
1.0
);
return
1.0
;
}
return
activeCurve
.
transform
(
_performance
.
progress
);
}
}
/// A timeline that can be reversed and used to update [Animatable]s.
///
/// For example, a performance may handle an animation of a menu opening by
/// sliding and fading in (changing Y value and opacity) over .5 seconds. The
/// performance can move forwards (present) or backwards (dismiss). A consumer
/// may also take direct control of the timeline by manipulating [progress], or
/// [fling] the timeline causing a physics-based simulation to take over the
/// progression.
class
Performance
extends
PerformanceView
with
EagerListenerMixin
,
LocalPerformanceListenersMixin
,
LocalPerformanceStatusListenersMixin
{
Performance
({
this
.
duration
,
double
progress
,
this
.
debugLabel
})
{
_timeline
=
new
SimulationStepper
(
_tick
);
if
(
progress
!=
null
)
_timeline
.
value
=
progress
.
clamp
(
0.0
,
1.0
);
}
/// A label that is used in the [toString] output. Intended to aid with
/// identifying performance instances in debug output.
final
String
debugLabel
;
/// Returns a [PerformanceView] for this performance,
/// so that a pointer to this object can be passed around without
/// allowing users of that pointer to mutate the Performance state.
PerformanceView
get
view
=>
this
;
/// The length of time this performance should last.
Duration
duration
;
SimulationStepper
_timeline
;
AnimationDirection
get
direction
=>
_direction
;
AnimationDirection
_direction
=
AnimationDirection
.
forward
;
AnimationDirection
get
curveDirection
=>
_curveDirection
;
AnimationDirection
_curveDirection
=
AnimationDirection
.
forward
;
/// The progress of this performance along the timeline.
///
/// Note: Setting this value stops the current animation.
double
get
progress
=>
_timeline
.
value
.
clamp
(
0.0
,
1.0
);
void
set
progress
(
double
t
)
{
stop
();
_timeline
.
value
=
t
.
clamp
(
0.0
,
1.0
);
_checkStatusChanged
();
}
/// Whether this animation is currently animating in either the forward or reverse direction.
bool
get
isAnimating
=>
_timeline
.
isAnimating
;
PerformanceStatus
get
status
{
if
(!
isAnimating
&&
progress
==
1.0
)
return
PerformanceStatus
.
completed
;
if
(!
isAnimating
&&
progress
==
0.0
)
return
PerformanceStatus
.
dismissed
;
return
_direction
==
AnimationDirection
.
forward
?
PerformanceStatus
.
forward
:
PerformanceStatus
.
reverse
;
}
/// Updates the given variable according to the current progress of this performance.
void
updateVariable
(
Animatable
variable
)
{
variable
.
setProgress
(
progress
,
_curveDirection
);
}
/// Starts running this animation forwards (towards the end).
Future
forward
()
=>
play
(
AnimationDirection
.
forward
);
/// Starts running this animation in reverse (towards the beginning).
Future
reverse
()
=>
play
(
AnimationDirection
.
reverse
);
/// Starts running this animation in the given direction.
Future
play
([
AnimationDirection
direction
=
AnimationDirection
.
forward
])
{
_direction
=
direction
;
return
resume
();
}
/// Resumes this animation in the most recent direction.
Future
resume
()
{
return
_animateTo
(
_direction
==
AnimationDirection
.
forward
?
1.0
:
0.0
);
}
/// Stops running this animation.
void
stop
()
{
_timeline
.
stop
();
}
/// Releases any resources used by this object.
///
/// Same as stop().
void
dispose
()
{
stop
();
}
///
/// Flings the timeline with an optional force (defaults to a critically
/// damped spring) and initial velocity. If velocity is positive, the
/// animation will complete, otherwise it will dismiss.
Future
fling
({
double
velocity:
1.0
,
Force
force
})
{
force
??=
kDefaultSpringForce
;
_direction
=
velocity
<
0.0
?
AnimationDirection
.
reverse
:
AnimationDirection
.
forward
;
return
_timeline
.
animateWith
(
force
.
release
(
progress
,
velocity
));
}
/// Starts running this animation in the forward direction, and
/// restarts the animation when it completes.
Future
repeat
({
double
min:
0.0
,
double
max:
1.0
,
Duration
period
})
{
period
??=
duration
;
return
_timeline
.
animateWith
(
new
_RepeatingSimulation
(
min
,
max
,
period
));
}
PerformanceStatus
_lastStatus
=
PerformanceStatus
.
dismissed
;
void
_checkStatusChanged
()
{
PerformanceStatus
currentStatus
=
status
;
if
(
currentStatus
!=
_lastStatus
)
notifyStatusListeners
(
status
);
_lastStatus
=
currentStatus
;
}
void
_updateCurveDirection
()
{
if
(
status
!=
_lastStatus
)
{
if
(
_lastStatus
==
PerformanceStatus
.
dismissed
||
_lastStatus
==
PerformanceStatus
.
completed
)
_curveDirection
=
_direction
;
}
}
Future
_animateTo
(
double
target
)
{
Duration
remainingDuration
=
duration
*
(
target
-
_timeline
.
value
).
abs
();
_timeline
.
stop
();
if
(
remainingDuration
==
Duration
.
ZERO
)
return
new
Future
.
value
();
return
_timeline
.
animateTo
(
target
,
duration:
remainingDuration
);
}
void
_tick
(
double
t
)
{
_updateCurveDirection
();
didTick
(
t
);
}
void
didTick
(
double
t
)
{
notifyListeners
();
_checkStatusChanged
();
}
String
toStringDetails
()
{
String
paused
=
_timeline
.
isAnimating
?
''
:
'; paused'
;
String
label
=
debugLabel
==
null
?
''
:
'; for
$debugLabel
'
;
String
more
=
super
.
toStringDetails
();
return
'
$more$paused$label
'
;
}
}
/// An animation performance with an animated variable with a concrete type.
class
ValuePerformance
<
T
>
extends
Performance
{
ValuePerformance
({
this
.
variable
,
Duration
duration
,
double
progress
})
:
super
(
duration:
duration
,
progress:
progress
);
AnimatedValue
<
T
>
variable
;
T
get
value
=>
variable
.
value
;
void
didTick
(
double
t
)
{
if
(
variable
!=
null
)
variable
.
setProgress
(
progress
,
_curveDirection
);
super
.
didTick
(
t
);
}
}
class
_RepeatingSimulation
extends
Simulation
{
_RepeatingSimulation
(
this
.
min
,
this
.
max
,
Duration
period
)
:
_periodInSeconds
=
period
.
inMicroseconds
/
Duration
.
MICROSECONDS_PER_SECOND
{
assert
(
_periodInSeconds
>
0.0
);
}
final
double
min
;
final
double
max
;
final
double
_periodInSeconds
;
double
x
(
double
timeInSeconds
)
{
assert
(
timeInSeconds
>=
0.0
);
final
double
t
=
(
timeInSeconds
/
_periodInSeconds
)
%
1.0
;
return
lerpDouble
(
min
,
max
,
t
);
}
double
dx
(
double
timeInSeconds
)
=>
1.0
;
bool
isDone
(
double
timeInSeconds
)
=>
false
;
}
packages/flutter/lib/src/animation/simulation_stepper.dart
View file @
ecb72f97
...
...
@@ -5,31 +5,32 @@
import
'dart:async'
;
import
'package:newton/newton.dart'
;
import
'animated_value.dart'
;
import
'curves.dart'
;
import
'ticker.dart'
;
/// A simulation that varies from [begin] to [end] over [duration] using [curve].
///
/// This class is an adaptor between the Simulation interface and the
/// AnimatedValue interface.
/// A simulation that varies from begin to end over duration using curve.
class
_TweenSimulation
extends
Simulation
{
_TweenSimulation
(
double
begin
,
double
end
,
Duration
duration
,
Curve
curve
)
:
_durationInSeconds
=
duration
.
inMicroseconds
/
Duration
.
MICROSECONDS_PER_SECOND
,
_tween
=
new
AnimatedValue
<
double
>(
begin
,
end:
end
,
curve:
curve
)
{
_TweenSimulation
(
this
.
_begin
,
this
.
_end
,
Duration
duration
,
this
.
_curve
)
:
_durationInSeconds
=
duration
.
inMicroseconds
/
Duration
.
MICROSECONDS_PER_SECOND
{
assert
(
_durationInSeconds
>
0.0
);
assert
(
begin
!=
null
);
assert
(
end
!=
null
);
assert
(
_
begin
!=
null
);
assert
(
_
end
!=
null
);
}
final
double
_durationInSeconds
;
final
AnimatedValue
<
double
>
_tween
;
final
double
_begin
;
final
double
_end
;
final
Curve
_curve
;
double
x
(
double
timeInSeconds
)
{
assert
(
timeInSeconds
>=
0.0
);
final
double
t
=
(
timeInSeconds
/
_durationInSeconds
).
clamp
(
0.0
,
1.0
);
_tween
.
setProgress
(
t
,
AnimationDirection
.
forward
);
return
_tween
.
value
;
double
t
=
(
timeInSeconds
/
_durationInSeconds
).
clamp
(
0.0
,
1.0
);
if
(
t
==
0.0
)
return
_begin
;
else
if
(
t
==
1.0
)
return
_end
;
else
return
_begin
+
(
_end
-
_begin
)
*
_curve
.
transform
(
t
);
}
double
dx
(
double
timeInSeconds
)
=>
1.0
;
...
...
packages/flutter/lib/src/animation/tween.dart
View file @
ecb72f97
...
...
@@ -2,320 +2,50 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'dart:ui'
show
Color
,
Size
,
Rect
,
VoidCallback
,
lerpDouble
;
import
'package:newton/newton.dart'
;
import
'animated_value.dart'
;
import
'animation.dart'
;
import
'animations.dart'
;
import
'curves.dart'
;
import
'forces.dart'
;
import
'listener_helpers.dart'
;
import
'simulation_stepper.dart'
;
abstract
class
Animated
<
T
>
{
const
Animated
();
/// Calls the listener every time the value of the animation changes.
void
addListener
(
VoidCallback
listener
);
/// Stop calling the listener every time the value of the animation changes.
void
removeListener
(
VoidCallback
listener
);
/// Calls listener every time the status of the animation changes.
void
addStatusListener
(
PerformanceStatusListener
listener
);
/// Stops calling the listener every time the status of the animation changes.
void
removeStatusListener
(
PerformanceStatusListener
listener
);
/// The current status of this animation.
PerformanceStatus
get
status
;
/// The current direction of the animation.
AnimationDirection
get
direction
;
/// The current value of the animation.
T
get
value
;
abstract
class
Animatable
<
T
>
{
const
Animatable
()
;
/// Whether this animation is stopped at the beginning.
bool
get
isDismissed
=>
status
==
PerformanceStatus
.
dismissed
;
T
evaluate
(
Animation
<
double
>
animation
);
/// Whether this animation is stopped at the end.
bool
get
isCompleted
=>
status
==
PerformanceStatus
.
completed
;
String
toString
()
{
return
'
$runtimeType
(
${toStringDetails()}
)'
;
}
String
toStringDetails
()
{
assert
(
status
!=
null
);
assert
(
direction
!=
null
);
String
icon
;
switch
(
status
)
{
case
PerformanceStatus
.
forward
:
icon
=
'
\
u25B6'
;
// >
break
;
case
PerformanceStatus
.
reverse
:
icon
=
'
\
u25C0'
;
// <
break
;
case
PerformanceStatus
.
completed
:
switch
(
direction
)
{
case
AnimationDirection
.
forward
:
icon
=
'
\
u23ED'
;
// >>|
break
;
case
AnimationDirection
.
reverse
:
icon
=
'
\
u29CF'
;
// <|
break
;
}
break
;
case
PerformanceStatus
.
dismissed
:
switch
(
direction
)
{
case
AnimationDirection
.
forward
:
icon
=
'
\
u29D0'
;
// |>
break
;
case
AnimationDirection
.
reverse
:
icon
=
'
\
u23EE'
;
// |<<
break
;
}
break
;
}
assert
(
icon
!=
null
);
return
'
$icon
'
;
Animation
<
T
>
animate
(
Animation
<
double
>
parent
)
{
return
new
_AnimatedEvaluation
<
T
>(
parent
,
this
);
}
}
abstract
class
ProxyAnimatedMixin
{
Animated
<
double
>
get
parent
;
void
addListener
(
VoidCallback
listener
)
=>
parent
.
addListener
(
listener
);
void
removeListener
(
VoidCallback
listener
)
=>
parent
.
removeListener
(
listener
);
void
addStatusListener
(
PerformanceStatusListener
listener
)
=>
parent
.
addStatusListener
(
listener
);
void
removeStatusListener
(
PerformanceStatusListener
listener
)
=>
parent
.
removeStatusListener
(
listener
);
PerformanceStatus
get
status
=>
parent
.
status
;
AnimationDirection
get
direction
=>
parent
.
direction
;
}
abstract
class
Evaluatable
<
T
>
{
const
Evaluatable
();
T
evaluate
(
Animated
<
double
>
animation
);
Animated
<
T
>
animate
(
Animated
<
double
>
parent
)
{
return
new
_AnimatedEvaluation
<
T
>(
parent
,
this
);
Animatable
<
T
>
chain
(
Animatable
<
double
>
parent
)
{
return
new
_ChainedEvaluation
<
T
>(
parent
,
this
);
}
}
class
_AnimatedEvaluation
<
T
>
extends
Animat
ed
<
T
>
with
ProxyAnimatedMixin
{
class
_AnimatedEvaluation
<
T
>
extends
Animat
ion
<
T
>
with
ProxyAnimatedMixin
{
_AnimatedEvaluation
(
this
.
parent
,
this
.
_evaluatable
);
/// The animation from which this value is derived.
final
Animat
ed
<
double
>
parent
;
final
Animat
ion
<
double
>
parent
;
final
Evalu
atable
<
T
>
_evaluatable
;
final
Anim
atable
<
T
>
_evaluatable
;
T
get
value
=>
_evaluatable
.
evaluate
(
parent
);
}
class
AnimationController
extends
Animated
<
double
>
with
EagerListenerMixin
,
LocalPerformanceListenersMixin
,
LocalPerformanceStatusListenersMixin
{
AnimationController
({
this
.
duration
,
double
value
,
this
.
debugLabel
})
{
_timeline
=
new
SimulationStepper
(
_tick
);
if
(
value
!=
null
)
_timeline
.
value
=
value
.
clamp
(
0.0
,
1.0
);
}
/// A label that is used in the [toString] output. Intended to aid with
/// identifying animation controller instances in debug output.
final
String
debugLabel
;
class
_ChainedEvaluation
<
T
>
extends
Animatable
<
T
>
{
_ChainedEvaluation
(
this
.
_parent
,
this
.
_evaluatable
);
/// Returns a [Animated<double>] for this animation controller,
/// so that a pointer to this object can be passed around without
/// allowing users of that pointer to mutate the AnimationController state.
Animated
<
double
>
get
view
=>
this
;
final
Animatable
<
double
>
_parent
;
final
Animatable
<
T
>
_evaluatable
;
/// The length of time this animation should last.
Duration
duration
;
SimulationStepper
_timeline
;
AnimationDirection
get
direction
=>
_direction
;
AnimationDirection
_direction
=
AnimationDirection
.
forward
;
/// The progress of this animation along the timeline.
///
/// Note: Setting this value stops the current animation.
double
get
value
=>
_timeline
.
value
.
clamp
(
0.0
,
1.0
);
void
set
value
(
double
t
)
{
stop
();
_timeline
.
value
=
t
.
clamp
(
0.0
,
1.0
);
_checkStatusChanged
();
}
/// Whether this animation is currently animating in either the forward or reverse direction.
bool
get
isAnimating
=>
_timeline
.
isAnimating
;
PerformanceStatus
get
status
{
if
(!
isAnimating
&&
value
==
1.0
)
return
PerformanceStatus
.
completed
;
if
(!
isAnimating
&&
value
==
0.0
)
return
PerformanceStatus
.
dismissed
;
return
_direction
==
AnimationDirection
.
forward
?
PerformanceStatus
.
forward
:
PerformanceStatus
.
reverse
;
}
/// Starts running this animation forwards (towards the end).
Future
forward
()
=>
play
(
AnimationDirection
.
forward
);
/// Starts running this animation in reverse (towards the beginning).
Future
reverse
()
=>
play
(
AnimationDirection
.
reverse
);
/// Starts running this animation in the given direction.
Future
play
(
AnimationDirection
direction
)
{
_direction
=
direction
;
return
resume
();
}
/// Resumes this animation in the most recent direction.
Future
resume
()
{
return
_animateTo
(
_direction
==
AnimationDirection
.
forward
?
1.0
:
0.0
);
}
/// Stops running this animation.
void
stop
()
{
_timeline
.
stop
();
}
/// Releases any resources used by this object.
///
/// Same as stop().
void
dispose
()
{
stop
();
}
///
/// Flings the timeline with an optional force (defaults to a critically
/// damped spring) and initial velocity. If velocity is positive, the
/// animation will complete, otherwise it will dismiss.
Future
fling
({
double
velocity:
1.0
,
Force
force
})
{
force
??=
kDefaultSpringForce
;
_direction
=
velocity
<
0.0
?
AnimationDirection
.
reverse
:
AnimationDirection
.
forward
;
return
_timeline
.
animateWith
(
force
.
release
(
value
,
velocity
));
}
/// Starts running this animation in the forward direction, and
/// restarts the animation when it completes.
Future
repeat
({
double
min:
0.0
,
double
max:
1.0
,
Duration
period
})
{
period
??=
duration
;
return
_timeline
.
animateWith
(
new
_RepeatingSimulation
(
min
,
max
,
period
));
}
PerformanceStatus
_lastStatus
=
PerformanceStatus
.
dismissed
;
void
_checkStatusChanged
()
{
PerformanceStatus
currentStatus
=
status
;
if
(
currentStatus
!=
_lastStatus
)
notifyStatusListeners
(
status
);
_lastStatus
=
currentStatus
;
}
Future
_animateTo
(
double
target
)
{
Duration
remainingDuration
=
duration
*
(
target
-
_timeline
.
value
).
abs
();
_timeline
.
stop
();
if
(
remainingDuration
==
Duration
.
ZERO
)
return
new
Future
.
value
();
return
_timeline
.
animateTo
(
target
,
duration:
remainingDuration
);
}
void
_tick
(
double
t
)
{
notifyListeners
();
_checkStatusChanged
();
}
String
toStringDetails
()
{
String
paused
=
_timeline
.
isAnimating
?
''
:
'; paused'
;
String
label
=
debugLabel
==
null
?
''
:
'; for
$debugLabel
'
;
String
more
=
'
${super.toStringDetails()}
${value.toStringAsFixed(3)}
'
;
return
'
$more$paused$label
'
;
}
}
class
_RepeatingSimulation
extends
Simulation
{
_RepeatingSimulation
(
this
.
min
,
this
.
max
,
Duration
period
)
:
_periodInSeconds
=
period
.
inMicroseconds
/
Duration
.
MICROSECONDS_PER_SECOND
{
assert
(
_periodInSeconds
>
0.0
);
}
final
double
min
;
final
double
max
;
final
double
_periodInSeconds
;
double
x
(
double
timeInSeconds
)
{
assert
(
timeInSeconds
>=
0.0
);
final
double
t
=
(
timeInSeconds
/
_periodInSeconds
)
%
1.0
;
return
lerpDouble
(
min
,
max
,
t
);
}
double
dx
(
double
timeInSeconds
)
=>
1.0
;
bool
isDone
(
double
timeInSeconds
)
=>
false
;
}
class
CurvedAnimation
extends
Animated
<
double
>
with
ProxyAnimatedMixin
{
CurvedAnimation
({
this
.
parent
,
this
.
curve
:
Curves
.
linear
,
this
.
reverseCurve
})
{
assert
(
parent
!=
null
);
assert
(
curve
!=
null
);
parent
.
addStatusListener
(
_handleStatusChanged
);
}
final
Animated
<
double
>
parent
;
/// The curve to use in the forward direction.
Curve
curve
;
/// The curve to use in the reverse direction.
///
/// If this field is null, uses [curve] in both directions.
Curve
reverseCurve
;
/// The direction used to select the current curve.
///
/// The curve direction is only reset when we hit the beginning or the end of
/// the timeline to avoid discontinuities in the value of any variables this
/// a animation is used to animate.
AnimationDirection
_curveDirection
;
void
_handleStatusChanged
(
PerformanceStatus
status
)
{
switch
(
status
)
{
case
PerformanceStatus
.
dismissed
:
case
PerformanceStatus
.
completed
:
_curveDirection
=
null
;
break
;
case
PerformanceStatus
.
forward
:
_curveDirection
??=
AnimationDirection
.
forward
;
break
;
case
PerformanceStatus
.
reverse
:
_curveDirection
??=
AnimationDirection
.
reverse
;
break
;
}
}
double
get
value
{
final
bool
useForwardCurve
=
reverseCurve
==
null
||
(
_curveDirection
??
parent
.
direction
)
==
AnimationDirection
.
forward
;
Curve
activeCurve
=
useForwardCurve
?
curve
:
reverseCurve
;
double
t
=
parent
.
value
;
if
(
activeCurve
==
null
)
return
t
;
if
(
t
==
0.0
||
t
==
1.0
)
{
assert
(
activeCurve
.
transform
(
t
).
round
()
==
t
);
return
t
;
}
return
activeCurve
.
transform
(
t
);
T
evaluate
(
Animation
<
double
>
animation
)
{
double
value
=
_parent
.
evaluate
(
animation
);
return
_evaluatable
.
evaluate
(
new
AlwaysStoppedAnimation
(
value
));
}
}
class
Tween
<
T
extends
dynamic
>
extends
Evalu
atable
<
T
>
{
class
Tween
<
T
extends
dynamic
>
extends
Anim
atable
<
T
>
{
Tween
({
this
.
begin
,
this
.
end
});
/// The value this variable has at the beginning of the animation.
...
...
@@ -327,7 +57,7 @@ class Tween<T extends dynamic> extends Evaluatable<T> {
/// Returns the value this variable has at the given animation clock value.
T
lerp
(
double
t
)
=>
begin
+
(
end
-
begin
)
*
t
;
T
evaluate
(
Animat
ed
<
double
>
animation
)
{
T
evaluate
(
Animat
ion
<
double
>
animation
)
{
if
(
end
==
null
)
return
begin
;
double
t
=
animation
.
value
;
...
...
@@ -378,12 +108,12 @@ class IntTween extends Tween<int> {
int
lerp
(
double
t
)
=>
(
begin
+
(
end
-
begin
)
*
t
).
round
();
}
class
CurveTween
extends
Evalu
atable
<
double
>
{
class
CurveTween
extends
Anim
atable
<
double
>
{
CurveTween
({
this
.
curve
});
Curve
curve
;
double
evaluate
(
Animat
ed
<
double
>
animation
)
{
double
evaluate
(
Animat
ion
<
double
>
animation
)
{
double
t
=
animation
.
value
;
if
(
t
==
0.0
||
t
==
1.0
)
{
assert
(
curve
.
transform
(
t
).
round
()
==
t
);
...
...
packages/flutter/lib/src/material/bottom_sheet.dart
View file @
ecb72f97
...
...
@@ -167,7 +167,7 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
return
BottomSheet
.
createAnimationController
();
}
Widget
buildPage
(
BuildContext
context
,
Animat
ed
<
double
>
animation
,
Animated
<
double
>
forwardAnimation
)
{
Widget
buildPage
(
BuildContext
context
,
Animat
ion
<
double
>
animation
,
Animation
<
double
>
forwardAnimation
)
{
return
new
_ModalBottomSheet
(
route:
this
);
}
}
...
...
packages/flutter/lib/src/material/dialog.dart
View file @
ecb72f97
...
...
@@ -128,11 +128,11 @@ class _DialogRoute<T> extends PopupRoute<T> {
bool
get
barrierDismissable
=>
true
;
Color
get
barrierColor
=>
Colors
.
black54
;
Widget
buildPage
(
BuildContext
context
,
Animat
ed
<
double
>
animation
,
Animated
<
double
>
forwardAnimation
)
{
Widget
buildPage
(
BuildContext
context
,
Animat
ion
<
double
>
animation
,
Animation
<
double
>
forwardAnimation
)
{
return
child
;
}
Widget
buildTransitions
(
BuildContext
context
,
Animat
ed
<
double
>
animation
,
Animated
<
double
>
forwardAnimation
,
Widget
child
)
{
Widget
buildTransitions
(
BuildContext
context
,
Animat
ion
<
double
>
animation
,
Animation
<
double
>
forwardAnimation
,
Widget
child
)
{
return
new
FadeTransition
(
opacity:
new
CurvedAnimation
(
parent:
animation
,
...
...
packages/flutter/lib/src/material/drawer.dart
View file @
ecb72f97
...
...
@@ -92,18 +92,18 @@ class DrawerControllerState extends State<DrawerController> {
}
}
void
_animationStatusChanged
(
Performance
Status
status
)
{
void
_animationStatusChanged
(
Animation
Status
status
)
{
switch
(
status
)
{
case
Performance
Status
.
forward
:
case
Animation
Status
.
forward
:
_ensureHistoryEntry
();
break
;
case
Performance
Status
.
reverse
:
case
Animation
Status
.
reverse
:
_historyEntry
?.
remove
();
_historyEntry
=
null
;
break
;
case
Performance
Status
.
dismissed
:
case
Animation
Status
.
dismissed
:
break
;
case
Performance
Status
.
completed
:
case
Animation
Status
.
completed
:
break
;
}
}
...
...
@@ -155,7 +155,7 @@ class DrawerControllerState extends State<DrawerController> {
final
GlobalKey
_gestureDetectorKey
=
new
GlobalKey
();
Widget
build
(
BuildContext
context
)
{
if
(
_controller
.
status
==
Performance
Status
.
dismissed
)
{
if
(
_controller
.
status
==
Animation
Status
.
dismissed
)
{
return
new
Align
(
alignment:
const
FractionalOffset
(
0.0
,
0.5
),
child:
new
GestureDetector
(
...
...
packages/flutter/lib/src/material/dropdown.dart
View file @
ecb72f97
...
...
@@ -193,7 +193,7 @@ class _DropDownRoute<T> extends PopupRoute<_DropDownRouteResult<T>> {
);
}
Widget
buildPage
(
BuildContext
context
,
Animat
ed
<
double
>
animation
,
Animated
<
double
>
forwardAnimation
)
{
Widget
buildPage
(
BuildContext
context
,
Animat
ion
<
double
>
animation
,
Animation
<
double
>
forwardAnimation
)
{
return
new
_DropDownMenu
(
route:
this
);
}
}
...
...
packages/flutter/lib/src/material/floating_action_button.dart
View file @
ecb72f97
...
...
@@ -40,7 +40,7 @@ class FloatingActionButton extends StatefulComponent {
}
class
_FloatingActionButtonState
extends
State
<
FloatingActionButton
>
{
Animat
ed
<
double
>
_childSegue
;
Animat
ion
<
double
>
_childSegue
;
AnimationController
_childSegueController
;
void
initState
()
{
...
...
packages/flutter/lib/src/material/material.dart
View file @
ecb72f97
...
...
@@ -367,10 +367,10 @@ class _InkSplash extends InkFeature implements InkSplash {
final
bool
clipToReferenceBox
;
final
bool
repositionToReferenceBox
;
Animat
ed
<
double
>
_radius
;
Animat
ion
<
double
>
_radius
;
AnimationController
_radiusController
;
Animat
ed
<
int
>
_alpha
;
Animat
ion
<
int
>
_alpha
;
AnimationController
_alphaController
;
void
confirm
()
{
...
...
@@ -385,8 +385,8 @@ class _InkSplash extends InkFeature implements InkSplash {
_alphaController
.
forward
();
}
void
_handleAlphaStatusChanged
(
Performance
Status
status
)
{
if
(
status
==
Performance
Status
.
completed
)
void
_handleAlphaStatusChanged
(
Animation
Status
status
)
{
if
(
status
==
Animation
Status
.
completed
)
dispose
();
}
...
...
@@ -456,7 +456,7 @@ class _InkHighlight extends InkFeature implements InkHighlight {
bool
get
active
=>
_active
;
bool
_active
=
true
;
Animat
ed
<
int
>
_alpha
;
Animat
ion
<
int
>
_alpha
;
AnimationController
_alphaController
;
void
activate
()
{
...
...
@@ -469,8 +469,8 @@ class _InkHighlight extends InkFeature implements InkHighlight {
_alphaController
.
reverse
();
}
void
_handleAlphaStatusChanged
(
Performance
Status
status
)
{
if
(
status
==
Performance
Status
.
dismissed
&&
!
_active
)
void
_handleAlphaStatusChanged
(
Animation
Status
status
)
{
if
(
status
==
Animation
Status
.
dismissed
&&
!
_active
)
dispose
();
}
...
...
packages/flutter/lib/src/material/page.dart
View file @
ecb72f97
...
...
@@ -10,7 +10,7 @@ import 'package:flutter/widgets.dart';
class
_MaterialPageTransition
extends
AnimatedComponent
{
_MaterialPageTransition
({
Key
key
,
Animat
ed
<
double
>
animation
,
Animat
ion
<
double
>
animation
,
this
.
child
})
:
super
(
key:
key
,
...
...
@@ -57,7 +57,7 @@ class MaterialPageRoute<T> extends PageRoute<T> {
Color
get
barrierColor
=>
null
;
bool
canTransitionFrom
(
TransitionRoute
nextRoute
)
=>
false
;
Widget
buildPage
(
BuildContext
context
,
Animat
ed
<
double
>
animation
,
Animated
<
double
>
forwardAnimation
)
{
Widget
buildPage
(
BuildContext
context
,
Animat
ion
<
double
>
animation
,
Animation
<
double
>
forwardAnimation
)
{
Widget
result
=
builder
(
context
);
assert
(()
{
if
(
result
==
null
)
...
...
@@ -68,7 +68,7 @@ class MaterialPageRoute<T> extends PageRoute<T> {
return
result
;
}
Widget
buildTransitions
(
BuildContext
context
,
Animat
ed
<
double
>
animation
,
Animated
<
double
>
forwardAnimation
,
Widget
child
)
{
Widget
buildTransitions
(
BuildContext
context
,
Animat
ion
<
double
>
animation
,
Animation
<
double
>
forwardAnimation
,
Widget
child
)
{
return
new
_MaterialPageTransition
(
animation:
animation
,
child:
child
...
...
packages/flutter/lib/src/material/popup_menu.dart
View file @
ecb72f97
...
...
@@ -132,7 +132,7 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
return
position
;
}
Animat
ed
<
double
>
createAnimation
()
{
Animat
ion
<
double
>
createAnimation
()
{
return
new
CurvedAnimation
(
parent:
super
.
createAnimation
(),
reverseCurve:
new
Interval
(
0.0
,
_kMenuCloseIntervalEnd
)
...
...
@@ -143,7 +143,7 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
bool
get
barrierDismissable
=>
true
;
Color
get
barrierColor
=>
null
;
Widget
buildPage
(
BuildContext
context
,
Animat
ed
<
double
>
animation
,
Animated
<
double
>
forwardAnimation
)
{
Widget
buildPage
(
BuildContext
context
,
Animat
ion
<
double
>
animation
,
Animation
<
double
>
forwardAnimation
)
{
return
new
_PopupMenu
(
route:
this
);
}
}
...
...
packages/flutter/lib/src/material/progress_indicator.dart
View file @
ecb72f97
...
...
@@ -38,15 +38,15 @@ abstract class ProgressIndicator extends StatefulComponent {
}
class
_ProgressIndicatorState
extends
State
<
ProgressIndicator
>
{
Animat
ed
<
double
>
_animation
;
Animat
ion
<
double
>
_animation
;
AnimationController
_controller
;
void
initState
()
{
super
.
initState
();
_controller
=
new
AnimationController
(
duration:
const
Duration
(
milliseconds:
1500
)
)..
addStatusListener
((
Performance
Status
status
)
{
if
(
status
==
Performance
Status
.
completed
)
)..
addStatusListener
((
Animation
Status
status
)
{
if
(
status
==
Animation
Status
.
completed
)
_restartAnimation
();
})..
forward
();
_animation
=
new
CurvedAnimation
(
parent:
_controller
,
curve:
Curves
.
ease
);
...
...
packages/flutter/lib/src/material/scaffold.dart
View file @
ecb72f97
...
...
@@ -227,9 +227,9 @@ class ScaffoldState extends State<Scaffold> {
return
controller
;
}
void
_handleSnackBarStatusChange
(
Performance
Status
status
)
{
void
_handleSnackBarStatusChange
(
Animation
Status
status
)
{
switch
(
status
)
{
case
Performance
Status
.
dismissed
:
case
Animation
Status
.
dismissed
:
assert
(
_snackBars
.
isNotEmpty
);
setState
(()
{
_snackBars
.
removeFirst
();
...
...
@@ -237,21 +237,21 @@ class ScaffoldState extends State<Scaffold> {
if
(
_snackBars
.
isNotEmpty
)
_snackBarController
.
forward
();
break
;
case
Performance
Status
.
completed
:
case
Animation
Status
.
completed
:
setState
(()
{
assert
(
_snackBarTimer
==
null
);
// build will create a new timer if necessary to dismiss the snack bar
});
break
;
case
Performance
Status
.
forward
:
case
Performance
Status
.
reverse
:
case
Animation
Status
.
forward
:
case
Animation
Status
.
reverse
:
break
;
}
}
void
_hideSnackBar
()
{
assert
(
_snackBarController
.
status
==
Performance
Status
.
forward
||
_snackBarController
.
status
==
Performance
Status
.
completed
);
assert
(
_snackBarController
.
status
==
Animation
Status
.
forward
||
_snackBarController
.
status
==
Animation
Status
.
completed
);
_snackBars
.
first
.
_completer
.
complete
();
_snackBarController
.
reverse
();
_snackBarTimer
=
null
;
...
...
@@ -449,7 +449,7 @@ class _PersistentBottomSheetState extends State<_PersistentBottomSheet> {
void
initState
()
{
super
.
initState
();
assert
(
config
.
animationController
.
status
==
Performance
Status
.
forward
);
assert
(
config
.
animationController
.
status
==
Animation
Status
.
forward
);
config
.
animationController
.
addStatusListener
(
_handleStatusChange
);
}
...
...
@@ -467,8 +467,8 @@ class _PersistentBottomSheetState extends State<_PersistentBottomSheet> {
config
.
animationController
.
reverse
();
}
void
_handleStatusChange
(
Performance
Status
status
)
{
if
(
status
==
Performance
Status
.
dismissed
&&
config
.
onDismissed
!=
null
)
void
_handleStatusChange
(
Animation
Status
status
)
{
if
(
status
==
Animation
Status
.
dismissed
&&
config
.
onDismissed
!=
null
)
config
.
onDismissed
();
}
...
...
packages/flutter/lib/src/material/slider.dart
View file @
ecb72f97
...
...
@@ -123,7 +123,7 @@ class _RenderSlider extends RenderConstrainedBox {
double
get
_trackLength
=>
size
.
width
-
2.0
*
_kReactionRadius
;
Animat
ed
<
double
>
_reaction
;
Animat
ion
<
double
>
_reaction
;
AnimationController
_reactionController
;
HorizontalDragGestureRecognizer
_drag
;
...
...
@@ -186,7 +186,7 @@ class _RenderSlider extends RenderConstrainedBox {
canvas
.
drawRect
(
new
Rect
.
fromLTRB
(
trackLeft
,
trackTop
,
trackActive
,
trackBottom
),
primaryPaint
);
Point
activeLocation
=
new
Point
(
trackActive
,
trackCenter
);
if
(
_reaction
.
status
!=
Performance
Status
.
dismissed
)
{
if
(
_reaction
.
status
!=
Animation
Status
.
dismissed
)
{
Paint
reactionPaint
=
new
Paint
()..
color
=
_activeColor
.
withAlpha
(
kRadialReactionAlpha
);
canvas
.
drawCircle
(
activeLocation
,
_reaction
.
value
,
reactionPaint
);
}
...
...
packages/flutter/lib/src/material/snack_bar.dart
View file @
ecb72f97
...
...
@@ -65,7 +65,7 @@ class SnackBar extends StatelessComponent {
final
Widget
content
;
final
List
<
SnackBarAction
>
actions
;
final
Duration
duration
;
final
Animat
ed
<
double
>
animation
;
final
Animat
ion
<
double
>
animation
;
Widget
build
(
BuildContext
context
)
{
assert
(
animation
!=
null
);
...
...
@@ -130,7 +130,7 @@ class SnackBar extends StatelessComponent {
);
}
SnackBar
withAnimation
(
Animat
ed
<
double
>
newAnimation
,
{
Key
fallbackKey
})
{
SnackBar
withAnimation
(
Animat
ion
<
double
>
newAnimation
,
{
Key
fallbackKey
})
{
return
new
SnackBar
(
key:
key
??
fallbackKey
,
content:
content
,
...
...
packages/flutter/lib/src/material/tabs.dart
View file @
ecb72f97
...
...
@@ -382,7 +382,7 @@ class _TabsScrollBehavior extends BoundedBehavior {
}
abstract
class
TabBarSelectionPerformanceListener
{
void
handleStatusChange
(
Performance
Status
status
);
void
handleStatusChange
(
Animation
Status
status
);
void
handleProgressChange
();
void
handleSelectionDeactivate
();
}
...
...
@@ -415,7 +415,7 @@ class TabBarSelection<T> extends StatefulComponent {
class
TabBarSelectionState
<
T
>
extends
State
<
TabBarSelection
<
T
>>
{
Animat
ed
<
double
>
get
animation
=>
_controller
.
view
;
Animat
ion
<
double
>
get
animation
=>
_controller
.
view
;
// Both the TabBar and TabBarView classes access _controller because they
// alternately drive selection progress between tabs.
final
AnimationController
_controller
=
new
AnimationController
(
duration:
_kTabBarScroll
,
value:
1.0
);
...
...
@@ -481,7 +481,7 @@ class TabBarSelectionState<T> extends State<TabBarSelection<T>> {
// the previous and current selection index.
double
value
;
if
(
_controller
.
status
==
Performance
Status
.
completed
)
if
(
_controller
.
status
==
Animation
Status
.
completed
)
value
=
0.0
;
else
if
(
_previousValue
==
values
.
first
)
value
=
_controller
.
value
;
...
...
@@ -584,11 +584,11 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
_selection
=
null
;
}
void
handleStatusChange
(
Performance
Status
status
)
{
void
handleStatusChange
(
Animation
Status
status
)
{
if
(
config
.
labels
.
length
==
0
)
return
;
if
(
_valueIsChanging
&&
status
==
Performance
Status
.
completed
)
{
if
(
_valueIsChanging
&&
status
==
Animation
Status
.
completed
)
{
_valueIsChanging
=
false
;
_indicatorTween
..
begin
=
_tabIndicatorRect
(
math
.
max
(
0
,
_selection
.
index
-
1
))
...
...
@@ -868,7 +868,7 @@ class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSe
_updateScrollBehaviorForSelectedIndex
(
selectedIndex
);
}
void
handleStatusChange
(
Performance
Status
status
)
{
void
handleStatusChange
(
Animation
Status
status
)
{
}
void
handleProgressChange
()
{
...
...
@@ -876,14 +876,14 @@ class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSe
return
;
// The TabBar is driving the TabBarSelection performance.
final
Animat
ed
<
double
>
animation
=
_selection
.
animation
;
final
Animat
ion
<
double
>
animation
=
_selection
.
animation
;
if
(
animation
.
status
==
Performance
Status
.
completed
)
{
if
(
animation
.
status
==
Animation
Status
.
completed
)
{
_updateItemsAndScrollBehavior
();
return
;
}
if
(
animation
.
status
!=
Performance
Status
.
forward
)
if
(
animation
.
status
!=
Animation
Status
.
forward
)
return
;
final
int
selectedIndex
=
_selection
.
index
;
...
...
packages/flutter/lib/src/material/time_picker.dart
View file @
ecb72f97
...
...
@@ -350,7 +350,7 @@ class _DialState extends State<_Dial> {
}
Tween
<
double
>
_thetaTween
;
Animat
ed
<
double
>
_theta
;
Animat
ion
<
double
>
_theta
;
AnimationController
_thetaController
;
bool
_dragging
=
false
;
...
...
packages/flutter/lib/src/material/toggleable.dart
View file @
ecb72f97
...
...
@@ -99,15 +99,15 @@ abstract class RenderToggleable extends RenderConstrainedBox {
AnimationController
get
reactionController
=>
_reactionController
;
AnimationController
_reactionController
;
Animat
ed
<
double
>
_reaction
;
Animat
ion
<
double
>
_reaction
;
TapGestureRecognizer
_tap
;
void
_handlePositionStateChanged
(
Performance
Status
status
)
{
void
_handlePositionStateChanged
(
Animation
Status
status
)
{
if
(
isInteractive
)
{
if
(
status
==
Performance
Status
.
completed
&&
!
_value
)
if
(
status
==
Animation
Status
.
completed
&&
!
_value
)
onChanged
(
true
);
else
if
(
status
==
Performance
Status
.
dismissed
&&
_value
)
else
if
(
status
==
Animation
Status
.
dismissed
&&
_value
)
onChanged
(
false
);
}
}
...
...
packages/flutter/lib/src/material/tooltip.dart
View file @
ecb72f97
...
...
@@ -78,14 +78,14 @@ class _TooltipState extends State<Tooltip> {
void
initState
()
{
super
.
initState
();
_controller
=
new
AnimationController
(
duration:
config
.
fadeDuration
)
..
addStatusListener
((
Performance
Status
status
)
{
..
addStatusListener
((
Animation
Status
status
)
{
switch
(
status
)
{
case
Performance
Status
.
completed
:
case
Animation
Status
.
completed
:
assert
(
_entry
!=
null
);
assert
(
_timer
==
null
);
resetShowTimer
();
break
;
case
Performance
Status
.
dismissed
:
case
Animation
Status
.
dismissed
:
assert
(
_entry
!=
null
);
assert
(
_timer
==
null
);
_entry
.
remove
();
...
...
@@ -117,7 +117,7 @@ class _TooltipState extends State<Tooltip> {
}
void
resetShowTimer
()
{
assert
(
_controller
.
status
==
Performance
Status
.
completed
);
assert
(
_controller
.
status
==
Animation
Status
.
completed
);
assert
(
_entry
!=
null
);
_timer
=
new
Timer
(
config
.
showDuration
,
hideTooltip
);
}
...
...
@@ -149,7 +149,7 @@ class _TooltipState extends State<Tooltip> {
Overlay
.
of
(
context
).
insert
(
_entry
);
}
_timer
?.
cancel
();
if
(
_controller
.
status
!=
Performance
Status
.
completed
)
{
if
(
_controller
.
status
!=
Animation
Status
.
completed
)
{
_timer
=
null
;
_controller
.
forward
();
}
else
{
...
...
@@ -249,7 +249,7 @@ class _TooltipOverlay extends StatelessComponent {
final
double
borderRadius
;
final
double
height
;
final
EdgeDims
padding
;
final
Animat
ed
<
double
>
animation
;
final
Animat
ion
<
double
>
animation
;
final
Point
target
;
final
double
verticalOffset
;
final
EdgeDims
screenEdgeMargin
;
...
...
packages/flutter/lib/src/rendering/box.dart
View file @
ecb72f97
...
...
@@ -854,9 +854,8 @@ abstract class RenderBoxContainerDefaultsMixin<ChildType extends RenderBox, Pare
}
}
class
AnimatedFractionalOffsetValue
extends
AnimatedValue
<
FractionalOffset
>
{
AnimatedFractionalOffsetValue
(
FractionalOffset
begin
,
{
FractionalOffset
end
,
Curve
curve
,
Curve
reverseCurve
})
:
super
(
begin
,
end:
end
,
curve:
curve
,
reverseCurve:
reverseCurve
);
class
FractionalOffsetTween
extends
Tween
<
FractionalOffset
>
{
FractionalOffsetTween
({
FractionalOffset
begin
,
FractionalOffset
end
})
:
super
(
begin:
begin
,
end:
end
);
FractionalOffset
lerp
(
double
t
)
=>
FractionalOffset
.
lerp
(
begin
,
end
,
t
);
}
packages/flutter/lib/src/widgets/dismissable.dart
View file @
ecb72f97
...
...
@@ -73,8 +73,8 @@ class _DismissableState extends State<Dismissable> {
void
initState
()
{
super
.
initState
();
_dismissController
=
new
AnimationController
(
duration:
_kCardDismissDuration
);
_dismissController
.
addStatusListener
((
Performance
Status
status
)
{
if
(
status
==
Performance
Status
.
completed
)
_dismissController
.
addStatusListener
((
Animation
Status
status
)
{
if
(
status
==
Animation
Status
.
completed
)
_handleDismissCompleted
();
});
}
...
...
@@ -251,9 +251,9 @@ class _DismissableState extends State<Dismissable> {
Widget
build
(
BuildContext
context
)
{
if
(
_resizeController
!=
null
)
{
// make sure you remove this widget once it's been dismissed!
assert
(
_resizeController
.
status
==
Performance
Status
.
forward
);
assert
(
_resizeController
.
status
==
Animation
Status
.
forward
);
Animat
ed
<
double
>
squashAxisExtent
=
new
Tween
<
double
>(
Animat
ion
<
double
>
squashAxisExtent
=
new
Tween
<
double
>(
begin:
_directionIsYAxis
?
_size
.
width
:
_size
.
height
,
end:
0.0
).
animate
(
new
CurvedAnimation
(
...
...
packages/flutter/lib/src/widgets/enter_exit_transition.dart
View file @
ecb72f97
...
...
@@ -30,32 +30,41 @@ class SmoothlyResizingOverflowBox extends StatefulComponent {
}
class
_SmoothlyResizingOverflowBoxState
extends
State
<
SmoothlyResizingOverflowBox
>
{
ValuePerformance
<
Size
>
_size
;
SizeTween
_sizeTween
;
CurveTween
_curveTween
;
Animation
<
Size
>
_size
;
AnimationController
_sizeController
;
void
initState
()
{
super
.
initState
();
_size
=
new
ValuePerformance
(
variable:
new
AnimatedSizeValue
(
config
.
size
,
curve:
config
.
curve
),
duration:
config
.
duration
)..
addListener
(()
{
setState
(()
{});
});
_sizeController
=
new
AnimationController
(
duration:
config
.
duration
);
_sizeTween
=
new
SizeTween
(
begin:
config
.
size
);
_curveTween
=
new
CurveTween
(
curve:
config
.
curve
);
_size
=
_sizeTween
.
chain
(
_curveTween
).
animate
(
_sizeController
)
..
addListener
(()
{
setState
(()
{});
});
}
void
didUpdateConfig
(
SmoothlyResizingOverflowBox
oldConfig
)
{
_size
.
duration
=
config
.
duration
;
_size
.
variable
.
curve
=
config
.
curve
;
bool
needsAnimation
=
false
;
if
(
config
.
size
!=
oldConfig
.
size
)
{
AnimatedSizeValue
variable
=
_size
.
variable
;
variable
.
begin
=
variable
.
value
;
variable
.
end
=
config
.
size
;
_size
.
progress
=
0.0
;
_size
.
play
();
_sizeTween
..
begin
=
_size
.
value
..
end
=
config
.
size
;
needsAnimation
=
true
;
}
_sizeController
.
duration
=
config
.
duration
;
_curveTween
.
curve
=
config
.
curve
;
if
(
needsAnimation
)
{
_sizeController
..
value
=
0.0
..
forward
();
}
}
void
dispose
()
{
_size
.
stop
();
_size
Controller
.
stop
();
super
.
dispose
();
}
...
...
@@ -91,9 +100,9 @@ class _Entry {
}
}
typedef
Widget
TransitionBuilderCallback
(
Animat
ed
<
double
>
animation
,
Widget
child
);
typedef
Widget
TransitionBuilderCallback
(
Animat
ion
<
double
>
animation
,
Widget
child
);
Widget
_identityTransition
(
Animat
ed
<
double
>
animation
,
Widget
child
)
=>
child
;
Widget
_identityTransition
(
Animat
ion
<
double
>
animation
,
Widget
child
)
=>
child
;
class
EnterExitTransition
extends
StatefulComponent
{
EnterExitTransition
({
...
...
packages/flutter/lib/src/widgets/heroes.dart
View file @
ecb72f97
...
...
@@ -73,7 +73,7 @@ class _HeroManifest {
abstract
class
HeroHandle
{
bool
get
alwaysAnimate
;
_HeroManifest
_takeChild
(
Rect
animationArea
,
Animat
ed
<
double
>
currentAnimation
);
_HeroManifest
_takeChild
(
Rect
animationArea
,
Animat
ion
<
double
>
currentAnimation
);
}
class
Hero
extends
StatefulComponent
{
...
...
@@ -167,7 +167,7 @@ class HeroState extends State<Hero> implements HeroHandle {
bool
get
alwaysAnimate
=>
config
.
alwaysAnimate
;
_HeroManifest
_takeChild
(
Rect
animationArea
,
Animat
ed
<
double
>
currentAnimation
)
{
_HeroManifest
_takeChild
(
Rect
animationArea
,
Animat
ion
<
double
>
currentAnimation
)
{
assert
(
_mode
==
_HeroMode
.
measured
||
_mode
==
_HeroMode
.
taken
);
final
RenderBox
renderObject
=
context
.
findRenderObject
();
final
Point
heroTopLeft
=
renderObject
.
localToGlobal
(
Point
.
origin
);
...
...
@@ -263,7 +263,7 @@ class _HeroQuestState implements HeroHandle {
bool
get
taken
=>
_taken
;
bool
_taken
=
false
;
_HeroManifest
_takeChild
(
Rect
animationArea
,
Animat
ed
<
double
>
currentAnimation
)
{
_HeroManifest
_takeChild
(
Rect
animationArea
,
Animat
ion
<
double
>
currentAnimation
)
{
assert
(!
taken
);
_taken
=
true
;
Set
<
HeroState
>
states
=
sourceStates
;
...
...
@@ -278,7 +278,7 @@ class _HeroQuestState implements HeroHandle {
);
}
Widget
build
(
BuildContext
context
,
Animat
ed
<
double
>
animation
)
{
Widget
build
(
BuildContext
context
,
Animat
ion
<
double
>
animation
)
{
return
new
PositionedTransition
(
rect:
currentRect
.
animate
(
animation
),
child:
new
RotationTransition
(
...
...
@@ -376,14 +376,14 @@ class HeroParty {
_heroes
=
_newHeroes
;
}
Animat
ed
<
double
>
_currentAnimation
;
Animat
ion
<
double
>
_currentAnimation
;
void
_clearCurrentAnimation
()
{
_currentAnimation
?.
removeStatusListener
(
_handleUpdate
);
_currentAnimation
=
null
;
}
void
setAnimation
(
Animat
ed
<
double
>
animation
)
{
void
setAnimation
(
Animat
ion
<
double
>
animation
)
{
assert
(
animation
!=
null
||
_heroes
.
length
==
0
);
if
(
animation
!=
_currentAnimation
)
{
_clearCurrentAnimation
();
...
...
@@ -392,9 +392,9 @@ class HeroParty {
}
}
void
_handleUpdate
(
Performance
Status
status
)
{
if
(
status
==
Performance
Status
.
completed
||
status
==
Performance
Status
.
dismissed
)
{
void
_handleUpdate
(
Animation
Status
status
)
{
if
(
status
==
Animation
Status
.
completed
||
status
==
Animation
Status
.
dismissed
)
{
for
(
_HeroQuestState
hero
in
_heroes
)
{
if
(
hero
.
targetState
!=
null
)
hero
.
targetState
.
_setChild
(
hero
.
key
);
...
...
@@ -417,7 +417,7 @@ class HeroController extends NavigatorObserver {
}
HeroParty
_party
;
Animat
ed
<
double
>
_animation
;
Animat
ion
<
double
>
_animation
;
PageRoute
_from
;
PageRoute
_to
;
...
...
@@ -452,7 +452,7 @@ class HeroController extends NavigatorObserver {
void
_checkForHeroQuest
()
{
if
(
_from
!=
null
&&
_to
!=
null
&&
_from
!=
_to
)
{
_to
.
offstage
=
_to
.
animation
.
status
!=
Performance
Status
.
completed
;
_to
.
offstage
=
_to
.
animation
.
status
!=
Animation
Status
.
completed
;
Scheduler
.
instance
.
addPostFrameCallback
(
_updateQuest
);
}
}
...
...
@@ -505,9 +505,9 @@ class HeroController extends NavigatorObserver {
Map
<
Object
,
HeroHandle
>
heroesTo
=
Hero
.
of
(
_to
.
subtreeContext
,
mostValuableKeys
);
_to
.
offstage
=
false
;
Animat
ed
<
double
>
animation
=
_animation
;
Animat
ion
<
double
>
animation
=
_animation
;
Curve
curve
=
Curves
.
ease
;
if
(
animation
.
status
==
Performance
Status
.
reverse
)
{
if
(
animation
.
status
==
Animation
Status
.
reverse
)
{
animation
=
new
ReverseAnimation
(
animation
);
curve
=
new
Interval
(
animation
.
value
,
1.0
,
curve:
curve
);
}
...
...
packages/flutter/lib/src/widgets/implicit_animations.dart
View file @
ecb72f97
...
...
@@ -84,8 +84,8 @@ typedef Tween<T> TweenVisitor<T>(Tween<T> tween, T targetValue, TweenConstructor
abstract
class
AnimatedWidgetBaseState
<
T
extends
AnimatedWidgetBase
>
extends
State
<
T
>
{
AnimationController
_controller
;
Animat
ed
<
double
>
get
animation
=>
_animation
;
Animat
ed
<
double
>
_animation
;
Animat
ion
<
double
>
get
animation
=>
_animation
;
Animat
ion
<
double
>
_animation
;
void
initState
()
{
super
.
initState
();
...
...
packages/flutter/lib/src/widgets/modal_barrier.dart
View file @
ecb72f97
...
...
@@ -46,12 +46,12 @@ class ModalBarrier extends StatelessComponent {
class
AnimatedModalBarrier
extends
AnimatedComponent
{
AnimatedModalBarrier
({
Key
key
,
Animat
ed
<
Color
>
color
,
Animat
ion
<
Color
>
color
,
this
.
dismissable
:
true
})
:
color
=
color
,
super
(
key:
key
,
animation:
color
);
/// If non-null, fill the barrier with this color.
final
Animat
ed
<
Color
>
color
;
final
Animat
ion
<
Color
>
color
;
/// Whether touching the barrier will pop the current route off the [Navigator].
final
bool
dismissable
;
...
...
packages/flutter/lib/src/widgets/routes.dart
View file @
ecb72f97
...
...
@@ -92,8 +92,8 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
Duration
get
transitionDuration
;
bool
get
opaque
;
Animat
ed
<
double
>
get
animation
=>
_animation
;
Animat
ed
<
double
>
_animation
;
Animat
ion
<
double
>
get
animation
=>
_animation
;
Animat
ion
<
double
>
_animation
;
AnimationController
_controller
;
/// Called to create the animation controller that will drive the transitions to
...
...
@@ -108,25 +108,25 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
/// Called to create the animation that exposes the current progress of
/// the transition controlled by the animation controller created by
/// [createAnimationController()].
Animat
ed
<
double
>
createAnimation
()
{
Animat
ion
<
double
>
createAnimation
()
{
assert
(
_controller
!=
null
);
return
_controller
.
view
;
}
T
_result
;
void
handleStatusChanged
(
Performance
Status
status
)
{
void
handleStatusChanged
(
Animation
Status
status
)
{
switch
(
status
)
{
case
Performance
Status
.
completed
:
case
Animation
Status
.
completed
:
if
(
overlayEntries
.
isNotEmpty
)
overlayEntries
.
first
.
opaque
=
opaque
;
break
;
case
Performance
Status
.
forward
:
case
Performance
Status
.
reverse
:
case
Animation
Status
.
forward
:
case
Animation
Status
.
reverse
:
if
(
overlayEntries
.
isNotEmpty
)
overlayEntries
.
first
.
opaque
=
false
;
break
;
case
Performance
Status
.
dismissed
:
case
Animation
Status
.
dismissed
:
assert
(!
overlayEntries
.
first
.
opaque
);
finished
();
// clear the overlays
assert
(
overlayEntries
.
isEmpty
);
...
...
@@ -134,7 +134,7 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
}
}
Animat
ed
<
double
>
get
forwardAnimation
=>
_forwardAnimation
;
Animat
ion
<
double
>
get
forwardAnimation
=>
_forwardAnimation
;
final
ProxyAnimation
_forwardAnimation
=
new
ProxyAnimation
(
kAlwaysDismissedAnimation
);
void
install
(
OverlayEntry
insertionPoint
)
{
...
...
@@ -177,7 +177,7 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
void
_updateForwardAnimation
(
Route
nextRoute
)
{
if
(
nextRoute
is
TransitionRoute
&&
canTransitionTo
(
nextRoute
)
&&
nextRoute
.
canTransitionFrom
(
this
))
{
Animat
ed
<
double
>
current
=
_forwardAnimation
.
masterAnimation
;
Animat
ion
<
double
>
current
=
_forwardAnimation
.
masterAnimation
;
if
(
current
!=
null
)
{
if
(
current
is
TrainHoppingAnimation
)
{
TrainHoppingAnimation
newAnimation
;
...
...
@@ -320,7 +320,7 @@ class _ModalScopeState extends State<_ModalScope> {
super
.
dispose
();
}
void
_animationStatusChanged
(
Performance
Status
status
)
{
void
_animationStatusChanged
(
Animation
Status
status
)
{
setState
(()
{
// The animation's states are our build state, and they changed already.
});
...
...
@@ -342,7 +342,7 @@ class _ModalScopeState extends State<_ModalScope> {
contents
=
new
Focus
(
key:
new
GlobalObjectKey
(
config
.
route
),
child:
new
IgnorePointer
(
ignoring:
config
.
route
.
animation
?.
status
==
Performance
Status
.
reverse
,
ignoring:
config
.
route
.
animation
?.
status
==
Animation
Status
.
reverse
,
child:
config
.
route
.
buildTransitions
(
context
,
config
.
route
.
animation
,
...
...
@@ -396,8 +396,8 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
// The API for subclasses to override - used by _ModalScope
ModalPosition
getPosition
(
BuildContext
context
)
=>
null
;
Widget
buildPage
(
BuildContext
context
,
Animat
ed
<
double
>
animation
,
Animated
<
double
>
forwardAnimation
);
Widget
buildTransitions
(
BuildContext
context
,
Animat
ed
<
double
>
animation
,
Animated
<
double
>
forwardAnimation
,
Widget
child
)
{
Widget
buildPage
(
BuildContext
context
,
Animat
ion
<
double
>
animation
,
Animation
<
double
>
forwardAnimation
);
Widget
buildTransitions
(
BuildContext
context
,
Animat
ion
<
double
>
animation
,
Animation
<
double
>
forwardAnimation
,
Widget
child
)
{
return
child
;
}
...
...
@@ -442,7 +442,7 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
Widget
barrier
;
if
(
barrierColor
!=
null
)
{
assert
(
barrierColor
!=
_kTransparent
);
Animat
ed
<
Color
>
color
=
new
ColorTween
(
Animat
ion
<
Color
>
color
=
new
ColorTween
(
begin:
_kTransparent
,
end:
barrierColor
).
animate
(
new
CurvedAnimation
(
...
...
@@ -456,9 +456,9 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
}
else
{
barrier
=
new
ModalBarrier
(
dismissable:
barrierDismissable
);
}
assert
(
animation
.
status
!=
Performance
Status
.
dismissed
);
assert
(
animation
.
status
!=
Animation
Status
.
dismissed
);
return
new
IgnorePointer
(
ignoring:
animation
.
status
==
Performance
Status
.
reverse
,
ignoring:
animation
.
status
==
Animation
Status
.
reverse
,
child:
barrier
);
}
...
...
packages/flutter/lib/src/widgets/status_transitions.dart
View file @
ecb72f97
...
...
@@ -14,7 +14,7 @@ abstract class StatusTransitionComponent extends StatefulComponent {
assert
(
animation
!=
null
);
}
final
Animat
ed
<
double
>
animation
;
final
Animat
ion
<
double
>
animation
;
Widget
build
(
BuildContext
context
);
...
...
@@ -39,7 +39,7 @@ class _StatusTransitionState extends State<StatusTransitionComponent> {
super
.
dispose
();
}
void
_animationStatusChanged
(
Performance
Status
status
)
{
void
_animationStatusChanged
(
Animation
Status
status
)
{
setState
(()
{
// The animation's state is our build state, and it changed already.
});
...
...
packages/flutter/lib/src/widgets/transitions.dart
View file @
ecb72f97
...
...
@@ -14,55 +14,6 @@ import 'framework.dart';
export
'package:flutter/animation.dart'
show
AnimationDirection
;
export
'package:flutter/rendering.dart'
show
RelativeRect
;
abstract
class
TransitionComponent
extends
StatefulComponent
{
TransitionComponent
({
Key
key
,
this
.
performance
})
:
super
(
key:
key
)
{
assert
(
performance
!=
null
);
}
final
PerformanceView
performance
;
Widget
build
(
BuildContext
context
);
_TransitionState
createState
()
=>
new
_TransitionState
();
void
debugFillDescription
(
List
<
String
>
description
)
{
super
.
debugFillDescription
(
description
);
description
.
add
(
'performance:
$performance
'
);
}
}
class
_TransitionState
extends
State
<
TransitionComponent
>
{
void
initState
()
{
super
.
initState
();
config
.
performance
.
addListener
(
_performanceChanged
);
}
void
didUpdateConfig
(
TransitionComponent
oldConfig
)
{
if
(
config
.
performance
!=
oldConfig
.
performance
)
{
oldConfig
.
performance
.
removeListener
(
_performanceChanged
);
config
.
performance
.
addListener
(
_performanceChanged
);
}
}
void
dispose
()
{
config
.
performance
.
removeListener
(
_performanceChanged
);
super
.
dispose
();
}
void
_performanceChanged
()
{
setState
(()
{
// The performance's state is our build state, and it changed already.
});
}
Widget
build
(
BuildContext
context
)
{
return
config
.
build
(
context
);
}
}
abstract
class
AnimatedComponent
extends
StatefulComponent
{
AnimatedComponent
({
Key
key
,
...
...
@@ -71,7 +22,7 @@ abstract class AnimatedComponent extends StatefulComponent {
assert
(
animation
!=
null
);
}
final
Animat
ed
<
Object
>
animation
;
final
Animat
ion
<
Object
>
animation
;
Widget
build
(
BuildContext
context
);
...
...
@@ -112,30 +63,15 @@ class _AnimatedComponentState extends State<AnimatedComponent> {
}
}
abstract
class
TransitionWithChild
extends
TransitionComponent
{
TransitionWithChild
({
Key
key
,
this
.
child
,
PerformanceView
performance
})
:
super
(
key:
key
,
performance:
performance
);
final
Widget
child
;
Widget
build
(
BuildContext
context
)
=>
buildWithChild
(
context
,
child
);
Widget
buildWithChild
(
BuildContext
context
,
Widget
child
);
}
class
SlideTransition
extends
AnimatedComponent
{
SlideTransition
({
Key
key
,
Animated
<
FractionalOffset
>
position
,
PerformanceView
performance
,
Animation
<
FractionalOffset
>
position
,
this
.
transformHitTests
:
true
,
this
.
child
})
:
position
=
position
,
super
(
key:
key
,
animation:
position
);
final
Animat
ed
<
FractionalOffset
>
position
;
final
Animat
ion
<
FractionalOffset
>
position
;
final
bool
transformHitTests
;
final
Widget
child
;
...
...
@@ -151,12 +87,12 @@ class SlideTransition extends AnimatedComponent {
class
ScaleTransition
extends
AnimatedComponent
{
ScaleTransition
({
Key
key
,
Animat
ed
<
double
>
scale
,
Animat
ion
<
double
>
scale
,
this
.
alignment
:
const
FractionalOffset
(
0.5
,
0.5
),
this
.
child
})
:
scale
=
scale
,
super
(
key:
key
,
animation:
scale
);
final
Animat
ed
<
double
>
scale
;
final
Animat
ion
<
double
>
scale
;
final
FractionalOffset
alignment
;
final
Widget
child
;
...
...
@@ -175,11 +111,11 @@ class ScaleTransition extends AnimatedComponent {
class
RotationTransition
extends
AnimatedComponent
{
RotationTransition
({
Key
key
,
Animat
ed
<
double
>
turns
,
Animat
ion
<
double
>
turns
,
this
.
child
})
:
turns
=
turns
,
super
(
key:
key
,
animation:
turns
);
final
Animat
ed
<
double
>
turns
;
final
Animat
ion
<
double
>
turns
;
final
Widget
child
;
Widget
build
(
BuildContext
context
)
{
...
...
@@ -193,32 +129,14 @@ class RotationTransition extends AnimatedComponent {
}
}
class
OldFadeTransition
extends
TransitionWithChild
{
OldFadeTransition
({
Key
key
,
this
.
opacity
,
PerformanceView
performance
,
Widget
child
})
:
super
(
key:
key
,
performance:
performance
,
child:
child
);
final
AnimatedValue
<
double
>
opacity
;
Widget
buildWithChild
(
BuildContext
context
,
Widget
child
)
{
performance
.
updateVariable
(
opacity
);
return
new
Opacity
(
opacity:
opacity
.
value
,
child:
child
);
}
}
class
FadeTransition
extends
AnimatedComponent
{
FadeTransition
({
Key
key
,
Animat
ed
<
double
>
opacity
,
Animat
ion
<
double
>
opacity
,
this
.
child
})
:
opacity
=
opacity
,
super
(
key:
key
,
animation:
opacity
);
final
Animat
ed
<
double
>
opacity
;
final
Animat
ion
<
double
>
opacity
;
final
Widget
child
;
Widget
build
(
BuildContext
context
)
{
...
...
@@ -226,20 +144,17 @@ class FadeTransition extends AnimatedComponent {
}
}
class
ColorTransition
extends
TransitionWithChild
{
class
ColorTransition
extends
AnimatedComponent
{
ColorTransition
({
Key
key
,
this
.
color
,
PerformanceView
performance
,
Widget
child
})
:
super
(
key:
key
,
performance:
performance
,
child:
child
);
Animation
<
Color
>
color
,
this
.
child
})
:
color
=
color
,
super
(
key:
key
,
animation:
color
);
final
AnimatedColorValue
color
;
final
Animation
<
Color
>
color
;
final
Widget
child
;
Widget
buildWithChild
(
BuildContext
context
,
Widget
child
)
{
performance
.
updateVariable
(
color
);
Widget
build
(
BuildContext
context
)
{
return
new
DecoratedBox
(
decoration:
new
BoxDecoration
(
backgroundColor:
color
.
value
),
child:
child
...
...
@@ -247,61 +162,6 @@ class ColorTransition extends TransitionWithChild {
}
}
class
SquashTransition
extends
TransitionWithChild
{
SquashTransition
({
Key
key
,
this
.
width
,
this
.
height
,
PerformanceView
performance
,
Widget
child
})
:
super
(
key:
key
,
performance:
performance
,
child:
child
);
final
AnimatedValue
<
double
>
width
;
final
AnimatedValue
<
double
>
height
;
Widget
buildWithChild
(
BuildContext
context
,
Widget
child
)
{
if
(
width
!=
null
)
performance
.
updateVariable
(
width
);
if
(
height
!=
null
)
performance
.
updateVariable
(
height
);
return
new
SizedBox
(
width:
width
?.
value
,
height:
height
?.
value
,
child:
child
);
}
}
class
AlignTransition
extends
TransitionWithChild
{
AlignTransition
({
Key
key
,
this
.
alignment
,
this
.
widthFactor
,
this
.
heightFactor
,
PerformanceView
performance
,
Widget
child
})
:
super
(
key:
key
,
performance:
performance
,
child:
child
);
final
AnimatedValue
<
FractionalOffset
>
alignment
;
final
AnimatedValue
<
double
>
widthFactor
;
final
AnimatedValue
<
double
>
heightFactor
;
Widget
buildWithChild
(
BuildContext
context
,
Widget
child
)
{
if
(
alignment
!=
null
)
performance
.
updateVariable
(
alignment
);
if
(
widthFactor
!=
null
)
performance
.
updateVariable
(
widthFactor
);
if
(
heightFactor
!=
null
)
performance
.
updateVariable
(
heightFactor
);
return
new
Align
(
alignment:
alignment
?.
value
,
widthFactor:
widthFactor
?.
value
,
heightFactor:
heightFactor
?.
value
,
child:
child
);
}
}
/// An animated variable containing a RelativeRectangle
///
/// This class specializes the interpolation of AnimatedValue<RelativeRect> to
...
...
@@ -323,13 +183,13 @@ class RelativeRectTween extends Tween<RelativeRect> {
class
PositionedTransition
extends
AnimatedComponent
{
PositionedTransition
({
Key
key
,
Animat
ed
<
RelativeRect
>
rect
,
Animat
ion
<
RelativeRect
>
rect
,
this
.
child
})
:
rect
=
rect
,
super
(
key:
key
,
animation:
rect
)
{
assert
(
rect
!=
null
);
}
final
Animat
ed
<
RelativeRect
>
rect
;
final
Animat
ion
<
RelativeRect
>
rect
;
final
Widget
child
;
Widget
build
(
BuildContext
context
)
{
...
...
@@ -343,31 +203,12 @@ class PositionedTransition extends AnimatedComponent {
}
}
class
BuilderTransition
extends
TransitionComponent
{
BuilderTransition
({
Key
key
,
this
.
variables
:
const
<
AnimatedValue
>[],
this
.
builder
,
PerformanceView
performance
})
:
super
(
key:
key
,
performance:
performance
);
final
List
<
AnimatedValue
>
variables
;
final
WidgetBuilder
builder
;
Widget
build
(
BuildContext
context
)
{
for
(
int
i
=
0
;
i
<
variables
.
length
;
++
i
)
performance
.
updateVariable
(
variables
[
i
]);
return
builder
(
context
);
}
}
typedef
Widget
TransitionBuilder
(
BuildContext
context
,
Widget
child
);
class
AnimatedBuilder
extends
AnimatedComponent
{
AnimatedBuilder
({
Key
key
,
Animat
ed
<
Object
>
animation
,
Animat
ion
<
Object
>
animation
,
this
.
builder
,
this
.
child
})
:
super
(
key:
key
,
animation:
animation
);
...
...
packages/flutter/test/widget/page_forward_transitions_test.dart
View file @
ecb72f97
...
...
@@ -12,7 +12,7 @@ class TestTransition extends AnimatedComponent {
Key
key
,
this
.
childFirstHalf
,
this
.
childSecondHalf
,
Animat
ed
<
double
>
animation
Animat
ion
<
double
>
animation
})
:
super
(
key:
key
,
animation:
animation
)
{
assert
(
animation
!=
null
);
}
...
...
@@ -21,7 +21,7 @@ class TestTransition extends AnimatedComponent {
final
Widget
childSecondHalf
;
Widget
build
(
BuildContext
context
)
{
final
Animat
ed
<
double
>
animation
=
this
.
animation
;
final
Animat
ion
<
double
>
animation
=
this
.
animation
;
if
(
animation
.
value
>=
0.5
)
return
childSecondHalf
;
return
childFirstHalf
;
...
...
@@ -33,7 +33,7 @@ class TestRoute<T> extends PageRoute<T> {
final
Widget
child
;
Duration
get
transitionDuration
=>
kMaterialPageRouteTransitionDuration
;
Color
get
barrierColor
=>
null
;
Widget
buildPage
(
BuildContext
context
,
Animat
ed
<
double
>
animation
,
Animated
<
double
>
forwardAnimation
)
{
Widget
buildPage
(
BuildContext
context
,
Animat
ion
<
double
>
animation
,
Animation
<
double
>
forwardAnimation
)
{
return
child
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment