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

Side by Side Diff: sky/sdk/lib/animation/scroll_behavior.dart

Issue 1226373003: demo_launcher/lib/main.dart does not have bottom-overscroll (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
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 6
7 import 'mechanics.dart'; 7 import 'mechanics.dart';
8 import 'generators.dart'; 8 import 'generators.dart';
9 9
10 const double _kScrollFriction = 0.005; 10 const double _kScrollFriction = 0.005;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 if (_containerHeight != value) { 51 if (_containerHeight != value) {
52 _containerHeight = value; 52 _containerHeight = value;
53 // TODO(ianh) now what? what if we have a simulation ongoing? 53 // TODO(ianh) now what? what if we have a simulation ongoing?
54 } 54 }
55 } 55 }
56 56
57 OverscrollBehavior({double contentsHeight: 0.0, double containerHeight: 0.0}) 57 OverscrollBehavior({double contentsHeight: 0.0, double containerHeight: 0.0})
58 : _contentsHeight = contentsHeight, 58 : _contentsHeight = contentsHeight,
59 _containerHeight = containerHeight; 59 _containerHeight = containerHeight;
60 60
61 double get maxScroll => math.max(0.0, _contentsHeight - _containerHeight); 61 double get maxScrollOffset => math.max(0.0, _contentsHeight - _containerHeight );
62 62
63 Simulation release(Particle particle) { 63 Simulation release(Particle particle) {
64 System system; 64 System system;
65 if ((particle.position >= 0.0) && (particle.position < maxScroll)) { 65 if ((particle.position >= 0.0) && (particle.position < maxScrollOffset)) {
66 if (particle.velocity == 0.0) 66 if (particle.velocity == 0.0)
67 return null; 67 return null;
68 System slowdownSystem = new ParticleInBoxWithFriction( 68 System slowdownSystem = new ParticleInBoxWithFriction(
69 particle: particle, 69 particle: particle,
70 friction: _kScrollFriction, 70 friction: _kScrollFriction,
71 box: new GeofenceBox(min: 0.0, max: maxScroll, onEscape: () { 71 box: new GeofenceBox(min: 0.0, max: maxScrollOffset, onEscape: () {
72 (system as Multisystem).transitionToSystem(new ParticleInBoxWithFricti on( 72 (system as Multisystem).transitionToSystem(new ParticleInBoxWithFricti on(
73 particle: particle, 73 particle: particle,
74 friction: _kOverscrollFriction, 74 friction: _kOverscrollFriction,
75 box: new ClosedBox(), 75 box: new ClosedBox(),
76 onStop: () => (system as Multisystem).transitionToSystem(getBounceBa ckSystem(particle)) 76 onStop: () => (system as Multisystem).transitionToSystem(getBounceBa ckSystem(particle))
77 )); 77 ));
78 })); 78 }));
79 system = new Multisystem(particle: particle, system: slowdownSystem); 79 system = new Multisystem(particle: particle, system: slowdownSystem);
80 } else { 80 } else {
81 system = getBounceBackSystem(particle); 81 system = getBounceBackSystem(particle);
82 } 82 }
83 return new Simulation(system, terminationCondition: () => particle.position == 0.0); 83 return new Simulation(system, terminationCondition: () => particle.position == 0.0);
84 } 84 }
85 85
86 System getBounceBackSystem(Particle particle) { 86 System getBounceBackSystem(Particle particle) {
87 if (particle.position < 0.0) 87 if (particle.position < 0.0)
88 return new ParticleClimbingRamp( 88 return new ParticleClimbingRamp(
89 particle: particle, 89 particle: particle,
90 box: new ClosedBox(max: 0.0), 90 box: new ClosedBox(max: 0.0),
91 theta: _kBounceSlopeAngle, 91 theta: _kBounceSlopeAngle,
92 targetPosition: 0.0); 92 targetPosition: 0.0);
93 return new ParticleClimbingRamp( 93 return new ParticleClimbingRamp(
94 particle: particle, 94 particle: particle,
95 box: new ClosedBox(min: maxScroll), 95 box: new ClosedBox(min: maxScrollOffset),
96 theta: _kBounceSlopeAngle, 96 theta: _kBounceSlopeAngle,
97 targetPosition: maxScroll); 97 targetPosition: maxScrollOffset);
98 } 98 }
99 99
100 double applyCurve(double scrollOffset, double scrollDelta) { 100 double applyCurve(double scrollOffset, double scrollDelta) {
101 double newScrollOffset = scrollOffset + scrollDelta; 101 double newScrollOffset = scrollOffset + scrollDelta;
102 // If we're overscrolling, we want move the scroll offset 2x 102 // If we're overscrolling, we want move the scroll offset 2x
103 // slower than we would otherwise. Therefore, we "rewind" the 103 // slower than we would otherwise. Therefore, we "rewind" the
104 // newScrollOffset by half the amount that we moved it above. 104 // newScrollOffset by half the amount that we moved it above.
105 // Notice that we clap the "old" value to 0.0 so that we only 105 // Notice that we clap the "old" value to 0.0 so that we only
106 // reduce the portion of scrollDelta that's applied beyond 0.0. We 106 // reduce the portion of scrollDelta that's applied beyond 0.0. We
107 // do similar things for overscroll in the other direction. 107 // do similar things for overscroll in the other direction.
108 if (newScrollOffset < 0.0) { 108 if (newScrollOffset < 0.0) {
109 newScrollOffset -= (newScrollOffset - math.min(0.0, scrollOffset)) / 2.0; 109 newScrollOffset -= (newScrollOffset - math.min(0.0, scrollOffset)) / 2.0;
110 } else if (newScrollOffset > maxScroll) { 110 } else if (newScrollOffset > maxScrollOffset) {
111 newScrollOffset -= (newScrollOffset - math.max(maxScroll, scrollOffset)) / 2.0; 111 newScrollOffset -= (newScrollOffset - math.max(maxScrollOffset, scrollOffs et)) / 2.0;
112 } 112 }
113 return newScrollOffset; 113 return newScrollOffset;
114 } 114 }
115 } 115 }
OLDNEW
« no previous file with comments | « no previous file | sky/sdk/lib/widgets/fixed_height_scrollable.dart » ('j') | sky/sdk/lib/widgets/fixed_height_scrollable.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698