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
7724dc75
Commit
7724dc75
authored
Jul 16, 2015
by
Matt Perry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apply.patch
parent
633b6501
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
45 deletions
+37
-45
BUILD.gn
packages/flutter/BUILD.gn
+1
-0
animation_performance.dart
packages/flutter/lib/animation/animation_performance.dart
+16
-16
scroll_behavior.dart
packages/flutter/lib/animation/scroll_behavior.dart
+2
-1
timeline.dart
packages/flutter/lib/animation/timeline.dart
+0
-13
dismissable.dart
packages/flutter/lib/widgets/dismissable.dart
+2
-1
drawer.dart
packages/flutter/lib/widgets/drawer.dart
+16
-14
No files found.
packages/flutter/BUILD.gn
View file @
7724dc75
...
...
@@ -11,6 +11,7 @@ dart_pkg("sky") {
"lib/animation/animated_simulation.dart",
"lib/animation/animation_performance.dart",
"lib/animation/curves.dart",
"lib/animation/forces.dart",
"lib/animation/scroll_behavior.dart",
"lib/animation/timeline.dart",
"lib/assets/.gitignore",
...
...
packages/flutter/lib/animation/animation_performance.dart
View file @
7724dc75
...
...
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:newton/newton.dart'
;
import
'dart:async'
;
import
'package:sky/animation/timeline.dart'
;
import
'package:sky/animation/curves.dart'
;
import
'package:sky/animation/forces.dart'
;
abstract
class
AnimatedVariable
{
void
setFraction
(
double
t
);
...
...
@@ -99,23 +101,20 @@ class AnimationPerformance {
bool
get
isCompleted
=>
progress
==
1.0
;
bool
get
isAnimating
=>
timeline
.
isAnimating
;
void
play
()
{
_animateTo
(
1.0
);
}
void
reverse
()
{
_animateTo
(
0.0
);
}
Future
play
()
=>
_animateTo
(
1.0
);
Future
reverse
()
=>
_animateTo
(
0.0
);
void
stop
()
{
timeline
.
stop
();
}
// Resume animating in a direction, with the given velocity.
// TODO(mpcomplete): Allow user to specify the Simulation.
void
fling
({
double
velocity:
1.0
})
{
Simulation
simulation
=
timeline
.
defaultSpringSimulation
(
velocity:
velocity
);
timeline
.
fling
(
simulation
);
// Flings the timeline with an optional force (defaults to a critically damped
// spring) and initial velocity. Negative velocity causes the timeline to go
// in reverse.
Future
fling
({
double
velocity:
1.0
,
Force
force
})
{
if
(
force
==
null
)
force
=
kDefaultSpringForce
;
return
timeline
.
fling
(
force
.
release
(
progress
,
velocity
));
}
final
List
<
Function
>
_listeners
=
new
List
<
Function
>();
...
...
@@ -134,11 +133,12 @@ class AnimationPerformance {
listener
();
}
void
_animateTo
(
double
target
)
{
Future
_animateTo
(
double
target
)
{
double
remainingDistance
=
(
target
-
timeline
.
value
).
abs
();
timeline
.
stop
();
if
(
remainingDistance
!=
0.0
)
timeline
.
animateTo
(
target
,
duration:
duration
*
remainingDistance
);
if
(
remainingDistance
==
0.0
)
return
new
Future
.
value
();
return
timeline
.
animateTo
(
target
,
duration:
duration
*
remainingDistance
);
}
void
_tick
(
double
t
)
{
...
...
packages/flutter/lib/animation/scroll_behavior.dart
View file @
7724dc75
...
...
@@ -5,10 +5,11 @@
import
'dart:math'
as
math
;
import
'package:newton/newton.dart'
;
import
'package:sky/animation/forces.dart'
;
const
double
_kSecondsPerMillisecond
=
1000.0
;
abstract
class
ScrollBehavior
{
abstract
class
ScrollBehavior
extends
Force
{
Simulation
release
(
double
position
,
double
velocity
)
=>
null
;
// Returns the new scroll offset.
...
...
packages/flutter/lib/animation/timeline.dart
View file @
7724dc75
...
...
@@ -7,8 +7,6 @@ import 'dart:async';
import
'package:newton/newton.dart'
;
import
'package:sky/animation/animated_simulation.dart'
;
const
double
_kEpsilon
=
0.001
;
// Simple simulation that linearly varies from |begin| to |end| over |duration|.
class
TweenSimulation
extends
Simulation
{
final
double
_durationInSeconds
;
...
...
@@ -68,17 +66,6 @@ class Timeline {
_animation
.
stop
();
}
static
final
SpringDescription
_kDefaultSpringDesc
=
new
SpringDescription
.
withDampingRatio
(
mass:
1.0
,
springConstant:
500.0
,
ratio:
1.0
);
Simulation
defaultSpringSimulation
({
double
velocity:
0.0
})
{
// Target just past the 0 or 1 endpoint, because the animation will stop
// once the Spring gets within the epsilon, and we want to stop at 0 or 1.
double
target
=
velocity
<
0.0
?
-
_kEpsilon
:
1.0
+
_kEpsilon
;
return
new
SpringSimulation
(
_kDefaultSpringDesc
,
value
,
target
,
velocity
);
}
// Give |simulation| control over the timeline.
Future
fling
(
Simulation
simulation
)
{
stop
();
...
...
packages/flutter/lib/widgets/dismissable.dart
View file @
7724dc75
...
...
@@ -13,6 +13,7 @@ import 'package:vector_math/vector_math.dart';
const
Duration
_kCardDismissFadeout
=
const
Duration
(
milliseconds:
300
);
const
double
_kMinFlingVelocity
=
700.0
;
const
double
_kMinFlingVelocityDelta
=
400.0
;
const
double
_kFlingVelocityScale
=
1.0
/
300.0
;
const
double
_kDismissCardThreshold
=
0.6
;
typedef
void
DismissedCallback
(
);
...
...
@@ -129,7 +130,7 @@ class Dismissable extends AnimatedComponent {
_dragUnderway
=
false
;
_dragX
=
event
.
velocityX
.
sign
;
_position
.
end
=
_activeCardDragEndPoint
;
_performance
.
fling
(
velocity:
event
.
velocityX
.
abs
()
/
_width
);
_performance
.
fling
(
velocity:
event
.
velocityX
.
abs
()
*
_kFlingVelocityScale
);
}
}
...
...
packages/flutter/lib/widgets/drawer.dart
View file @
7724dc75
...
...
@@ -5,7 +5,6 @@
import
'dart:sky'
as
sky
;
import
'package:sky/animation/animation_performance.dart'
;
import
'package:sky/animation/curves.dart'
;
import
'package:sky/theme/shadows.dart'
;
import
'package:sky/theme/colors.dart'
as
colors
;
import
'package:sky/widgets/animated_component.dart'
;
...
...
@@ -30,14 +29,11 @@ import 'package:vector_math/vector_math.dart';
// The right nav can vary depending on content.
const
double
_kWidth
=
304.0
;
const
double
_kMinFlingVelocity
=
1.2
;
const
double
_kMinFlingVelocity
=
365.0
;
const
double
_kFlingVelocityScale
=
1.0
/
300.0
;
const
Duration
_kBaseSettleDuration
=
const
Duration
(
milliseconds:
246
);
// TODO(mpcomplete): The curve must be linear if we want the drawer to track
// the user's finger. Odeon remedies this by attaching spring forces to the
// initial timeline when animating (so it doesn't look linear).
const
Point
_kOpenPosition
=
Point
.
origin
;
const
Point
_kClosedPosition
=
const
Point
(-
_kWidth
,
0.0
);
const
Curve
_kAnimationCurve
=
linear
;
typedef
void
DrawerStatusChangeHandler
(
bool
showing
);
...
...
@@ -69,7 +65,7 @@ class Drawer extends AnimatedComponent {
AnimationPerformance
_performance
;
void
initState
()
{
_position
=
new
AnimatedType
<
Point
>(
_kClosedPosition
,
end:
_kOpenPosition
,
curve:
_kAnimationCurve
);
_position
=
new
AnimatedType
<
Point
>(
_kClosedPosition
,
end:
_kOpenPosition
);
_maskColor
=
new
AnimatedColor
(
colors
.
transparent
,
end:
const
Color
(
0x7F000000
));
_performance
=
new
AnimationPerformance
()
..
duration
=
_kBaseSettleDuration
...
...
@@ -95,11 +91,18 @@ class Drawer extends AnimatedComponent {
void
_show
()
{
if
(
navigator
!=
null
)
navigator
.
pushState
(
this
,
(
_
)
=>
_performance
.
reverse
());
_
performance
.
play
(
);
_
fling
(
1.0
);
}
void
_hide
()
{
_performance
.
reverse
();
_fling
(-
1.0
);
}
// We fling the performance timeline instead of animating it to give it a
// nice spring effect. We can't use curves for this because we need a linear
// curve in order to track the user's finger while dragging.
void
_fling
(
double
direction
)
{
_performance
.
fling
(
velocity:
direction
.
sign
);
}
Widget
build
()
{
...
...
@@ -151,9 +154,9 @@ class Drawer extends AnimatedComponent {
DrawerStatus
get
_status
=>
_performance
.
isDismissed
?
DrawerStatus
.
inactive
:
DrawerStatus
.
active
;
bool
get
_isMostlyClosed
=>
xPosition
<=
-
_kWidth
/
2
;
void
_settle
()
=>
_
isMostlyClosed
?
_performance
.
reverse
()
:
_performance
.
play
(
);
void
_settle
()
=>
_
fling
(
_isMostlyClosed
?
-
1.0
:
1.0
);
void
handleMaskTap
(
_
)
=>
_
performance
.
reverse
(
);
void
handleMaskTap
(
_
)
=>
_
fling
(-
1.0
);
// TODO(mpcomplete): Figure out how to generalize these handlers on a
// "PannableThingy" interface.
...
...
@@ -176,8 +179,7 @@ class Drawer extends AnimatedComponent {
}
void
handleFlingStart
(
event
)
{
double
velocityX
=
event
.
velocityX
/
_kWidth
;
if
(
velocityX
.
abs
()
>=
_kMinFlingVelocity
)
_performance
.
fling
(
velocity:
velocityX
);
if
(
event
.
velocityX
.
abs
()
>=
_kMinFlingVelocity
)
_performance
.
fling
(
velocity:
event
.
velocityX
*
_kFlingVelocityScale
);
}
}
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