| 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 '../animation/animated_value.dart'; | 5 import '../animation/animated_value.dart'; |
| 6 import '../animation/curves.dart'; | 6 import '../animation/curves.dart'; |
| 7 import '../fn2.dart'; | 7 import '../fn2.dart'; |
| 8 import '../rendering/box.dart'; | 8 import '../rendering/box.dart'; |
| 9 import '../rendering/flex.dart'; | 9 import '../rendering/flex.dart'; |
| 10 import '../rendering/object.dart'; | 10 import '../rendering/object.dart'; |
| 11 import '../theme/view_configuration.dart' as config; | |
| 12 import 'dart:async'; | 11 import 'dart:async'; |
| 13 import 'dart:collection'; | 12 import 'dart:collection'; |
| 14 import 'dart:math' as math; | 13 import 'dart:math' as math; |
| 15 import 'dart:sky' as sky; | 14 import 'dart:sky' as sky; |
| 16 | 15 |
| 17 const int _kSplashInitialOpacity = 0x80; | 16 const int _kSplashInitialOpacity = 0x80; |
| 17 const double _kSplashInitialDelay = 0.0; // we could delay initially in case the
user scrolls |
| 18 const double _kSplashInitialSize = 0.0; | 18 const double _kSplashInitialSize = 0.0; |
| 19 const double _kSplashConfirmedDuration = 350.0; | 19 const double _kSplashConfirmedVelocity = 0.3; |
| 20 const double _kSplashUnconfirmedDuration = config.kDefaultLongPressTimeout; | 20 const double _kSplashUnconfirmedVelocity = 0.1; |
| 21 const double _kSplashInitialDelay = 0.0; // we could delay initially in case the
user scrolls | |
| 22 | 21 |
| 23 double _getSplashTargetSize(Size bounds, Point position) { | 22 double _getSplashTargetSize(Size bounds, Point position) { |
| 24 return 2.0 * math.max(math.max(position.x, bounds.width - position.x), | 23 return math.max(math.max(position.x, bounds.width - position.x), |
| 25 math.max(position.y, bounds.height - position.y)); | 24 math.max(position.y, bounds.height - position.y)); |
| 26 } | 25 } |
| 27 | 26 |
| 28 class InkSplash { | 27 class InkSplash { |
| 29 InkSplash(this.pointer, this.position, this.well) { | 28 InkSplash(this.pointer, this.position, this.well) { |
| 30 _targetRadius = _getSplashTargetSize(well.size, position); | 29 _targetRadius = _getSplashTargetSize(well.size, position); |
| 30 double duration = _targetRadius / _kSplashUnconfirmedVelocity; |
| 31 _radius = new AnimatedValue(_kSplashInitialSize, onChange: _handleRadiusChan
ge); | 31 _radius = new AnimatedValue(_kSplashInitialSize, onChange: _handleRadiusChan
ge); |
| 32 _radius.animateTo(_targetRadius, _kSplashUnconfirmedDuration, | 32 _radius.animateTo(_targetRadius, duration, curve: easeOut, |
| 33 curve: easeOut, initialDelay: _kSplashInitialDelay); | 33 initialDelay: _kSplashInitialDelay); |
| 34 } | 34 } |
| 35 | 35 |
| 36 final int pointer; | 36 final int pointer; |
| 37 final Point position; | 37 final Point position; |
| 38 final RenderInkWell well; | 38 final RenderInkWell well; |
| 39 | 39 |
| 40 double _targetRadius; | 40 double _targetRadius; |
| 41 AnimatedValue _radius; | 41 AnimatedValue _radius; |
| 42 | 42 |
| 43 void confirm() { | 43 void confirm() { |
| 44 double fractionRemaining = (_targetRadius - _radius.value) / _targetRadius; | 44 double duration = (_targetRadius - _radius.value) / _kSplashConfirmedVelocit
y; |
| 45 double duration = fractionRemaining * _kSplashConfirmedDuration; | |
| 46 if (duration <= 0.0) | 45 if (duration <= 0.0) |
| 47 return; | 46 return; |
| 48 _radius.animateTo(_targetRadius, duration, curve: easeOut); | 47 _radius.animateTo(_targetRadius, duration, curve: easeOut); |
| 49 } | 48 } |
| 50 | 49 |
| 51 void _handleRadiusChange() { | 50 void _handleRadiusChange() { |
| 52 if (_radius.value == _targetRadius) | 51 if (_radius.value == _targetRadius) |
| 53 well._splashes.remove(this); | 52 well._splashes.remove(this); |
| 54 well.markNeedsPaint(); | 53 well.markNeedsPaint(); |
| 55 } | 54 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 UINode build() { | 117 UINode build() { |
| 119 return new InkWellWrapper( | 118 return new InkWellWrapper( |
| 120 child: new FlexContainer( | 119 child: new FlexContainer( |
| 121 direction: FlexDirection.horizontal, | 120 direction: FlexDirection.horizontal, |
| 122 justifyContent: FlexJustifyContent.center, | 121 justifyContent: FlexJustifyContent.center, |
| 123 children: children | 122 children: children |
| 124 ) | 123 ) |
| 125 ); | 124 ); |
| 126 } | 125 } |
| 127 } | 126 } |
| OLD | NEW |