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

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

Issue 1221673006: Scrollable TabBar Version 0 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Updated per review feedback 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/example/widgets/tabs.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 a6c4023a356507f47251fd4354077a9ef3b1ee9c..34e1e07e1eafe0017bba18bea7301954a47a3f1a 100644
--- a/sky/sdk/lib/widgets/scrollable.dart
+++ b/sky/sdk/lib/widgets/scrollable.dart
@@ -2,7 +2,6 @@
// 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:sky' as sky;
import '../animation/generators.dart';
@@ -14,24 +13,31 @@ import 'material.dart';
const double _kMillisecondsPerSecond = 1000.0;
-double _velocityForFlingGesture(sky.GestureEvent event) {
- return math.max(-config.kMaxFlingVelocity, math.min(config.kMaxFlingVelocity,
- -event.velocityY)) / _kMillisecondsPerSecond;
+double _velocityForFlingGesture(double eventVelocity) {
+ return eventVelocity.clamp(-config.kMaxFlingVelocity, config.kMaxFlingVelocity) /
+ _kMillisecondsPerSecond;
}
abstract class ScrollClient {
bool ancestorScrolled(Scrollable ancestor);
}
+enum ScrollDirection { vertical, horizontal }
+
abstract class Scrollable extends Component {
- Scrollable({ String key, Color this.backgroundColor })
- : super(key: key, stateful: true);
+ Scrollable({
+ String key,
+ this.backgroundColor,
+ this.direction: ScrollDirection.vertical
+ }) : super(key: key, stateful: true);
Color backgroundColor;
+ ScrollDirection direction;
void syncFields(Scrollable source) {
backgroundColor = source.backgroundColor;
+ direction == source.direction;
}
double _scrollOffset = 0.0;
@@ -145,11 +151,14 @@ abstract class Scrollable extends Component {
}
void _handleScrollUpdate(sky.GestureEvent event) {
- scrollBy(-event.dy);
+ scrollBy(direction == ScrollDirection.horizontal ? event.dx : -event.dy);
}
void _handleFlingStart(sky.GestureEvent event) {
- _startSimulation(_createParticle(_velocityForFlingGesture(event)));
+ double eventVelocity = direction == ScrollDirection.horizontal
+ ? -event.velocityX
+ : -event.velocityY;
+ _startSimulation(_createParticle(_velocityForFlingGesture(eventVelocity)));
}
void _handleFlingCancel(sky.GestureEvent event) {
« no previous file with comments | « sky/sdk/example/widgets/tabs.dart ('k') | sky/sdk/lib/widgets/tabs.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698