Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: sky/framework/components/ink_splash.dart

Issue 1019023003: Improve Material ink effects (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sky/framework/components/ink_splash.dart
diff --git a/sky/framework/components/ink_splash.dart b/sky/framework/components/ink_splash.dart
index c768cb6fcccb116e1bd69422ea227dd8474be7b0..928dcdbc2ac9c7c23b04b043e965139cacf52937 100644
--- a/sky/framework/components/ink_splash.dart
+++ b/sky/framework/components/ink_splash.dart
@@ -2,45 +2,69 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+import '../animation/animated_value.dart';
import '../animation/curves.dart';
import '../animation/generators.dart';
import '../fn.dart';
+import '../theme/view-configuration.dart' as config;
import 'dart:async';
+import 'dart:math' as math;
import 'dart:sky' as sky;
-const double _kSplashSize = 400.0;
-const double _kSplashDuration = 500.0;
+const double _kSplashConfirmedDuration = 350.0;
+const double _kSplashUnconfirmedDuration = config.kDefaultLongPressTimeout;
-class SplashAnimation {
- AnimationGenerator _animation;
+double _getSplashTargetSize(sky.ClientRect rect, double x, double y) {
+ return 2.0 * math.max(math.max(x - rect.left, rect.right - x),
+ math.max(y - rect.top, rect.bottom - y));
+}
+
+class SplashController {
+ final int pointer;
+ Stream<String> get onStyleChanged => _styleStream;
+
+ final AnimatedValue _size = new AnimatedValue(0.0);
double _offsetX;
double _offsetY;
+ double _targetSize;
+ Stream<String> _styleStream;
- Stream<String> _styleChanged;
+ void start() {
+ _size.animateTo(_targetSize, _kSplashUnconfirmedDuration, curve: easeOut);
+ }
- Stream<String> get onStyleChanged => _styleChanged;
+ void confirm() {
+ double fractionRemaining = (_targetSize - _size.value) / _targetSize;
+ double duration = fractionRemaining * _kSplashConfirmedDuration;
+ if (duration <= 0.0)
+ return;
+ _size.animateTo(_targetSize, duration, curve: easeOut);
+ }
- void cancel() => _animation.cancel();
+ void cancel() {
+ _size.stop();
+ }
- SplashAnimation(sky.ClientRect rect, double x, double y,
- { Function onDone })
+ SplashController(sky.ClientRect rect, double x, double y,
+ { this.pointer, Function onDone })
: _offsetX = x - rect.left,
- _offsetY = y - rect.top {
-
- _animation = new AnimationGenerator(
- duration:_kSplashDuration,
- end: _kSplashSize,
- curve: easeOut,
- onDone: onDone);
-
- _styleChanged = _animation.onTick.map((p) => '''
- top: ${_offsetY - p/2}px;
- left: ${_offsetX - p/2}px;
- width: ${p}px;
- height: ${p}px;
- border-radius: ${p}px;
- opacity: ${1.0 - (p / _kSplashSize)};
- ''');
+ _offsetY = y - rect.top,
+ _targetSize = _getSplashTargetSize(rect, x, y) {
+
+ _styleStream = _size.onValueChanged.map((p) {
+ if (p == _targetSize) {
+ onDone();
+ }
+ return '''
+ top: ${_offsetY - p/2}px;
+ left: ${_offsetX - p/2}px;
+ width: ${p}px;
+ height: ${p}px;
+ border-radius: ${p}px;
+ opacity: ${1.0 - (p / _targetSize)};''';
+ });
+
+ start();
}
}

Powered by Google App Engine
This is Rietveld 408576698