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

Side by Side Diff: sky/sdk/lib/framework/components2/ink_splash.dart

Issue 1172033003: Add a basic InkWell implementation (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: rm examples/raw/ink_well.dart Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | sky/sdk/lib/framework/components2/ink_well.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 import '../animation/animated_value.dart';
6 import '../animation/curves.dart';
7 import '../fn2.dart';
8 import '../theme/view_configuration.dart' as config;
9 import 'dart:async';
10 import 'dart:math' as math;
11
12 const double _kSplashConfirmedDuration = 350.0;
13 const double _kSplashUnconfirmedDuration = config.kDefaultLongPressTimeout;
14 const double _kSplashAbortDuration = 100.0;
15 const double _kSplashInitialDelay = 0.0; // we could delay initially in case the user scrolls
16
17 double _getSplashTargetSize(Rect rect, double x, double y) {
18 return 2.0 * math.max(math.max(x - rect.x, rect.x + rect.width - x),
19 math.max(y - rect.y, rect.y + rect.height - y));
20 }
21
22 class SplashController {
23
24 SplashController(Rect rect, double x, double y,
25 { this.pointer, Function onDone })
26 : _offsetX = x - rect.x,
27 _offsetY = y - rect.y,
28 _targetSize = _getSplashTargetSize(rect, x, y) {
29
30 _styleStream = _size.onValueChanged.map((p) {
31 if (p == _targetSize) {
32 onDone();
33 }
34 double size;
35 if (_growing) {
36 size = p;
37 _lastSize = p;
38 } else {
39 size = _lastSize;
40 }
41 return '''
42 top: ${_offsetY - size/2}px;
43 left: ${_offsetX - size/2}px;
44 width: ${size}px;
45 height: ${size}px;
46 border-radius: ${size}px;
47 opacity: ${1.0 - (p / _targetSize)};''';
48 });
49
50 start();
51 }
52
53 final int pointer;
54 Stream<String> get onStyleChanged => _styleStream;
55
56 final AnimatedValue _size = new AnimatedValue(0.0);
57 double _offsetX;
58 double _offsetY;
59 double _lastSize = 0.0;
60 bool _growing = true;
61 double _targetSize;
62 Stream<String> _styleStream;
63
64 void start() {
65 _size.animateTo(_targetSize, _kSplashUnconfirmedDuration, curve: easeOut, in itialDelay: _kSplashInitialDelay);
66 }
67
68 void confirm() {
69 double fractionRemaining = (_targetSize - _size.value) / _targetSize;
70 double duration = fractionRemaining * _kSplashConfirmedDuration;
71 if (duration <= 0.0)
72 return;
73 _size.animateTo(_targetSize, duration, curve: easeOut);
74 }
75
76 void abort() {
77 _growing = false;
78 double durationRemaining = _size.remainingTime;
79 if (durationRemaining <= _kSplashAbortDuration)
80 return;
81 _size.animateTo(_targetSize, _kSplashAbortDuration, curve: easeOut);
82 }
83
84 void cancel() {
85 _size.stop();
86 }
87
88 }
89
90 class InkSplash extends Component {
91
92 InkSplash(Stream<String> onStyleChanged)
93 : onStyleChanged = onStyleChanged,
94 super(stateful: true, key: onStyleChanged.hashCode);
95
96 static final Style _clipperStyle = new Style('''
97 position: absolute;
98 pointer-events: none;
99 overflow: hidden;
100 top: 0;
101 left: 0;
102 bottom: 0;
103 right: 0;''');
104
105 static final Style _splashStyle = new Style('''
106 position: absolute;
107 background-color: rgba(0, 0, 0, 0.2);''');
108
109 Stream<String> onStyleChanged;
110
111 double _offsetX;
112 double _offsetY;
113 String _inlineStyle;
114
115 bool _listening = false;
116
117 void _ensureListening() {
118 if (_listening)
119 return;
120
121 _listening = true;
122
123 onStyleChanged.listen((style) {
124 setState(() {
125 _inlineStyle = style;
126 });
127 });
128 }
129
130 UINode build() {
131 _ensureListening();
132
133 return new Container(
134 style: _clipperStyle,
135 children: [
136 new Container(
137 inlineStyle: _inlineStyle,
138 style: _splashStyle
139 )
140 ]
141 );
142 }
143
144 }
OLDNEW
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | sky/sdk/lib/framework/components2/ink_well.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698