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:math' as math; | 5 import 'dart:math' as math; |
6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
7 | 7 |
8 import '../animation/generators.dart'; | 8 import '../animation/generators.dart'; |
9 import '../animation/mechanics.dart'; | 9 import '../animation/mechanics.dart'; |
10 import '../animation/scroll_behavior.dart'; | 10 import '../animation/scroll_behavior.dart'; |
| 11 import '../theme/colors.dart' as colors; |
| 12 import '../theme/theme_data.dart'; |
11 import '../theme/view_configuration.dart' as config; | 13 import '../theme/view_configuration.dart' as config; |
12 import 'basic.dart'; | 14 import 'basic.dart'; |
13 import 'material.dart'; | 15 import 'material.dart'; |
| 16 import 'theme.dart'; |
14 | 17 |
15 const double _kMillisecondsPerSecond = 1000.0; | 18 const double _kMillisecondsPerSecond = 1000.0; |
16 | 19 |
17 double _velocityForFlingGesture(sky.GestureEvent event) { | 20 double _velocityForFlingGesture(sky.GestureEvent event) { |
18 return math.max(-config.kMaxFlingVelocity, math.min(config.kMaxFlingVelocity, | 21 return math.max(-config.kMaxFlingVelocity, math.min(config.kMaxFlingVelocity, |
19 -event.velocityY)) / _kMillisecondsPerSecond; | 22 -event.velocityY)) / _kMillisecondsPerSecond; |
20 } | 23 } |
21 | 24 |
22 abstract class ScrollClient { | 25 abstract class ScrollClient { |
23 bool ancestorScrolled(Scrollable ancestor); | 26 bool ancestorScrolled(Scrollable ancestor); |
24 } | 27 } |
25 | 28 |
26 abstract class Scrollable extends Component { | 29 abstract class Scrollable extends Component { |
27 | 30 |
28 Scrollable({ String key, Color this.backgroundColor }) | 31 Scrollable({ String key, Color this.backgroundColor }) |
29 : super(key: key, stateful: true); | 32 : super(key: key, stateful: true); |
30 | 33 |
31 Color backgroundColor; | 34 Color backgroundColor; |
32 | 35 |
33 void syncFields(Scrollable source) { | 36 void syncFields(Scrollable source) { |
34 backgroundColor = source.backgroundColor; | 37 backgroundColor = source.backgroundColor; |
35 } | 38 } |
36 | 39 |
| 40 Color get _nonNullBackgroundColor { |
| 41 if (backgroundColor != null) |
| 42 return backgroundColor; |
| 43 switch (Theme.of(this).brightness) { |
| 44 case ThemeBrightness.light: |
| 45 return colors.Grey[50]; |
| 46 case ThemeBrightness.dark: |
| 47 return colors.Grey[850]; |
| 48 } |
| 49 } |
| 50 |
37 double _scrollOffset = 0.0; | 51 double _scrollOffset = 0.0; |
38 double get scrollOffset => _scrollOffset; | 52 double get scrollOffset => _scrollOffset; |
39 | 53 |
40 ScrollBehavior _scrollBehavior; | 54 ScrollBehavior _scrollBehavior; |
41 ScrollBehavior createScrollBehavior(); | 55 ScrollBehavior createScrollBehavior(); |
42 ScrollBehavior get scrollBehavior { | 56 ScrollBehavior get scrollBehavior { |
43 if (_scrollBehavior == null) | 57 if (_scrollBehavior == null) |
44 _scrollBehavior = createScrollBehavior(); | 58 _scrollBehavior = createScrollBehavior(); |
45 return _scrollBehavior; | 59 return _scrollBehavior; |
46 } | 60 } |
47 | 61 |
48 Simulation _simulation; | 62 Simulation _simulation; |
49 | 63 |
50 Widget buildContent(); | 64 Widget buildContent(); |
51 | 65 |
52 Widget build() { | 66 Widget build() { |
53 return new Listener( | 67 return new Listener( |
54 child: new Material( | 68 child: new Material( |
55 child: buildContent(), | 69 child: buildContent(), |
56 edge: MaterialEdge.canvas, | 70 edge: MaterialEdge.canvas, |
57 color: backgroundColor | 71 color: _nonNullBackgroundColor |
58 ), | 72 ), |
59 onPointerDown: _handlePointerDown, | 73 onPointerDown: _handlePointerDown, |
60 onPointerUp: _handlePointerUpOrCancel, | 74 onPointerUp: _handlePointerUpOrCancel, |
61 onPointerCancel: _handlePointerUpOrCancel, | 75 onPointerCancel: _handlePointerUpOrCancel, |
62 onGestureFlingStart: _handleFlingStart, | 76 onGestureFlingStart: _handleFlingStart, |
63 onGestureFlingCancel: _handleFlingCancel, | 77 onGestureFlingCancel: _handleFlingCancel, |
64 onGestureScrollUpdate: _handleScrollUpdate, | 78 onGestureScrollUpdate: _handleScrollUpdate, |
65 onWheel: _handleWheel | 79 onWheel: _handleWheel |
66 ); | 80 ); |
67 } | 81 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 168 |
155 void _handleFlingCancel(sky.GestureEvent event) { | 169 void _handleFlingCancel(sky.GestureEvent event) { |
156 _startSimulation(_createParticle()); | 170 _startSimulation(_createParticle()); |
157 } | 171 } |
158 | 172 |
159 void _handleWheel(sky.WheelEvent event) { | 173 void _handleWheel(sky.WheelEvent event) { |
160 scrollBy(-event.offsetY); | 174 scrollBy(-event.offsetY); |
161 } | 175 } |
162 | 176 |
163 } | 177 } |
OLD | NEW |