| 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 '../animation/generators.dart'; | 7 import '../animation/generators.dart'; |
| 8 import '../animation/mechanics.dart'; | 8 import '../animation/mechanics.dart'; |
| 9 import '../animation/scroll_behavior.dart'; | 9 import '../animation/scroll_behavior.dart'; |
| 10 import '../theme/view_configuration.dart' as config; | 10 import '../theme/view_configuration.dart' as config; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 Scrollable({ | 29 Scrollable({ |
| 30 String key, | 30 String key, |
| 31 this.backgroundColor, | 31 this.backgroundColor, |
| 32 this.direction: ScrollDirection.vertical | 32 this.direction: ScrollDirection.vertical |
| 33 }) : super(key: key); | 33 }) : super(key: key); |
| 34 | 34 |
| 35 Color backgroundColor; | 35 Color backgroundColor; |
| 36 ScrollDirection direction; | 36 ScrollDirection direction; |
| 37 | 37 |
| 38 @override |
| 38 void syncFields(Scrollable source) { | 39 void syncFields(Scrollable source) { |
| 39 backgroundColor = source.backgroundColor; | 40 backgroundColor = source.backgroundColor; |
| 40 direction == source.direction; | 41 direction == source.direction; |
| 41 } | 42 } |
| 42 | 43 |
| 43 double _scrollOffset = 0.0; | 44 double _scrollOffset = 0.0; |
| 44 double get scrollOffset => _scrollOffset; | 45 double get scrollOffset => _scrollOffset; |
| 45 | 46 |
| 46 ScrollBehavior _scrollBehavior; | 47 ScrollBehavior _scrollBehavior; |
| 47 ScrollBehavior createScrollBehavior(); | 48 ScrollBehavior createScrollBehavior(); |
| 48 ScrollBehavior get scrollBehavior { | 49 ScrollBehavior get scrollBehavior { |
| 49 if (_scrollBehavior == null) | 50 if (_scrollBehavior == null) |
| 50 _scrollBehavior = createScrollBehavior(); | 51 _scrollBehavior = createScrollBehavior(); |
| 51 return _scrollBehavior; | 52 return _scrollBehavior; |
| 52 } | 53 } |
| 53 | 54 |
| 54 Simulation _simulation; | 55 Simulation _simulation; |
| 55 | 56 |
| 56 Widget buildContent(); | 57 Widget buildContent(); |
| 57 | 58 |
| 59 @override |
| 58 Widget build() { | 60 Widget build() { |
| 59 return new Listener( | 61 return new Listener( |
| 60 child: new Material( | 62 child: new Material( |
| 61 type: MaterialType.canvas, | 63 type: MaterialType.canvas, |
| 62 child: buildContent(), | 64 child: buildContent(), |
| 63 color: backgroundColor | 65 color: backgroundColor |
| 64 ), | 66 ), |
| 65 onPointerDown: _handlePointerDown, | 67 onPointerDown: _handlePointerDown, |
| 66 onPointerUp: _handlePointerUpOrCancel, | 68 onPointerUp: _handlePointerUpOrCancel, |
| 67 onPointerCancel: _handlePointerUpOrCancel, | 69 onPointerCancel: _handlePointerUpOrCancel, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 }); | 112 }); |
| 111 } | 113 } |
| 112 return true; | 114 return true; |
| 113 } | 115 } |
| 114 | 116 |
| 115 bool scrollBy(double scrollDelta) { | 117 bool scrollBy(double scrollDelta) { |
| 116 var newScrollOffset = scrollBehavior.applyCurve(_scrollOffset, scrollDelta); | 118 var newScrollOffset = scrollBehavior.applyCurve(_scrollOffset, scrollDelta); |
| 117 return scrollTo(newScrollOffset); | 119 return scrollTo(newScrollOffset); |
| 118 } | 120 } |
| 119 | 121 |
| 122 @override |
| 120 void didUnmount() { | 123 void didUnmount() { |
| 121 _stopSimulation(); | 124 _stopSimulation(); |
| 122 super.didUnmount(); | 125 super.didUnmount(); |
| 123 } | 126 } |
| 124 | 127 |
| 125 void _stopSimulation() { | 128 void _stopSimulation() { |
| 126 if (_simulation == null) | 129 if (_simulation == null) |
| 127 return; | 130 return; |
| 128 _simulation.cancel(); | 131 _simulation.cancel(); |
| 129 _simulation = null; | 132 _simulation = null; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 166 |
| 164 void _handleFlingCancel(sky.GestureEvent event) { | 167 void _handleFlingCancel(sky.GestureEvent event) { |
| 165 _startSimulation(_createParticle()); | 168 _startSimulation(_createParticle()); |
| 166 } | 169 } |
| 167 | 170 |
| 168 void _handleWheel(sky.WheelEvent event) { | 171 void _handleWheel(sky.WheelEvent event) { |
| 169 scrollBy(-event.offsetY); | 172 scrollBy(-event.offsetY); |
| 170 } | 173 } |
| 171 | 174 |
| 172 } | 175 } |
| OLD | NEW |