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

Unified Diff: sky/sdk/lib/widgets/scrollable.dart

Issue 1226133004: Switch scroll physics over to using newton (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: analyzer nit 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/sdk/lib/widgets/fixed_height_scrollable.dart ('k') | sky/sdk/lib/widgets/tabs.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/widgets/scrollable.dart
diff --git a/sky/sdk/lib/widgets/scrollable.dart b/sky/sdk/lib/widgets/scrollable.dart
index 6a8beb29c53e4c388934680b797c062656c490c8..b9eab727001e8ed508e4b4419571a830702a3b91 100644
--- a/sky/sdk/lib/widgets/scrollable.dart
+++ b/sky/sdk/lib/widgets/scrollable.dart
@@ -4,8 +4,9 @@
import 'dart:sky' as sky;
-import '../animation/generators.dart';
-import '../animation/mechanics.dart';
+import 'package:newton/newton.dart';
+
+import '../animation/animated_simulation.dart';
import '../animation/scroll_behavior.dart';
import '../theme/view_configuration.dart' as config;
import 'basic.dart';
@@ -30,7 +31,9 @@ abstract class Scrollable extends StatefulComponent {
String key,
this.backgroundColor,
this.direction: ScrollDirection.vertical
- }) : super(key: key);
+ }) : super(key: key) {
+ _animation = new AnimatedSimulation(_tickScrollOffset);
+ }
Color backgroundColor;
ScrollDirection direction;
@@ -51,7 +54,7 @@ abstract class Scrollable extends StatefulComponent {
return _scrollBehavior;
}
- Simulation _simulation;
+ AnimatedSimulation _animation;
Widget buildContent();
@@ -123,26 +126,23 @@ abstract class Scrollable extends StatefulComponent {
}
void settleScrollOffset() {
- _startSimulation(_createParticle());
+ _startSimulation();
}
void _stopSimulation() {
- if (_simulation == null)
- return;
- _simulation.cancel();
- _simulation = null;
+ _animation.stop();
}
- void _startSimulation(Particle particle) {
+ void _startSimulation({ double velocity: 0.0 }) {
_stopSimulation();
- _simulation = scrollBehavior.release(particle);
- if (_simulation == null)
- return;
- _simulation.onTick.listen((_) => scrollTo(particle.position));
+ print("velocity=$velocity");
+ Simulation simulation = scrollBehavior.release(scrollOffset, velocity);
+ if (simulation != null)
+ _animation.start(simulation);
}
- Particle _createParticle([double velocity = 0.0]) {
- return new Particle(position: _scrollOffset, velocity: velocity);
+ void _tickScrollOffset(double value) {
+ scrollTo(value);
}
void _handlePointerDown(_) {
@@ -150,7 +150,7 @@ abstract class Scrollable extends StatefulComponent {
}
void _handlePointerUpOrCancel(_) {
- if (_simulation == null)
+ if (!_animation.isAnimating)
settleScrollOffset();
}
@@ -162,7 +162,7 @@ abstract class Scrollable extends StatefulComponent {
double eventVelocity = direction == ScrollDirection.horizontal
? -event.velocityX
: -event.velocityY;
- _startSimulation(_createParticle(_velocityForFlingGesture(eventVelocity)));
+ _startSimulation(velocity: _velocityForFlingGesture(eventVelocity));
}
void _handleFlingCancel(sky.GestureEvent event) {
« no previous file with comments | « sky/sdk/lib/widgets/fixed_height_scrollable.dart ('k') | sky/sdk/lib/widgets/tabs.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698