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

Unified Diff: sky/sdk/lib/widgets/ink_well.dart

Issue 1231893006: Update ink splash to new animation system (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: less final Created 5 years, 5 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
« no previous file with comments | « sky/sdk/lib/animation/animation_performance.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/widgets/ink_well.dart
diff --git a/sky/sdk/lib/widgets/ink_well.dart b/sky/sdk/lib/widgets/ink_well.dart
index 5feae55f9edf3574b75a13f4daa62b12607e75a6..c182eafe7ed601ab0f472046df844f7760d2afb6 100644
--- a/sky/sdk/lib/widgets/ink_well.dart
+++ b/sky/sdk/lib/widgets/ink_well.dart
@@ -5,7 +5,7 @@
import 'dart:math' as math;
import 'dart:sky' as sky;
-import '../animation/animated_value.dart';
+import '../animation/animation_performance.dart';
import '../animation/curves.dart';
import '../rendering/box.dart';
import '../rendering/object.dart';
@@ -13,9 +13,9 @@ import 'basic.dart';
import 'widget.dart';
const int _kSplashInitialOpacity = 0x80;
-const double _kSplashInitialDelay = 0.0; // we could delay initially in case the user scrolls
-const double _kSplashInitialSize = 0.0;
+const double _kSplashCancelledVelocity = 0.3;
const double _kSplashConfirmedVelocity = 0.3;
+const double _kSplashInitialSize = 0.0;
const double _kSplashUnconfirmedVelocity = 0.1;
double _getSplashTargetSize(Size bounds, Point position) {
@@ -26,10 +26,14 @@ double _getSplashTargetSize(Size bounds, Point position) {
class InkSplash {
InkSplash(this.pointer, this.position, this.well) {
_targetRadius = _getSplashTargetSize(well.size, position);
- double duration = _targetRadius / _kSplashUnconfirmedVelocity;
- _radius = new AnimatedValue(_kSplashInitialSize, onChange: _handleRadiusChange);
- _radius.animateTo(_targetRadius, duration, curve: easeOut,
- initialDelay: _kSplashInitialDelay);
+ _radius = new AnimatedType<double>(
+ _kSplashInitialSize, end: _targetRadius, curve: easeOut);
+
+ _performance = new AnimationPerformance()
+ ..variable = _radius
+ ..duration = new Duration(milliseconds: (_targetRadius / _kSplashUnconfirmedVelocity).floor())
+ ..addListener(_handleRadiusChange)
+ ..play();
}
final int pointer;
@@ -37,13 +41,24 @@ class InkSplash {
final RenderInkWell well;
double _targetRadius;
- AnimatedValue _radius;
+ double _pinnedRadius;
+ AnimatedType<double> _radius;
+ AnimationPerformance _performance;
+
+ void _updateVelocity(double velocity) {
+ int duration = (_targetRadius / velocity).floor();
+ _performance
+ ..duration = new Duration(milliseconds: duration)
+ ..play();
+ }
void confirm() {
- double duration = (_targetRadius - _radius.value) / _kSplashConfirmedVelocity;
- if (duration <= 0.0)
- return;
- _radius.animateTo(_targetRadius, duration, curve: easeOut);
+ _updateVelocity(_kSplashConfirmedVelocity);
+ }
+
+ void cancel() {
+ _updateVelocity(_kSplashCancelledVelocity);
+ _pinnedRadius = _radius.value;
}
void _handleRadiusChange() {
@@ -55,7 +70,8 @@ class InkSplash {
void paint(PaintingCanvas canvas) {
int opacity = (_kSplashInitialOpacity * (1.0 - (_radius.value / _targetRadius))).floor();
sky.Paint paint = new sky.Paint()..color = new sky.Color(opacity << 24);
- canvas.drawCircle(position, _radius.value, paint);
+ double radius = _pinnedRadius == null ? _radius.value : _pinnedRadius;
+ canvas.drawCircle(position, radius, paint);
}
}
@@ -84,9 +100,18 @@ class RenderInkWell extends RenderProxyBox {
markNeedsPaint();
}
- void _confirmSplash(int pointer) {
+ void _forEachSplash(int pointer, Function callback) {
_splashes.where((splash) => splash.pointer == pointer)
- .forEach((splash) { splash.confirm(); });
+ .forEach(callback);
+ }
+
+ void _confirmSplash(int pointer) {
+ _forEachSplash(pointer, (splash) { splash.confirm(); });
+ markNeedsPaint();
+ }
+
+ void _cancelSplash(int pointer) {
+ _forEachSplash(pointer, (splash) { splash.cancel(); });
markNeedsPaint();
}
« no previous file with comments | « sky/sdk/lib/animation/animation_performance.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698