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/curves.dart'; | 6 import '../animation/curves.dart'; |
6 import '../animation/generators.dart'; | 7 import '../animation/generators.dart'; |
7 import '../fn.dart'; | 8 import '../fn.dart'; |
| 9 import '../theme/view-configuration.dart' as config; |
8 import 'dart:async'; | 10 import 'dart:async'; |
| 11 import 'dart:math' as math; |
9 import 'dart:sky' as sky; | 12 import 'dart:sky' as sky; |
10 | 13 |
11 const double _kSplashSize = 400.0; | 14 const double _kSplashConfirmedDuration = 350.0; |
12 const double _kSplashDuration = 500.0; | 15 const double _kSplashUnconfirmedDuration = config.kDefaultLongPressTimeout; |
13 | 16 |
14 class SplashAnimation { | 17 double _getSplashTargetSize(sky.ClientRect rect, double x, double y) { |
15 AnimationGenerator _animation; | 18 return 2.0 * math.max(math.max(x - rect.left, rect.right - x), |
| 19 math.max(y - rect.top, rect.bottom - y)); |
| 20 } |
| 21 |
| 22 class SplashController { |
| 23 final int pointer; |
| 24 Stream<String> get onStyleChanged => _styleStream; |
| 25 |
| 26 final AnimatedValue _size = new AnimatedValue(0.0); |
16 double _offsetX; | 27 double _offsetX; |
17 double _offsetY; | 28 double _offsetY; |
| 29 double _targetSize; |
| 30 Stream<String> _styleStream; |
18 | 31 |
19 Stream<String> _styleChanged; | 32 void start() { |
| 33 _size.animateTo(_targetSize, _kSplashUnconfirmedDuration, curve: easeOut); |
| 34 } |
20 | 35 |
21 Stream<String> get onStyleChanged => _styleChanged; | 36 void confirm() { |
| 37 double fractionRemaining = (_targetSize - _size.value) / _targetSize; |
| 38 double duration = fractionRemaining * _kSplashConfirmedDuration; |
| 39 if (duration <= 0.0) |
| 40 return; |
| 41 _size.animateTo(_targetSize, duration, curve: easeOut); |
| 42 } |
22 | 43 |
23 void cancel() => _animation.cancel(); | 44 void cancel() { |
| 45 _size.stop(); |
| 46 } |
24 | 47 |
25 SplashAnimation(sky.ClientRect rect, double x, double y, | 48 SplashController(sky.ClientRect rect, double x, double y, |
26 { Function onDone }) | 49 { this.pointer, Function onDone }) |
27 : _offsetX = x - rect.left, | 50 : _offsetX = x - rect.left, |
28 _offsetY = y - rect.top { | 51 _offsetY = y - rect.top, |
| 52 _targetSize = _getSplashTargetSize(rect, x, y) { |
29 | 53 |
30 _animation = new AnimationGenerator( | 54 _styleStream = _size.onValueChanged.map((p) { |
31 duration:_kSplashDuration, | 55 if (p == _targetSize) { |
32 end: _kSplashSize, | 56 onDone(); |
33 curve: easeOut, | 57 } |
34 onDone: onDone); | 58 return ''' |
| 59 top: ${_offsetY - p/2}px; |
| 60 left: ${_offsetX - p/2}px; |
| 61 width: ${p}px; |
| 62 height: ${p}px; |
| 63 border-radius: ${p}px; |
| 64 opacity: ${1.0 - (p / _targetSize)};'''; |
| 65 }); |
35 | 66 |
36 _styleChanged = _animation.onTick.map((p) => ''' | 67 start(); |
37 top: ${_offsetY - p/2}px; | |
38 left: ${_offsetX - p/2}px; | |
39 width: ${p}px; | |
40 height: ${p}px; | |
41 border-radius: ${p}px; | |
42 opacity: ${1.0 - (p / _kSplashSize)}; | |
43 '''); | |
44 } | 68 } |
45 } | 69 } |
46 | 70 |
47 class InkSplash extends Component { | 71 class InkSplash extends Component { |
48 static final Style _clipperStyle = new Style(''' | 72 static final Style _clipperStyle = new Style(''' |
49 position: absolute; | 73 position: absolute; |
50 pointer-events: none; | 74 pointer-events: none; |
51 overflow: hidden; | 75 overflow: hidden; |
52 top: 0; | 76 top: 0; |
53 left: 0; | 77 left: 0; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 style: _clipperStyle, | 114 style: _clipperStyle, |
91 children: [ | 115 children: [ |
92 new Container( | 116 new Container( |
93 inlineStyle: _inlineStyle, | 117 inlineStyle: _inlineStyle, |
94 style: _splashStyle | 118 style: _splashStyle |
95 ) | 119 ) |
96 ] | 120 ] |
97 ); | 121 ); |
98 } | 122 } |
99 } | 123 } |
OLD | NEW |