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
3ee85e01
Unverified
Commit
3ee85e01
authored
Feb 22, 2018
by
David Shuckerow
Committed by
GitHub
Feb 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create and test max and min animations (#14814)
parent
3ea4d063
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
2 deletions
+101
-2
animations.dart
packages/flutter/lib/src/animation/animations.dart
+31
-2
animations_test.dart
packages/flutter/test/animation/animations_test.dart
+70
-0
No files found.
packages/flutter/lib/src/animation/animations.dart
View file @
3ee85e01
...
...
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:math'
as
math
;
import
'dart:ui'
show
VoidCallback
;
import
'package:flutter/foundation.dart'
;
...
...
@@ -544,6 +545,10 @@ class TrainHoppingAnimation extends Animation<double>
///
/// For example, to create an animation that is the sum of two others, subclass
/// this class and define `T get value = first.value + second.value;`
///
/// By default, the [status] of a [CompoundAnimation] is the status of the
/// [next] animation if [next] is moving, and the status of the [first]
/// animation otherwise.
abstract
class
CompoundAnimation
<
T
>
extends
Animation
<
T
>
with
AnimationLazyListenerMixin
,
AnimationLocalListenersMixin
,
AnimationLocalStatusListenersMixin
{
/// Creates a CompoundAnimation. Both arguments must be non-null. Either can
...
...
@@ -577,10 +582,12 @@ abstract class CompoundAnimation<T> extends Animation<T>
next
.
removeStatusListener
(
_maybeNotifyStatusListeners
);
}
/// Gets the status of this animation based on the [first] and [next] status.
///
/// The default is that if the [next] animation is moving, use its status.
/// Otherwise, default to [first].
@override
AnimationStatus
get
status
{
// If one of the sub-animations is moving, use that status. Otherwise,
// default to `first`.
if
(
next
.
status
==
AnimationStatus
.
forward
||
next
.
status
==
AnimationStatus
.
reverse
)
return
next
.
status
;
return
first
.
status
;
...
...
@@ -625,3 +632,25 @@ class AnimationMean extends CompoundAnimation<double> {
@override
double
get
value
=>
(
first
.
value
+
next
.
value
)
/
2.0
;
}
/// An animation that tracks the maximum of two other animations.
///
/// The [value] of this animation is the maximum of the values of
/// [first] and [next].
class
AnimationMax
<
T
extends
num
>
extends
CompoundAnimation
<
T
>
{
AnimationMax
(
Animation
<
T
>
first
,
Animation
<
T
>
next
):
super
(
first:
first
,
next:
next
);
@override
T
get
value
=>
math
.
max
(
first
.
value
,
next
.
value
);
}
/// An animation that tracks the minimum of two other animations.
///
/// The [value] of this animation is the maximum of the values of
/// [first] and [next].
class
AnimationMin
<
T
extends
num
>
extends
CompoundAnimation
<
T
>
{
AnimationMin
(
Animation
<
T
>
first
,
Animation
<
T
>
next
):
super
(
first:
first
,
next:
next
);
@override
T
get
value
=>
math
.
min
(
first
.
value
,
next
.
value
);
}
\ No newline at end of file
packages/flutter/test/animation/animations_test.dart
View file @
3ee85e01
...
...
@@ -153,6 +153,76 @@ void main() {
expect
(
log
,
isEmpty
);
});
test
(
'AnimationMax control test'
,
()
{
final
AnimationController
first
=
new
AnimationController
(
value:
0.5
,
vsync:
const
TestVSync
(),
);
final
AnimationController
second
=
new
AnimationController
(
vsync:
const
TestVSync
(),
);
final
AnimationMax
<
double
>
max
=
new
AnimationMax
<
double
>(
first
,
second
);
expect
(
max
,
hasOneLineDescription
);
expect
(
max
.
value
,
equals
(
0.5
));
final
List
<
double
>
log
=
<
double
>[];
void
logValue
()
{
log
.
add
(
max
.
value
);
}
max
.
addListener
(
logValue
);
second
.
value
=
1.0
;
expect
(
max
.
value
,
equals
(
1.0
));
expect
(
log
,
equals
(<
double
>[
1.0
]));
log
.
clear
();
max
.
removeListener
(
logValue
);
first
.
value
=
0.0
;
expect
(
max
.
value
,
equals
(
1.0
));
expect
(
log
,
isEmpty
);
});
test
(
'AnimationMin control test'
,
()
{
final
AnimationController
first
=
new
AnimationController
(
value:
0.5
,
vsync:
const
TestVSync
(),
);
final
AnimationController
second
=
new
AnimationController
(
vsync:
const
TestVSync
(),
);
final
AnimationMin
<
double
>
min
=
new
AnimationMin
<
double
>(
first
,
second
);
expect
(
min
,
hasOneLineDescription
);
expect
(
min
.
value
,
equals
(
0.0
));
final
List
<
double
>
log
=
<
double
>[];
void
logValue
()
{
log
.
add
(
min
.
value
);
}
min
.
addListener
(
logValue
);
second
.
value
=
1.0
;
expect
(
min
.
value
,
equals
(
0.5
));
expect
(
log
,
equals
(<
double
>[
0.5
]));
log
.
clear
();
min
.
removeListener
(
logValue
);
first
.
value
=
0.25
;
expect
(
min
.
value
,
equals
(
0.25
));
expect
(
log
,
isEmpty
);
});
test
(
'CurvedAnimation with bogus curve'
,
()
{
final
AnimationController
controller
=
new
AnimationController
(
vsync:
const
TestVSync
(),
...
...
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