| 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 '../animation/generators.dart'; | 7 import '../animation/generators.dart'; |
| 8 import '../fn.dart'; | 8 import '../fn.dart'; |
| 9 import '../theme/view-configuration.dart' as config; | 9 import '../theme/view-configuration.dart' as config; |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| 11 import 'dart:math' as math; | 11 import 'dart:math' as math; |
| 12 import 'dart:sky' as sky; | 12 import 'dart:sky' as sky; |
| 13 | 13 |
| 14 const double _kSplashConfirmedDuration = 350.0; | 14 const double _kSplashConfirmedDuration = 350.0; |
| 15 const double _kSplashUnconfirmedDuration = config.kDefaultLongPressTimeout; | 15 const double _kSplashUnconfirmedDuration = config.kDefaultLongPressTimeout; |
| 16 const double _kSplashAbortDuration = 100.0; |
| 17 const double _kSplashInitialDelay = 0.0; // we could delay initially in case the
user scrolls |
| 16 | 18 |
| 17 double _getSplashTargetSize(sky.ClientRect rect, double x, double y) { | 19 double _getSplashTargetSize(sky.ClientRect rect, double x, double y) { |
| 18 return 2.0 * math.max(math.max(x - rect.left, rect.right - x), | 20 return 2.0 * math.max(math.max(x - rect.left, rect.right - x), |
| 19 math.max(y - rect.top, rect.bottom - y)); | 21 math.max(y - rect.top, rect.bottom - y)); |
| 20 } | 22 } |
| 21 | 23 |
| 22 class SplashController { | 24 class SplashController { |
| 23 final int pointer; | 25 final int pointer; |
| 24 Stream<String> get onStyleChanged => _styleStream; | 26 Stream<String> get onStyleChanged => _styleStream; |
| 25 | 27 |
| 26 final AnimatedValue _size = new AnimatedValue(0.0); | 28 final AnimatedValue _size = new AnimatedValue(0.0); |
| 27 double _offsetX; | 29 double _offsetX; |
| 28 double _offsetY; | 30 double _offsetY; |
| 31 double _lastSize = 0.0; |
| 32 bool _growing = true; |
| 29 double _targetSize; | 33 double _targetSize; |
| 30 Stream<String> _styleStream; | 34 Stream<String> _styleStream; |
| 31 | 35 |
| 32 void start() { | 36 void start() { |
| 33 _size.animateTo(_targetSize, _kSplashUnconfirmedDuration, curve: easeOut); | 37 _size.animateTo(_targetSize, _kSplashUnconfirmedDuration, curve: easeOut, in
itialDelay: _kSplashInitialDelay); |
| 34 } | 38 } |
| 35 | 39 |
| 36 void confirm() { | 40 void confirm() { |
| 37 double fractionRemaining = (_targetSize - _size.value) / _targetSize; | 41 double fractionRemaining = (_targetSize - _size.value) / _targetSize; |
| 38 double duration = fractionRemaining * _kSplashConfirmedDuration; | 42 double duration = fractionRemaining * _kSplashConfirmedDuration; |
| 39 if (duration <= 0.0) | 43 if (duration <= 0.0) |
| 40 return; | 44 return; |
| 41 _size.animateTo(_targetSize, duration, curve: easeOut); | 45 _size.animateTo(_targetSize, duration, curve: easeOut); |
| 42 } | 46 } |
| 43 | 47 |
| 48 void abort() { |
| 49 _growing = false; |
| 50 double durationRemaining = _size.remainingTime; |
| 51 if (durationRemaining <= _kSplashAbortDuration) |
| 52 return; |
| 53 _size.animateTo(_targetSize, _kSplashAbortDuration, curve: easeOut); |
| 54 } |
| 55 |
| 44 void cancel() { | 56 void cancel() { |
| 45 _size.stop(); | 57 _size.stop(); |
| 46 } | 58 } |
| 47 | 59 |
| 48 SplashController(sky.ClientRect rect, double x, double y, | 60 SplashController(sky.ClientRect rect, double x, double y, |
| 49 { this.pointer, Function onDone }) | 61 { this.pointer, Function onDone }) |
| 50 : _offsetX = x - rect.left, | 62 : _offsetX = x - rect.left, |
| 51 _offsetY = y - rect.top, | 63 _offsetY = y - rect.top, |
| 52 _targetSize = _getSplashTargetSize(rect, x, y) { | 64 _targetSize = _getSplashTargetSize(rect, x, y) { |
| 53 | 65 |
| 54 _styleStream = _size.onValueChanged.map((p) { | 66 _styleStream = _size.onValueChanged.map((p) { |
| 55 if (p == _targetSize) { | 67 if (p == _targetSize) { |
| 56 onDone(); | 68 onDone(); |
| 57 } | 69 } |
| 70 double size; |
| 71 if (_growing) { |
| 72 sise = p; |
| 73 _lastSize = p; |
| 74 } else { |
| 75 size = _lastSize; |
| 76 } |
| 58 return ''' | 77 return ''' |
| 59 top: ${_offsetY - p/2}px; | 78 top: ${_offsetY - size/2}px; |
| 60 left: ${_offsetX - p/2}px; | 79 left: ${_offsetX - size/2}px; |
| 61 width: ${p}px; | 80 width: ${size}px; |
| 62 height: ${p}px; | 81 height: ${size}px; |
| 63 border-radius: ${p}px; | 82 border-radius: ${size}px; |
| 64 opacity: ${1.0 - (p / _targetSize)};'''; | 83 opacity: ${1.0 - (p / _targetSize)};'''; |
| 65 }); | 84 }); |
| 66 | 85 |
| 67 start(); | 86 start(); |
| 68 } | 87 } |
| 69 } | 88 } |
| 70 | 89 |
| 71 class InkSplash extends Component { | 90 class InkSplash extends Component { |
| 72 static final Style _clipperStyle = new Style(''' | 91 static final Style _clipperStyle = new Style(''' |
| 73 position: absolute; | 92 position: absolute; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 style: _clipperStyle, | 133 style: _clipperStyle, |
| 115 children: [ | 134 children: [ |
| 116 new Container( | 135 new Container( |
| 117 inlineStyle: _inlineStyle, | 136 inlineStyle: _inlineStyle, |
| 118 style: _splashStyle | 137 style: _splashStyle |
| 119 ) | 138 ) |
| 120 ] | 139 ] |
| 121 ); | 140 ); |
| 122 } | 141 } |
| 123 } | 142 } |
| OLD | NEW |