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
b6cf053e
Commit
b6cf053e
authored
Dec 05, 2015
by
Ian Hickson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #752 from Hixie/yak3-remove-timing
Replace AnimationTiming with CurvedPerformance
parents
88fbf76e
379b6a50
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
141 additions
and
73 deletions
+141
-73
animated_value.dart
packages/flutter/lib/src/animation/animated_value.dart
+24
-32
performance.dart
packages/flutter/lib/src/animation/performance.dart
+60
-10
bottom_sheet.dart
packages/flutter/lib/src/material/bottom_sheet.dart
+3
-3
popup_menu.dart
packages/flutter/lib/src/material/popup_menu.dart
+5
-6
scaffold.dart
packages/flutter/lib/src/material/scaffold.dart
+2
-2
snack_bar.dart
packages/flutter/lib/src/material/snack_bar.dart
+1
-1
animated_container.dart
packages/flutter/lib/src/widgets/animated_container.dart
+22
-10
routes.dart
packages/flutter/lib/src/widgets/routes.dart
+24
-9
No files found.
packages/flutter/lib/src/animation/animated_value.dart
View file @
b6cf053e
...
...
@@ -20,16 +20,28 @@ enum AnimationDirection {
/// 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
);
String
toString
();
}
/// Used by [Performance] to convert the timing of a performance to a different timescale.
/// For example, by setting different values for the interval and reverseInterval, a performance
/// can be made to take longer in one direction that the other.
class
AnimationTiming
{
AnimationTiming
({
this
.
curve
,
this
.
reverseCurve
});
/// 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
;
...
...
@@ -39,6 +51,12 @@ class AnimationTiming {
/// If this field is null, use [curve] in both directions.
Curve
reverseCurve
;
Curve
_getActiveCurve
(
AnimationDirection
direction
)
{
if
(
direction
==
AnimationDirection
.
forward
||
reverseCurve
==
null
)
return
curve
;
return
reverseCurve
;
}
/// Applies this timing to the given animation clock value in the given direction
double
transform
(
double
t
,
AnimationDirection
direction
)
{
Curve
activeCurve
=
_getActiveCurve
(
direction
);
...
...
@@ -51,32 +69,6 @@ class AnimationTiming {
return
activeCurve
.
transform
(
t
);
}
Curve
_getActiveCurve
(
AnimationDirection
direction
)
{
if
(
direction
==
AnimationDirection
.
forward
||
reverseCurve
==
null
)
return
curve
;
return
reverseCurve
;
}
}
/// An animated variable with a concrete type.
class
AnimatedValue
<
T
extends
dynamic
>
extends
AnimationTiming
implements
Animatable
{
AnimatedValue
(
this
.
begin
,
{
this
.
end
,
Curve
curve
,
Curve
reverseCurve
})
:
super
(
curve:
curve
,
reverseCurve:
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
;
/// Updates the value of this variable according to the given animation clock
/// value and direction.
void
setProgress
(
double
t
,
AnimationDirection
direction
)
{
...
...
packages/flutter/lib/src/animation/performance.dart
View file @
b6cf053e
...
...
@@ -8,9 +8,10 @@ import 'dart:ui' show VoidCallback, lerpDouble;
import
'package:newton/newton.dart'
;
import
'animated_value.dart'
;
import
'curves.dart'
;
import
'forces.dart'
;
import
'simulation_stepper.dart'
;
import
'listener_helpers.dart'
;
import
'simulation_stepper.dart'
;
/// An interface that is implemented by [Performance] that exposes a
/// read-only view of the underlying performance. This is used by classes that
...
...
@@ -425,6 +426,62 @@ class ProxyPerformance extends PerformanceView
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
...
...
@@ -459,9 +516,6 @@ class Performance extends PerformanceView
AnimationDirection
get
curveDirection
=>
_curveDirection
;
AnimationDirection
_curveDirection
;
/// If non-null, animate with this timing instead of a linear timing
AnimationTiming
timing
;
/// The progress of this performance along the timeline
///
/// Note: Setting this value stops the current animation.
...
...
@@ -472,10 +526,6 @@ class Performance extends PerformanceView
_checkStatusChanged
();
}
double
get
_curvedProgress
{
return
timing
!=
null
?
timing
.
transform
(
progress
,
_curveDirection
)
:
progress
;
}
/// Whether this animation is currently animating in either the forward or reverse direction
bool
get
isAnimating
=>
_timeline
.
isAnimating
;
...
...
@@ -491,7 +541,7 @@ class Performance extends PerformanceView
/// Update the given varaible according to the current progress of this performance
void
updateVariable
(
Animatable
variable
)
{
variable
.
setProgress
(
_curvedP
rogress
,
_curveDirection
);
variable
.
setProgress
(
p
rogress
,
_curveDirection
);
}
/// Start running this animation forwards (towards the end)
...
...
@@ -591,7 +641,7 @@ class ValuePerformance<T> extends Performance {
void
didTick
(
double
t
)
{
if
(
variable
!=
null
)
variable
.
setProgress
(
_curvedP
rogress
,
_curveDirection
);
variable
.
setProgress
(
p
rogress
,
_curveDirection
);
super
.
didTick
(
t
);
}
}
...
...
packages/flutter/lib/src/material/bottom_sheet.dart
View file @
b6cf053e
...
...
@@ -37,7 +37,7 @@ class BottomSheet extends StatelessComponent {
final
double
childHeight
;
final
WidgetBuilder
builder
;
static
Performance
createPerformance
()
{
static
Performance
createPerformance
Controller
()
{
return
new
Performance
(
duration:
_kBottomSheetDuration
,
debugLabel:
'BottomSheet'
...
...
@@ -154,8 +154,8 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
bool
get
barrierDismissable
=>
true
;
Color
get
barrierColor
=>
Colors
.
black54
;
Performance
createPerformance
()
{
return
BottomSheet
.
createPerformance
();
Performance
createPerformance
Controller
()
{
return
BottomSheet
.
createPerformance
Controller
();
}
Widget
buildPage
(
BuildContext
context
,
PerformanceView
performance
,
PerformanceView
forwardPerformance
)
{
...
...
packages/flutter/lib/src/material/popup_menu.dart
View file @
b6cf053e
...
...
@@ -97,12 +97,11 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
final
List
<
PopupMenuItem
<
T
>>
items
;
final
int
elevation
;
Performance
createPerformance
()
{
Performance
result
=
super
.
createPerformance
();
AnimationTiming
timing
=
new
AnimationTiming
();
timing
.
reverseCurve
=
new
Interval
(
0.0
,
_kMenuCloseIntervalEnd
);
result
.
timing
=
timing
;
return
result
;
PerformanceView
createPerformance
()
{
return
new
CurvedPerformance
(
super
.
createPerformance
(),
reverseCurve:
new
Interval
(
0.0
,
_kMenuCloseIntervalEnd
)
);
}
Duration
get
transitionDuration
=>
_kMenuDuration
;
...
...
packages/flutter/lib/src/material/scaffold.dart
View file @
b6cf053e
...
...
@@ -133,7 +133,7 @@ class ScaffoldState extends State<Scaffold> {
Timer
_snackBarTimer
;
ScaffoldFeatureController
showSnackBar
(
SnackBar
snackbar
)
{
_snackBarPerformance
??=
SnackBar
.
createPerformance
()
_snackBarPerformance
??=
SnackBar
.
createPerformance
Controller
()
..
addStatusListener
(
_handleSnackBarStatusChange
);
if
(
_snackBars
.
isEmpty
)
{
assert
(
_snackBarPerformance
.
isDismissed
);
...
...
@@ -201,7 +201,7 @@ class ScaffoldState extends State<Scaffold> {
}
Completer
completer
=
new
Completer
();
GlobalKey
<
_PersistentBottomSheetState
>
bottomSheetKey
=
new
GlobalKey
<
_PersistentBottomSheetState
>();
Performance
performance
=
BottomSheet
.
createPerformance
()
Performance
performance
=
BottomSheet
.
createPerformance
Controller
()
..
forward
();
_PersistentBottomSheet
bottomSheet
;
LocalHistoryEntry
entry
=
new
LocalHistoryEntry
(
...
...
packages/flutter/lib/src/material/snack_bar.dart
View file @
b6cf053e
...
...
@@ -116,7 +116,7 @@ class SnackBar extends StatelessComponent {
// API for Scaffold.addSnackBar():
static
Performance
createPerformance
()
{
static
Performance
createPerformance
Controller
()
{
return
new
Performance
(
duration:
_kSnackBarTransitionDuration
,
debugLabel:
'SnackBar'
...
...
packages/flutter/lib/src/widgets/animated_container.dart
View file @
b6cf053e
...
...
@@ -92,28 +92,40 @@ class _AnimatedContainerState extends State<AnimatedContainer> {
AnimatedValue
<
double
>
_width
;
AnimatedValue
<
double
>
_height
;
Performance
_performance
;
Performance
_performanceController
;
PerformanceView
_performance
;
void
initState
()
{
super
.
initState
();
_performance
=
new
Performance
(
duration:
config
.
duration
,
debugLabel:
'
${config.toStringShort()}
'
)
..
timing
=
new
AnimationTiming
(
curve:
config
.
curve
)
..
addListener
(
_updateAllVariables
);
_performanceController
=
new
Performance
(
duration:
config
.
duration
,
debugLabel:
'
${config.toStringShort()}
'
);
_updateCurve
();
_configAllVariables
();
}
void
didUpdateConfig
(
AnimatedContainer
oldConfig
)
{
_performance
..
duration
=
config
.
duration
..
timing
.
curve
=
config
.
curve
;
if
(
config
.
curve
!=
oldConfig
.
curve
)
_updateCurve
();
_performanceController
.
duration
=
config
.
duration
;
if
(
_configAllVariables
())
{
_performance
.
progress
=
0.0
;
_performance
.
play
();
_performance
Controller
.
progress
=
0.0
;
_performance
Controller
.
play
();
}
}
void
_updateCurve
()
{
_performance
?.
removeListener
(
_updateAllVariables
);
if
(
config
.
curve
!=
null
)
_performance
=
new
CurvedPerformance
(
_performanceController
,
curve:
config
.
curve
);
else
_performance
=
_performanceController
;
_performance
.
addListener
(
_updateAllVariables
);
}
void
dispose
()
{
_performance
.
stop
();
_performance
Controller
.
stop
();
super
.
dispose
();
}
...
...
packages/flutter/lib/src/widgets/routes.dart
View file @
b6cf053e
...
...
@@ -81,15 +81,27 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
Duration
get
transitionDuration
;
bool
get
opaque
;
PerformanceView
get
performance
=>
_performance
?.
view
;
Performance
_performance
;
Performance
createPerformance
()
{
PerformanceView
get
performance
=>
_performance
;
Performance
_performanceController
;
PerformanceView
_performance
;
/// Called to create the Performance object that will drive the transitions to
/// this route from the previous one, and back to the previous route from this
/// one.
Performance
createPerformanceController
()
{
Duration
duration
=
transitionDuration
;
assert
(
duration
!=
null
&&
duration
>=
Duration
.
ZERO
);
return
new
Performance
(
duration:
duration
,
debugLabel:
debugLabel
);
}
/// Called to create the PerformanceView that exposes the current progress of
/// the transition controlled by the Performance object created by
/// [createPerformanceController()].
PerformanceView
createPerformance
()
{
assert
(
_performanceController
!=
null
);
return
_performanceController
.
view
;
}
T
_result
;
void
handleStatusChanged
(
PerformanceStatus
status
)
{
...
...
@@ -112,26 +124,29 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
}
void
install
(
OverlayEntry
insertionPoint
)
{
_performanceController
=
createPerformanceController
();
assert
(
_performanceController
!=
null
);
_performance
=
createPerformance
();
assert
(
_performance
!=
null
);
super
.
install
(
insertionPoint
);
}
void
didPush
()
{
_performance
.
addStatusListener
(
handleStatusChanged
);
_performance
.
forward
();
_performance
Controller
.
forward
();
super
.
didPush
();
}
void
didReplace
(
Route
oldRoute
)
{
if
(
oldRoute
is
TransitionRoute
)
_performance
.
progress
=
oldRoute
.
_performance
.
progress
;
_performance
Controller
.
progress
=
oldRoute
.
_performanceController
.
progress
;
_performance
.
addStatusListener
(
handleStatusChanged
);
super
.
didReplace
(
oldRoute
);
}
bool
didPop
(
T
result
)
{
_result
=
result
;
_performance
.
reverse
();
_performance
Controller
.
reverse
();
_popCompleter
?.
complete
(
_result
);
return
true
;
}
...
...
@@ -142,7 +157,7 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
}
void
dispose
()
{
_performance
.
stop
();
_performance
Controller
.
stop
();
super
.
dispose
();
}
...
...
@@ -182,7 +197,7 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
bool
canTransitionFrom
(
TransitionRoute
nextRoute
)
=>
true
;
String
get
debugLabel
=>
'
$runtimeType
'
;
String
toString
()
=>
'
$runtimeType
(performance:
$_performance
)'
;
String
toString
()
=>
'
$runtimeType
(performance:
$_performance
Controller
)'
;
}
class
LocalHistoryEntry
{
...
...
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