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