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
aabd1ce4
Commit
aabd1ce4
authored
Jan 20, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1317 from abarth/port_widgets
Port most of widgets to AnimationController
parents
e4940a01
24872f69
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
203 additions
and
211 deletions
+203
-211
theme.dart
packages/flutter/lib/src/material/theme.dart
+7
-8
dismissable.dart
packages/flutter/lib/src/widgets/dismissable.dart
+50
-46
heroes.dart
packages/flutter/lib/src/widgets/heroes.dart
+3
-3
implicit_animations.dart
packages/flutter/lib/src/widgets/implicit_animations.dart
+101
-111
mimic.dart
packages/flutter/lib/src/widgets/mimic.dart
+9
-12
routes.dart
packages/flutter/lib/src/widgets/routes.dart
+14
-14
status_transitions.dart
packages/flutter/lib/src/widgets/status_transitions.dart
+6
-6
transitions.dart
packages/flutter/lib/src/widgets/transitions.dart
+13
-11
No files found.
packages/flutter/lib/src/material/theme.dart
View file @
aabd1ce4
...
...
@@ -41,10 +41,9 @@ class Theme extends InheritedWidget {
}
}
/// An animated value that interpolates [BoxConstraint]s.
class
AnimatedThemeDataValue
extends
AnimatedValue
<
ThemeData
>
{
AnimatedThemeDataValue
(
ThemeData
begin
,
{
ThemeData
end
,
Curve
curve
,
Curve
reverseCurve
})
:
super
(
begin
,
end:
end
,
curve:
curve
,
reverseCurve:
reverseCurve
);
/// An animated value that interpolates [ThemeData]s.
class
ThemeDataTween
extends
Tween
<
ThemeData
>
{
ThemeDataTween
({
ThemeData
begin
,
ThemeData
end
})
:
super
(
begin:
begin
,
end:
end
);
ThemeData
lerp
(
double
t
)
=>
ThemeData
.
lerp
(
begin
,
end
,
t
);
}
...
...
@@ -71,18 +70,18 @@ class AnimatedTheme extends AnimatedWidgetBase {
}
class
_AnimatedThemeState
extends
AnimatedWidgetBaseState
<
AnimatedTheme
>
{
AnimatedThemeDataValue
_data
;
ThemeDataTween
_data
;
void
forEach
Variable
(
Variable
Visitor
visitor
)
{
void
forEach
Tween
(
Tween
Visitor
visitor
)
{
// TODO(ianh): Use constructor tear-offs when it becomes possible
_data
=
visitor
(
_data
,
config
.
data
,
(
dynamic
value
)
=>
new
AnimatedThemeDataValue
(
value
));
_data
=
visitor
(
_data
,
config
.
data
,
(
dynamic
value
)
=>
new
ThemeDataTween
(
begin:
value
));
assert
(
_data
!=
null
);
}
Widget
build
(
BuildContext
context
)
{
return
new
Theme
(
child:
config
.
child
,
data:
_data
.
value
data:
_data
.
evaluate
(
animation
)
);
}
...
...
packages/flutter/lib/src/widgets/dismissable.dart
View file @
aabd1ce4
...
...
@@ -72,23 +72,23 @@ class Dismissable extends StatefulComponent {
class
_DismissableState
extends
State
<
Dismissable
>
{
void
initState
()
{
super
.
initState
();
_dismiss
Performance
=
new
Performance
(
duration:
_kCardDismissDuration
);
_dismiss
Performance
.
addStatusListener
((
PerformanceStatus
status
)
{
_dismiss
Controller
=
new
AnimationController
(
duration:
_kCardDismissDuration
);
_dismiss
Controller
.
addStatusListener
((
PerformanceStatus
status
)
{
if
(
status
==
PerformanceStatus
.
completed
)
_handleDismissCompleted
();
});
}
Performance
_dismissPerformance
;
Performance
_resizePerformance
;
AnimationController
_dismissController
;
AnimationController
_resizeController
;
Size
_size
;
double
_dragExtent
=
0.0
;
bool
_dragUnderway
=
false
;
void
dispose
()
{
_dismiss
Performance
?.
stop
();
_resize
Performance
?.
stop
();
_dismiss
Controller
?.
stop
();
_resize
Controller
?.
stop
();
super
.
dispose
();
}
...
...
@@ -101,11 +101,11 @@ class _DismissableState extends State<Dismissable> {
void
_handleDismissCompleted
()
{
if
(!
_dragUnderway
)
_startResize
Performance
();
_startResize
Animation
();
}
bool
get
_isActive
{
return
_size
!=
null
&&
(
_dragUnderway
||
_dismiss
Performance
.
isAnimating
);
return
_size
!=
null
&&
(
_dragUnderway
||
_dismiss
Controller
.
isAnimating
);
}
void
_maybeCallOnResized
()
{
...
...
@@ -118,21 +118,20 @@ class _DismissableState extends State<Dismissable> {
config
.
onDismissed
();
}
void
_startResize
Performance
()
{
void
_startResize
Animation
()
{
assert
(
_size
!=
null
);
assert
(
_dismiss
Performance
!=
null
);
assert
(
_dismiss
Performance
.
isCompleted
);
assert
(
_resize
Performance
==
null
);
assert
(
_dismiss
Controller
!=
null
);
assert
(
_dismiss
Controller
.
isCompleted
);
assert
(
_resize
Controller
==
null
);
setState
(()
{
_resizePerformance
=
new
Performance
()
..
duration
=
_kCardResizeDuration
_resizeController
=
new
AnimationController
(
duration:
_kCardResizeDuration
)
..
addListener
(
_handleResizeProgressChanged
);
_resize
Performance
.
play
();
_resize
Controller
.
forward
();
});
}
void
_handleResizeProgressChanged
()
{
if
(
_resize
Performance
.
isCompleted
)
if
(
_resize
Controller
.
isCompleted
)
_maybeCallOnDismissed
();
else
_maybeCallOnResized
();
...
...
@@ -141,18 +140,18 @@ class _DismissableState extends State<Dismissable> {
void
_handleDragStart
(
_
)
{
setState
(()
{
_dragUnderway
=
true
;
if
(
_dismiss
Performance
.
isAnimating
)
{
_dragExtent
=
_dismiss
Performance
.
progress
*
_size
.
width
*
_dragExtent
.
sign
;
_dismiss
Performance
.
stop
();
if
(
_dismiss
Controller
.
isAnimating
)
{
_dragExtent
=
_dismiss
Controller
.
value
*
_size
.
width
*
_dragExtent
.
sign
;
_dismiss
Controller
.
stop
();
}
else
{
_dragExtent
=
0.0
;
_dismiss
Performance
.
progress
=
0.0
;
_dismiss
Controller
.
value
=
0.0
;
}
});
}
void
_handleDragUpdate
(
double
delta
)
{
if
(!
_isActive
||
_dismiss
Performance
.
isAnimating
)
if
(!
_isActive
||
_dismiss
Controller
.
isAnimating
)
return
;
double
oldDragExtent
=
_dragExtent
;
...
...
@@ -180,11 +179,11 @@ class _DismissableState extends State<Dismissable> {
// Rebuild to update the new drag endpoint.
// The sign of _dragExtent is part of our build state;
// the actual value is not, it's just used to configure
// the
performance
s.
// the
animation
s.
});
}
if
(!
_dismiss
Performance
.
isAnimating
)
_dismiss
Performance
.
progress
=
_dragExtent
.
abs
()
/
_size
.
width
;
if
(!
_dismiss
Controller
.
isAnimating
)
_dismiss
Controller
.
value
=
_dragExtent
.
abs
()
/
_size
.
width
;
}
bool
_isFlingGesture
(
ui
.
Offset
velocity
)
{
...
...
@@ -217,20 +216,20 @@ class _DismissableState extends State<Dismissable> {
}
void
_handleDragEnd
(
ui
.
Offset
velocity
)
{
if
(!
_isActive
||
_dismiss
Performance
.
isAnimating
)
if
(!
_isActive
||
_dismiss
Controller
.
isAnimating
)
return
;
setState
(()
{
_dragUnderway
=
false
;
if
(
_dismiss
Performance
.
isCompleted
)
{
_startResize
Performance
();
if
(
_dismiss
Controller
.
isCompleted
)
{
_startResize
Animation
();
}
else
if
(
_isFlingGesture
(
velocity
))
{
double
flingVelocity
=
_directionIsYAxis
?
velocity
.
dy
:
velocity
.
dx
;
_dragExtent
=
flingVelocity
.
sign
;
_dismiss
Performance
.
fling
(
velocity:
flingVelocity
.
abs
()
*
_kFlingVelocityScale
);
}
else
if
(
_dismiss
Performance
.
progress
>
_kDismissCardThreshold
)
{
_dismiss
Performance
.
forward
();
_dismiss
Controller
.
fling
(
velocity:
flingVelocity
.
abs
()
*
_kFlingVelocityScale
);
}
else
if
(
_dismiss
Controller
.
value
>
_kDismissCardThreshold
)
{
_dismiss
Controller
.
forward
();
}
else
{
_dismiss
Performance
.
reverse
();
_dismiss
Controller
.
reverse
();
}
});
}
...
...
@@ -250,20 +249,26 @@ class _DismissableState extends State<Dismissable> {
}
Widget
build
(
BuildContext
context
)
{
if
(
_resize
Performance
!=
null
)
{
if
(
_resize
Controller
!=
null
)
{
// make sure you remove this widget once it's been dismissed!
assert
(
_resize
Performance
.
status
==
PerformanceStatus
.
forward
);
assert
(
_resize
Controller
.
status
==
PerformanceStatus
.
forward
);
AnimatedValue
<
double
>
squashAxisExtent
=
new
AnimatedValue
<
double
>(
_directionIsYAxis
?
_size
.
width
:
_size
.
height
,
end:
0.0
,
Animated
<
double
>
squashAxisExtent
=
new
Tween
<
double
>(
begin:
_directionIsYAxis
?
_size
.
width
:
_size
.
height
,
end:
0.0
).
animate
(
new
CurvedAnimation
(
parent:
_resizeController
,
curve:
_kCardResizeTimeCurve
);
return
new
SquashTransition
(
performance:
_resizePerformance
.
view
,
width:
_directionIsYAxis
?
squashAxisExtent
:
null
,
height:
!
_directionIsYAxis
?
squashAxisExtent
:
null
));
return
new
AnimatedBuilder
(
animation:
squashAxisExtent
,
builder:
(
BuildContext
context
,
Widget
child
)
{
return
new
SizedBox
(
width:
_directionIsYAxis
?
squashAxisExtent
.
value
:
null
,
height:
!
_directionIsYAxis
?
squashAxisExtent
.
value
:
null
);
}
);
}
...
...
@@ -278,11 +283,10 @@ class _DismissableState extends State<Dismissable> {
child:
new
SizeObserver
(
onSizeChanged:
_handleSizeChanged
,
child:
new
SlideTransition
(
performance:
_dismissPerformance
.
view
,
position:
new
AnimatedValue
<
FractionalOffset
>(
FractionalOffset
.
zero
,
position:
new
Tween
<
FractionalOffset
>(
begin:
FractionalOffset
.
zero
,
end:
_activeCardDragEndPoint
),
)
.
animate
(
_dismissController
)
,
child:
config
.
child
)
)
...
...
packages/flutter/lib/src/widgets/heroes.dart
View file @
aabd1ce4
...
...
@@ -378,7 +378,7 @@ class HeroParty {
Animated
<
double
>
_currentAnimation
;
void
_clearCurrent
Performance
()
{
void
_clearCurrent
Animation
()
{
_currentAnimation
?.
removeStatusListener
(
_handleUpdate
);
_currentAnimation
=
null
;
}
...
...
@@ -386,7 +386,7 @@ class HeroParty {
void
setAnimation
(
Animated
<
double
>
animation
)
{
assert
(
animation
!=
null
||
_heroes
.
length
==
0
);
if
(
animation
!=
_currentAnimation
)
{
_clearCurrent
Performance
();
_clearCurrent
Animation
();
_currentAnimation
=
animation
;
_currentAnimation
?.
addStatusListener
(
_handleUpdate
);
}
...
...
@@ -402,7 +402,7 @@ class HeroParty {
source
.
_resetChild
();
}
_heroes
.
clear
();
_clearCurrent
Performance
();
_clearCurrent
Animation
();
if
(
onQuestFinished
!=
null
)
onQuestFinished
();
}
...
...
packages/flutter/lib/src/widgets/implicit_animations.dart
View file @
aabd1ce4
...
...
@@ -10,17 +10,15 @@ import 'framework.dart';
import
'package:vector_math/vector_math_64.dart'
;
/// An animated value that interpolates [BoxConstraint]s.
class
AnimatedBoxConstraintsValue
extends
AnimatedValue
<
BoxConstraints
>
{
AnimatedBoxConstraintsValue
(
BoxConstraints
begin
,
{
BoxConstraints
end
,
Curve
curve
,
Curve
reverseCurve
})
:
super
(
begin
,
end:
end
,
curve:
curve
,
reverseCurve:
reverseCurve
);
class
BoxConstraintsTween
extends
Tween
<
BoxConstraints
>
{
BoxConstraintsTween
({
BoxConstraints
begin
,
BoxConstraints
end
})
:
super
(
begin:
begin
,
end:
end
);
BoxConstraints
lerp
(
double
t
)
=>
BoxConstraints
.
lerp
(
begin
,
end
,
t
);
}
/// An animated value that interpolates [Decoration]s.
class
AnimatedDecorationValue
extends
AnimatedValue
<
Decoration
>
{
AnimatedDecorationValue
(
Decoration
begin
,
{
Decoration
end
,
Curve
curve
,
Curve
reverseCurve
})
:
super
(
begin
,
end:
end
,
curve:
curve
,
reverseCurve:
reverseCurve
);
class
DecorationTween
extends
Tween
<
Decoration
>
{
DecorationTween
({
Decoration
begin
,
Decoration
end
})
:
super
(
begin:
begin
,
end:
end
);
Decoration
lerp
(
double
t
)
{
if
(
begin
==
null
&&
end
==
null
)
...
...
@@ -32,9 +30,8 @@ class AnimatedDecorationValue extends AnimatedValue<Decoration> {
}
/// An animated value that interpolates [EdgeDims].
class
AnimatedEdgeDimsValue
extends
AnimatedValue
<
EdgeDims
>
{
AnimatedEdgeDimsValue
(
EdgeDims
begin
,
{
EdgeDims
end
,
Curve
curve
,
Curve
reverseCurve
})
:
super
(
begin
,
end:
end
,
curve:
curve
,
reverseCurve:
reverseCurve
);
class
EdgeDimsTween
extends
Tween
<
EdgeDims
>
{
EdgeDimsTween
({
EdgeDims
begin
,
EdgeDims
end
})
:
super
(
begin:
begin
,
end:
end
);
EdgeDims
lerp
(
double
t
)
=>
EdgeDims
.
lerp
(
begin
,
end
,
t
);
}
...
...
@@ -42,9 +39,8 @@ class AnimatedEdgeDimsValue extends AnimatedValue<EdgeDims> {
/// An animated value that interpolates [Matrix4]s.
///
/// Currently this class works only for translations.
class
AnimatedMatrix4Value
extends
AnimatedValue
<
Matrix4
>
{
AnimatedMatrix4Value
(
Matrix4
begin
,
{
Matrix4
end
,
Curve
curve
,
Curve
reverseCurve
})
:
super
(
begin
,
end:
end
,
curve:
curve
,
reverseCurve:
reverseCurve
);
class
Matrix4Tween
extends
Tween
<
Matrix4
>
{
Matrix4Tween
({
Matrix4
begin
,
Matrix4
end
})
:
super
(
begin:
begin
,
end:
end
);
Matrix4
lerp
(
double
t
)
{
// TODO(mpcomplete): Animate the full matrix. Will animating the cells
...
...
@@ -82,113 +78,107 @@ abstract class AnimatedWidgetBase extends StatefulComponent {
}
}
typedef
AnimatedValue
<
T
>
Variable
Constructor
<
T
>(
T
targetValue
);
typedef
AnimatedValue
<
T
>
VariableVisitor
<
T
>(
AnimatedValue
<
T
>
variable
,
T
targetValue
,
Variable
Constructor
<
T
>
constructor
);
typedef
Tween
<
T
>
Tween
Constructor
<
T
>(
T
targetValue
);
typedef
Tween
<
T
>
TweenVisitor
<
T
>(
Tween
<
T
>
tween
,
T
targetValue
,
Tween
Constructor
<
T
>
constructor
);
abstract
class
AnimatedWidgetBaseState
<
T
extends
AnimatedWidgetBase
>
extends
State
<
T
>
{
Performance
_performanceController
;
PerformanceView
_performance
;
AnimationController
_controller
;
Animated
<
double
>
get
animation
=>
_animation
;
Animated
<
double
>
_animation
;
void
initState
()
{
super
.
initState
();
_
performanceController
=
new
Performance
(
_
controller
=
new
AnimationController
(
duration:
config
.
duration
,
debugLabel:
'
${config.toStringShort()}
'
);
)
..
addListener
(
_handleAnimationChanged
)
;
_updateCurve
();
_con
figAllVariable
s
();
_con
structTween
s
();
}
void
didUpdateConfig
(
T
oldConfig
)
{
if
(
config
.
curve
!=
oldConfig
.
curve
)
_updateCurve
();
_performanceController
.
duration
=
config
.
duration
;
if
(
_configAllVariables
())
{
forEachVariable
((
AnimatedValue
variable
,
dynamic
targetValue
,
VariableConstructor
<
T
>
constructor
)
{
_updateBeginValue
(
variable
);
return
variable
;
_controller
.
duration
=
config
.
duration
;
if
(
_constructTweens
())
{
forEachTween
((
Tween
tween
,
dynamic
targetValue
,
TweenConstructor
<
T
>
constructor
)
{
_updateTween
(
tween
,
targetValue
);
return
tween
;
});
_performanceController
.
progress
=
0.0
;
_performanceController
.
play
();
_controller
..
value
=
0.0
..
forward
();
}
}
void
_updateCurve
()
{
_performance
?.
removeListener
(
_updateAllVariables
);
if
(
config
.
curve
!=
null
)
_
performance
=
new
CurvedPerformance
(
_performanceC
ontroller
,
curve:
config
.
curve
);
_
animation
=
new
CurvedAnimation
(
parent:
_c
ontroller
,
curve:
config
.
curve
);
else
_performance
=
_performanceController
;
_performance
.
addListener
(
_updateAllVariables
);
_animation
=
_controller
;
}
void
dispose
()
{
_
performanceC
ontroller
.
stop
();
_
c
ontroller
.
stop
();
super
.
dispose
();
}
void
_updateVariable
(
Animatable
variable
)
{
if
(
variable
!=
null
)
_performance
.
updateVariable
(
variable
);
}
void
_updateAllVariables
()
{
setState
(()
{
forEachVariable
((
AnimatedValue
variable
,
dynamic
targetValue
,
VariableConstructor
<
T
>
constructor
)
{
_updateVariable
(
variable
);
return
variable
;
});
});
void
_handleAnimationChanged
()
{
setState
(()
{
});
}
bool
_updateEndValue
(
AnimatedValue
variable
,
dynamic
targetValue
)
{
if
(
targetValue
==
variable
.
end
)
return
false
;
variable
.
end
=
targetValue
;
return
true
;
bool
_shouldAnimateTween
(
Tween
tween
,
dynamic
targetValue
)
{
return
targetValue
!=
(
tween
.
end
??
tween
.
begin
);
}
void
_updateBeginValue
(
AnimatedValue
variable
)
{
variable
?.
begin
=
variable
.
value
;
void
_updateTween
(
Tween
tween
,
dynamic
targetValue
)
{
if
(
tween
==
null
)
return
;
tween
..
begin
=
tween
.
evaluate
(
_animation
)
..
end
=
targetValue
;
}
bool
_con
figAllVariable
s
()
{
bool
startAnimation
=
false
;
forEach
Variable
((
AnimatedValue
variable
,
dynamic
targetValue
,
VariableConstructor
<
T
>
constructor
)
{
bool
_con
structTween
s
()
{
bool
s
houldS
tartAnimation
=
false
;
forEach
Tween
((
Tween
tween
,
dynamic
targetValue
,
TweenConstructor
<
T
>
constructor
)
{
if
(
targetValue
!=
null
)
{
variable
??=
constructor
(
targetValue
);
if
(
_
updateEndValue
(
variable
,
targetValue
))
startAnimation
=
true
;
tween
??=
constructor
(
targetValue
);
if
(
_
shouldAnimateTween
(
tween
,
targetValue
))
s
houldS
tartAnimation
=
true
;
}
else
{
variable
=
null
;
tween
=
null
;
}
return
variable
;
return
tween
;
});
return
startAnimation
;
return
s
houldS
tartAnimation
;
}
/// Subclasses must implement this function by running through the following
/// steps for for each animatable facet in the class:
///
/// 1. Call the visitor callback with three arguments, the first argument
/// being the current value of the
AnimatedValue
<T> object that represents the
///
variable
(initially null), the second argument, of type T, being the value
/// being the current value of the
Tween
<T> object that represents the
///
tween
(initially null), the second argument, of type T, being the value
/// on the Widget (config) that represents the current target value of the
///
variable
, and the third being a callback that takes a value T (which will
///
tween
, and the third being a callback that takes a value T (which will
/// be the second argument to the visitor callback), and that returns an
///
AnimatedValue<T> object for the variable
, configured with the given value
///
Tween<T> object for the tween
, configured with the given value
/// as the begin value.
///
/// 2. Take the value returned from the callback, and store it. This is the
/// value to use as the current value the next time that the forEach
Variable
()
/// value to use as the current value the next time that the forEach
Tween
()
/// method is called.
void
forEach
Variable
(
Variable
Visitor
visitor
);
void
forEach
Tween
(
Tween
Visitor
visitor
);
}
/// A container that gradually changes its values over a period of time.
///
/// This class is useful for generating simple implicit transitions between
/// different parameters to [Container]. For more complex animations, you'll
/// likely want to use a subclass of [Transition] or
control a [Performance]
/// yourself.
/// likely want to use a subclass of [Transition] or
use an
///
[AnimationController]
yourself.
class
AnimatedContainer
extends
AnimatedWidgetBase
{
AnimatedContainer
({
Key
key
,
...
...
@@ -260,38 +250,38 @@ class AnimatedContainer extends AnimatedWidgetBase {
}
class
_AnimatedContainerState
extends
AnimatedWidgetBaseState
<
AnimatedContainer
>
{
AnimatedBoxConstraintsValue
_constraints
;
AnimatedDecorationValue
_decoration
;
AnimatedDecorationValue
_foregroundDecoration
;
AnimatedEdgeDimsValue
_margin
;
AnimatedEdgeDimsValue
_padding
;
AnimatedMatrix4Value
_transform
;
AnimatedValue
<
double
>
_width
;
AnimatedValue
<
double
>
_height
;
void
forEach
Variable
(
Variable
Visitor
visitor
)
{
BoxConstraintsTween
_constraints
;
DecorationTween
_decoration
;
DecorationTween
_foregroundDecoration
;
EdgeDimsTween
_margin
;
EdgeDimsTween
_padding
;
Matrix4Tween
_transform
;
Tween
<
double
>
_width
;
Tween
<
double
>
_height
;
void
forEach
Tween
(
Tween
Visitor
visitor
)
{
// TODO(ianh): Use constructor tear-offs when it becomes possible
_constraints
=
visitor
(
_constraints
,
config
.
constraints
,
(
dynamic
value
)
=>
new
AnimatedBoxConstraintsValue
(
value
));
_decoration
=
visitor
(
_decoration
,
config
.
decoration
,
(
dynamic
value
)
=>
new
AnimatedDecorationValue
(
value
));
_foregroundDecoration
=
visitor
(
_foregroundDecoration
,
config
.
foregroundDecoration
,
(
dynamic
value
)
=>
new
AnimatedDecorationValue
(
value
));
_margin
=
visitor
(
_margin
,
config
.
margin
,
(
dynamic
value
)
=>
new
AnimatedEdgeDimsValue
(
value
));
_padding
=
visitor
(
_padding
,
config
.
padding
,
(
dynamic
value
)
=>
new
AnimatedEdgeDimsValue
(
value
));
_transform
=
visitor
(
_transform
,
config
.
transform
,
(
dynamic
value
)
=>
new
AnimatedMatrix4Value
(
value
));
_width
=
visitor
(
_width
,
config
.
width
,
(
dynamic
value
)
=>
new
AnimatedValue
<
double
>(
value
));
_height
=
visitor
(
_height
,
config
.
height
,
(
dynamic
value
)
=>
new
AnimatedValue
<
double
>(
value
));
_constraints
=
visitor
(
_constraints
,
config
.
constraints
,
(
dynamic
value
)
=>
new
BoxConstraintsTween
(
begin:
value
));
_decoration
=
visitor
(
_decoration
,
config
.
decoration
,
(
dynamic
value
)
=>
new
DecorationTween
(
begin:
value
));
_foregroundDecoration
=
visitor
(
_foregroundDecoration
,
config
.
foregroundDecoration
,
(
dynamic
value
)
=>
new
DecorationTween
(
begin:
value
));
_margin
=
visitor
(
_margin
,
config
.
margin
,
(
dynamic
value
)
=>
new
EdgeDimsTween
(
begin:
value
));
_padding
=
visitor
(
_padding
,
config
.
padding
,
(
dynamic
value
)
=>
new
EdgeDimsTween
(
begin:
value
));
_transform
=
visitor
(
_transform
,
config
.
transform
,
(
dynamic
value
)
=>
new
Matrix4Tween
(
begin:
value
));
_width
=
visitor
(
_width
,
config
.
width
,
(
dynamic
value
)
=>
new
Tween
<
double
>(
begin:
value
));
_height
=
visitor
(
_height
,
config
.
height
,
(
dynamic
value
)
=>
new
Tween
<
double
>(
begin:
value
));
}
Widget
build
(
BuildContext
context
)
{
return
new
Container
(
child:
config
.
child
,
constraints:
_constraints
?.
value
,
decoration:
_decoration
?.
value
,
foregroundDecoration:
_foregroundDecoration
?.
value
,
margin:
_margin
?.
value
,
padding:
_padding
?.
value
,
transform:
_transform
?.
value
,
width:
_width
?.
value
,
height:
_height
?.
value
constraints:
_constraints
?.
evaluate
(
animation
)
,
decoration:
_decoration
?.
evaluate
(
animation
)
,
foregroundDecoration:
_foregroundDecoration
?.
evaluate
(
animation
)
,
margin:
_margin
?.
evaluate
(
animation
)
,
padding:
_padding
?.
evaluate
(
animation
)
,
transform:
_transform
?.
evaluate
(
animation
)
,
width:
_width
?.
evaluate
(
animation
)
,
height:
_height
?.
evaluate
(
animation
)
);
}
...
...
@@ -381,32 +371,32 @@ class AnimatedPositioned extends AnimatedWidgetBase {
}
class
_AnimatedPositionedState
extends
AnimatedWidgetBaseState
<
AnimatedPositioned
>
{
AnimatedValue
<
double
>
_left
;
AnimatedValue
<
double
>
_top
;
AnimatedValue
<
double
>
_right
;
AnimatedValue
<
double
>
_bottom
;
AnimatedValue
<
double
>
_width
;
AnimatedValue
<
double
>
_height
;
void
forEach
Variable
(
Variable
Visitor
visitor
)
{
Tween
<
double
>
_left
;
Tween
<
double
>
_top
;
Tween
<
double
>
_right
;
Tween
<
double
>
_bottom
;
Tween
<
double
>
_width
;
Tween
<
double
>
_height
;
void
forEach
Tween
(
Tween
Visitor
visitor
)
{
// TODO(ianh): Use constructor tear-offs when it becomes possible
_left
=
visitor
(
_left
,
config
.
left
,
(
dynamic
value
)
=>
new
AnimatedValue
<
double
>(
value
));
_top
=
visitor
(
_top
,
config
.
top
,
(
dynamic
value
)
=>
new
AnimatedValue
<
double
>(
value
));
_right
=
visitor
(
_right
,
config
.
right
,
(
dynamic
value
)
=>
new
AnimatedValue
<
double
>(
value
));
_bottom
=
visitor
(
_bottom
,
config
.
bottom
,
(
dynamic
value
)
=>
new
AnimatedValue
<
double
>(
value
));
_width
=
visitor
(
_width
,
config
.
width
,
(
dynamic
value
)
=>
new
AnimatedValue
<
double
>(
value
));
_height
=
visitor
(
_height
,
config
.
height
,
(
dynamic
value
)
=>
new
AnimatedValue
<
double
>(
value
));
_left
=
visitor
(
_left
,
config
.
left
,
(
dynamic
value
)
=>
new
Tween
<
double
>(
begin:
value
));
_top
=
visitor
(
_top
,
config
.
top
,
(
dynamic
value
)
=>
new
Tween
<
double
>(
begin:
value
));
_right
=
visitor
(
_right
,
config
.
right
,
(
dynamic
value
)
=>
new
Tween
<
double
>(
begin:
value
));
_bottom
=
visitor
(
_bottom
,
config
.
bottom
,
(
dynamic
value
)
=>
new
Tween
<
double
>(
begin:
value
));
_width
=
visitor
(
_width
,
config
.
width
,
(
dynamic
value
)
=>
new
Tween
<
double
>(
begin:
value
));
_height
=
visitor
(
_height
,
config
.
height
,
(
dynamic
value
)
=>
new
Tween
<
double
>(
begin:
value
));
}
Widget
build
(
BuildContext
context
)
{
return
new
Positioned
(
child:
config
.
child
,
left:
_left
?.
value
,
top:
_top
?.
value
,
right:
_right
?.
value
,
bottom:
_bottom
?.
value
,
width:
_width
?.
value
,
height:
_height
?.
value
left:
_left
?.
evaluate
(
animation
)
,
top:
_top
?.
evaluate
(
animation
)
,
right:
_right
?.
evaluate
(
animation
)
,
bottom:
_bottom
?.
evaluate
(
animation
)
,
width:
_width
?.
evaluate
(
animation
)
,
height:
_height
?.
evaluate
(
animation
)
);
}
...
...
packages/flutter/lib/src/widgets/mimic.dart
View file @
aabd1ce4
...
...
@@ -3,7 +3,6 @@
// found in the LICENSE file.
import
'dart:async'
;
import
'dart:ui'
as
ui
;
import
'package:flutter/animation.dart'
;
import
'package:flutter/rendering.dart'
;
...
...
@@ -42,7 +41,7 @@ class MimicOverlayEntry {
// Animation state
GlobalKey
_targetKey
;
Curve
_curve
;
Performance
_performance
;
AnimationController
_controller
;
/// Animate the entry to the location of the widget that has the given target key.
///
...
...
@@ -63,10 +62,10 @@ class MimicOverlayEntry {
_targetKey
=
targetKey
;
_curve
=
curve
;
// TODO(abarth): Support changing the animation target when in flight.
assert
(
_
performance
==
null
);
_
performance
=
new
Performance
(
duration:
duration
)
assert
(
_
controller
==
null
);
_
controller
=
new
AnimationController
(
duration:
duration
)
..
addListener
(
_overlayEntry
.
markNeedsBuild
);
return
_
performance
.
play
();
return
_
controller
.
forward
();
}
/// Cause the overlay entry to rebuild during the next pipeline flush.
...
...
@@ -84,8 +83,8 @@ class MimicOverlayEntry {
void
dispose
()
{
_targetKey
=
null
;
_curve
=
null
;
_
performance
?.
stop
();
_
performance
=
null
;
_
controller
?.
stop
();
_
controller
=
null
;
_key
.
stopMimic
();
_key
=
null
;
_overlayEntry
.
remove
();
...
...
@@ -98,16 +97,14 @@ class MimicOverlayEntry {
Rect
globalBounds
=
_initialGlobalBounds
;
Point
globalPosition
=
globalBounds
.
topLeft
;
if
(
_targetKey
!=
null
)
{
assert
(
_
performance
!=
null
);
assert
(
_
controller
!=
null
);
assert
(
_curve
!=
null
);
RenderBox
box
=
_targetKey
.
currentContext
?.
findRenderObject
();
if
(
box
!=
null
)
{
// TODO(abarth): Handle the case where the transform here isn't just a translation.
Point
localPosition
=
box
.
localToGlobal
(
Point
.
origin
);
double
t
=
_curve
.
transform
(
_performance
.
progress
);
// TODO(abarth): Add Point.lerp.
globalPosition
=
new
Point
(
ui
.
lerpDouble
(
globalPosition
.
x
,
localPosition
.
x
,
t
),
ui
.
lerpDouble
(
globalPosition
.
y
,
localPosition
.
y
,
t
));
double
t
=
_curve
.
transform
(
_controller
.
value
);
globalPosition
=
Point
.
lerp
(
globalPosition
,
localPosition
,
t
);
}
}
...
...
packages/flutter/lib/src/widgets/routes.dart
View file @
aabd1ce4
...
...
@@ -96,7 +96,7 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
Animated
<
double
>
_animation
;
AnimationController
_controller
;
/// Called to create the
Performance object
that will drive the transitions to
/// Called to create the
animation controller
that will drive the transitions to
/// this route from the previous one, and back to the previous route from this
/// one.
AnimationController
createAnimationController
()
{
...
...
@@ -105,8 +105,8 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
return
new
AnimationController
(
duration:
duration
,
debugLabel:
debugLabel
);
}
/// Called to create the
PerformanceView
that exposes the current progress of
/// the transition controlled by the
Performance object
created by
/// Called to create the
animation
that exposes the current progress of
/// the transition controlled by the
animation controller
created by
/// [createAnimationController()].
Animated
<
double
>
createAnimation
()
{
assert
(
_controller
!=
null
);
...
...
@@ -166,32 +166,32 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
}
void
didPopNext
(
Route
nextRoute
)
{
_updateForward
Performance
(
nextRoute
);
_updateForward
Animation
(
nextRoute
);
super
.
didPopNext
(
nextRoute
);
}
void
didChangeNext
(
Route
nextRoute
)
{
_updateForward
Performance
(
nextRoute
);
_updateForward
Animation
(
nextRoute
);
super
.
didChangeNext
(
nextRoute
);
}
void
_updateForward
Performance
(
Route
nextRoute
)
{
void
_updateForward
Animation
(
Route
nextRoute
)
{
if
(
nextRoute
is
TransitionRoute
&&
canTransitionTo
(
nextRoute
)
&&
nextRoute
.
canTransitionFrom
(
this
))
{
Animated
<
double
>
current
=
_forwardAnimation
.
masterAnimation
;
if
(
current
!=
null
)
{
if
(
current
is
TrainHoppingAnimation
)
{
TrainHoppingAnimation
new
Performance
;
new
Performance
=
new
TrainHoppingAnimation
(
TrainHoppingAnimation
new
Animation
;
new
Animation
=
new
TrainHoppingAnimation
(
current
.
currentTrain
,
nextRoute
.
animation
,
onSwitchedTrain:
()
{
assert
(
_forwardAnimation
.
masterAnimation
==
new
Performance
);
assert
(
new
Performance
.
currentTrain
==
nextRoute
.
animation
);
_forwardAnimation
.
masterAnimation
=
new
Performance
.
currentTrain
;
new
Performance
.
dispose
();
assert
(
_forwardAnimation
.
masterAnimation
==
new
Animation
);
assert
(
new
Animation
.
currentTrain
==
nextRoute
.
animation
);
_forwardAnimation
.
masterAnimation
=
new
Animation
.
currentTrain
;
new
Animation
.
dispose
();
}
);
_forwardAnimation
.
masterAnimation
=
new
Performance
;
_forwardAnimation
.
masterAnimation
=
new
Animation
;
current
.
dispose
();
}
else
{
_forwardAnimation
.
masterAnimation
=
new
TrainHoppingAnimation
(
current
,
nextRoute
.
animation
);
...
...
@@ -322,7 +322,7 @@ class _ModalScopeState extends State<_ModalScope> {
void
_animationStatusChanged
(
PerformanceStatus
status
)
{
setState
(()
{
// The
performances'
states are our build state, and they changed already.
// The
animation's
states are our build state, and they changed already.
});
}
...
...
packages/flutter/lib/src/widgets/status_transitions.dart
View file @
aabd1ce4
...
...
@@ -24,24 +24,24 @@ abstract class StatusTransitionComponent extends StatefulComponent {
class
_StatusTransitionState
extends
State
<
StatusTransitionComponent
>
{
void
initState
()
{
super
.
initState
();
config
.
animation
.
addStatusListener
(
_
performance
StatusChanged
);
config
.
animation
.
addStatusListener
(
_
animation
StatusChanged
);
}
void
didUpdateConfig
(
StatusTransitionComponent
oldConfig
)
{
if
(
config
.
animation
!=
oldConfig
.
animation
)
{
oldConfig
.
animation
.
removeStatusListener
(
_
performance
StatusChanged
);
config
.
animation
.
addStatusListener
(
_
performance
StatusChanged
);
oldConfig
.
animation
.
removeStatusListener
(
_
animation
StatusChanged
);
config
.
animation
.
addStatusListener
(
_
animation
StatusChanged
);
}
}
void
dispose
()
{
config
.
animation
.
removeStatusListener
(
_
performance
StatusChanged
);
config
.
animation
.
removeStatusListener
(
_
animation
StatusChanged
);
super
.
dispose
();
}
void
_
performance
StatusChanged
(
PerformanceStatus
status
)
{
void
_
animation
StatusChanged
(
PerformanceStatus
status
)
{
setState
(()
{
// The
performance
's state is our build state, and it changed already.
// The
animation
's state is our build state, and it changed already.
});
}
...
...
packages/flutter/lib/src/widgets/transitions.dart
View file @
aabd1ce4
...
...
@@ -126,23 +126,25 @@ abstract class TransitionWithChild extends TransitionComponent {
Widget
buildWithChild
(
BuildContext
context
,
Widget
child
);
}
class
SlideTransition
extends
TransitionWithChild
{
class
SlideTransition
extends
AnimatedComponent
{
SlideTransition
({
Key
key
,
this
.
position
,
Animated
<
FractionalOffset
>
position
,
PerformanceView
performance
,
this
.
transformHitTests
:
true
,
Widget
child
})
:
super
(
key:
key
,
performance:
performance
,
child:
child
);
this
.
child
})
:
position
=
position
,
super
(
key:
key
,
animation:
position
);
final
AnimatedValue
<
FractionalOffset
>
position
;
bool
transformHitTests
;
final
Animated
<
FractionalOffset
>
position
;
final
bool
transformHitTests
;
final
Widget
child
;
Widget
buildWithChild
(
BuildContext
context
,
Widget
child
)
{
performance
.
updateVariable
(
position
);
return
new
FractionalTranslation
(
translation:
position
.
value
,
transformHitTests:
transformHitTests
,
child:
child
);
Widget
build
(
BuildContext
context
)
{
return
new
FractionalTranslation
(
translation:
position
.
value
,
transformHitTests:
transformHitTests
,
child:
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