| OLD | NEW |
| 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:sky' as sky; | 5 import 'dart:sky' as sky; |
| 6 | 6 |
| 7 import 'package:newton/newton.dart'; | 7 import 'package:newton/newton.dart'; |
| 8 import 'package:sky/animation/animated_simulation.dart'; | 8 import 'package:sky/animation/animated_simulation.dart'; |
| 9 import 'package:sky/animation/scroll_behavior.dart'; | 9 import 'package:sky/animation/scroll_behavior.dart'; |
| 10 import 'package:sky/theme/view_configuration.dart' as config; | 10 import 'package:sky/theme/view_configuration.dart' as config; |
| 11 import 'package:sky/widgets/basic.dart'; | 11 import 'package:sky/widgets/basic.dart'; |
| 12 import 'package:sky/widgets/material.dart'; | |
| 13 | 12 |
| 14 const double _kMillisecondsPerSecond = 1000.0; | 13 const double _kMillisecondsPerSecond = 1000.0; |
| 15 | 14 |
| 16 double _velocityForFlingGesture(double eventVelocity) { | 15 double _velocityForFlingGesture(double eventVelocity) { |
| 17 return eventVelocity.clamp(-config.kMaxFlingVelocity, config.kMaxFlingVelocity
) / | 16 return eventVelocity.clamp(-config.kMaxFlingVelocity, config.kMaxFlingVelocity
) / |
| 18 _kMillisecondsPerSecond; | 17 _kMillisecondsPerSecond; |
| 19 } | 18 } |
| 20 | 19 |
| 21 abstract class ScrollClient { | 20 abstract class ScrollClient { |
| 22 bool ancestorScrolled(Scrollable ancestor); | 21 bool ancestorScrolled(Scrollable ancestor); |
| 23 } | 22 } |
| 24 | 23 |
| 25 enum ScrollDirection { vertical, horizontal } | 24 enum ScrollDirection { vertical, horizontal } |
| 26 | 25 |
| 27 abstract class Scrollable extends StatefulComponent { | 26 abstract class Scrollable extends StatefulComponent { |
| 28 | 27 |
| 29 Scrollable({ | 28 Scrollable({ |
| 30 String key, | 29 String key, |
| 31 this.backgroundColor, | |
| 32 this.direction: ScrollDirection.vertical | 30 this.direction: ScrollDirection.vertical |
| 33 }) : super(key: key); | 31 }) : super(key: key); |
| 34 | 32 |
| 35 Color backgroundColor; | |
| 36 ScrollDirection direction; | 33 ScrollDirection direction; |
| 37 | 34 |
| 38 void initState() { | 35 void initState() { |
| 39 _animation = new AnimatedSimulation(_tickScrollOffset); | 36 _animation = new AnimatedSimulation(_tickScrollOffset); |
| 40 } | 37 } |
| 41 | 38 |
| 42 void syncFields(Scrollable source) { | 39 void syncFields(Scrollable source) { |
| 43 backgroundColor = source.backgroundColor; | |
| 44 direction == source.direction; | 40 direction == source.direction; |
| 45 } | 41 } |
| 46 | 42 |
| 47 double _scrollOffset = 0.0; | 43 double _scrollOffset = 0.0; |
| 48 double get scrollOffset => _scrollOffset; | 44 double get scrollOffset => _scrollOffset; |
| 49 | 45 |
| 50 ScrollBehavior _scrollBehavior; | 46 ScrollBehavior _scrollBehavior; |
| 51 ScrollBehavior createScrollBehavior(); | 47 ScrollBehavior createScrollBehavior(); |
| 52 ScrollBehavior get scrollBehavior { | 48 ScrollBehavior get scrollBehavior { |
| 53 if (_scrollBehavior == null) | 49 if (_scrollBehavior == null) |
| 54 _scrollBehavior = createScrollBehavior(); | 50 _scrollBehavior = createScrollBehavior(); |
| 55 return _scrollBehavior; | 51 return _scrollBehavior; |
| 56 } | 52 } |
| 57 | 53 |
| 58 AnimatedSimulation _animation; | 54 AnimatedSimulation _animation; |
| 59 | 55 |
| 60 Widget buildContent(); | 56 Widget buildContent(); |
| 61 | 57 |
| 62 Widget build() { | 58 Widget build() { |
| 63 return new Listener( | 59 return new Listener( |
| 64 child: new Material( | 60 child: buildContent(), |
| 65 type: MaterialType.canvas, | |
| 66 child: buildContent(), | |
| 67 color: backgroundColor | |
| 68 ), | |
| 69 onPointerDown: _handlePointerDown, | 61 onPointerDown: _handlePointerDown, |
| 70 onPointerUp: _handlePointerUpOrCancel, | 62 onPointerUp: _handlePointerUpOrCancel, |
| 71 onPointerCancel: _handlePointerUpOrCancel, | 63 onPointerCancel: _handlePointerUpOrCancel, |
| 72 onGestureFlingStart: _handleFlingStart, | 64 onGestureFlingStart: _handleFlingStart, |
| 73 onGestureFlingCancel: _handleFlingCancel, | 65 onGestureFlingCancel: _handleFlingCancel, |
| 74 onGestureScrollUpdate: _handleScrollUpdate, | 66 onGestureScrollUpdate: _handleScrollUpdate, |
| 75 onWheel: _handleWheel | 67 onWheel: _handleWheel |
| 76 ); | 68 ); |
| 77 } | 69 } |
| 78 | 70 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 159 |
| 168 void _handleFlingCancel(sky.GestureEvent event) { | 160 void _handleFlingCancel(sky.GestureEvent event) { |
| 169 settleScrollOffset(); | 161 settleScrollOffset(); |
| 170 } | 162 } |
| 171 | 163 |
| 172 void _handleWheel(sky.WheelEvent event) { | 164 void _handleWheel(sky.WheelEvent event) { |
| 173 scrollBy(-event.offsetY); | 165 scrollBy(-event.offsetY); |
| 174 } | 166 } |
| 175 | 167 |
| 176 } | 168 } |
| OLD | NEW |