Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: sky/framework/animation/scroll_curve.dart

Issue 999423004: Drive overscroll animations with a physics simulation (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: More comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/framework/animation/kinematics.dart ('k') | sky/framework/animation/simulation.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'dart:math' as math; 5 import 'dart:math' as math;
6 import 'kinematics.dart';
7 import 'simulation.dart';
8
9 const double _kSlope = 0.01;
6 10
7 abstract class ScrollCurve { 11 abstract class ScrollCurve {
12 Simulation release(Particle particle) => null;
13
8 // Returns the new scroll offset. 14 // Returns the new scroll offset.
9 double apply(double scrollOffset, double scrollDelta); 15 double apply(double scrollOffset, double scrollDelta);
10 } 16 }
11 17
12 class BoundedScrollCurve extends ScrollCurve { 18 class BoundedScrollCurve extends ScrollCurve {
13 double minOffset; 19 double minOffset;
14 double maxOffset; 20 double maxOffset;
15 21
16 BoundedScrollCurve({this.minOffset: 0.0, this.maxOffset}); 22 BoundedScrollCurve({this.minOffset: 0.0, this.maxOffset});
17 23
18 double apply(double scrollOffset, double scrollDelta) { 24 double apply(double scrollOffset, double scrollDelta) {
19 double newScrollOffset = scrollOffset + scrollDelta; 25 double newScrollOffset = scrollOffset + scrollDelta;
20 if (minOffset != null) 26 if (minOffset != null)
21 newScrollOffset = math.max(minOffset, newScrollOffset); 27 newScrollOffset = math.max(minOffset, newScrollOffset);
22 if (maxOffset != null) 28 if (maxOffset != null)
23 newScrollOffset = math.min(maxOffset, newScrollOffset); 29 newScrollOffset = math.min(maxOffset, newScrollOffset);
24 return newScrollOffset; 30 return newScrollOffset;
25 } 31 }
26 } 32 }
27 33
28 class OverscrollCurve extends ScrollCurve { 34 class OverscrollCurve extends ScrollCurve {
35 Simulation release(Particle particle) {
36 if (particle.position >= 0.0)
37 return null;
38 System system = new ParticleClimbingHill(
39 particle: particle,
40 box: new Box(max: 0.0),
41 slope: _kSlope,
42 targetPosition: 0.0);
43 return new Simulation(system,
44 terminationCondition: () => particle.position == 0.0);
45 }
46
29 double apply(double scrollOffset, double scrollDelta) { 47 double apply(double scrollOffset, double scrollDelta) {
30 double newScrollOffset = scrollOffset + scrollDelta; 48 double newScrollOffset = scrollOffset + scrollDelta;
31 if (newScrollOffset < 0.0) { 49 if (newScrollOffset < 0.0) {
32 // If we're overscrolling, we want move the scroll offset 2x slower than 50 // If we're overscrolling, we want move the scroll offset 2x slower than
33 // we would otherwise. Therefore, we "rewind" the newScrollOffset by half 51 // we would otherwise. Therefore, we "rewind" the newScrollOffset by half
34 // the amount that we moved it above. Notice that we clap the "old" value 52 // the amount that we moved it above. Notice that we clap the "old" value
35 // to 0.0 so that we only reduce the portion of scrollDelta that's applied 53 // to 0.0 so that we only reduce the portion of scrollDelta that's applied
36 // beyond 0.0. 54 // beyond 0.0.
37 newScrollOffset -= (newScrollOffset - math.min(0.0, scrollOffset)) / 2.0; 55 newScrollOffset -= (newScrollOffset - math.min(0.0, scrollOffset)) / 2.0;
38 } 56 }
39 return newScrollOffset; 57 return newScrollOffset;
40 } 58 }
41 } 59 }
OLDNEW
« no previous file with comments | « sky/framework/animation/kinematics.dart ('k') | sky/framework/animation/simulation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698