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

Side by Side Diff: sky/framework/components/ink_well.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 unified diff | Download patch
OLDNEW
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 '../fn.dart'; 5 import '../fn.dart';
6 import '../theme/shadows.dart';
7 import 'dart:collection'; 6 import 'dart:collection';
8 import 'dart:sky' as sky; 7 import 'dart:sky' as sky;
9 import 'ink_splash.dart'; 8 import 'ink_splash.dart';
10 9
11 class Material extends Component { 10 class InkWell extends Component {
12 static final List<Style> shadowStyle = [ 11 LinkedHashSet<SplashController> _splashes;
13 null,
14 new Style('box-shadow: ${Shadow[1]}'),
15 new Style('box-shadow: ${Shadow[2]}'),
16 new Style('box-shadow: ${Shadow[3]}'),
17 new Style('box-shadow: ${Shadow[4]}'),
18 new Style('box-shadow: ${Shadow[5]}'),
19 ];
20
21 LinkedHashSet<SplashAnimation> _splashes;
22 12
23 Style style; 13 Style style;
24 String inlineStyle; 14 String inlineStyle;
25 List<Node> children; 15 List<Node> children;
26 int level;
27 16
28 Material({ 17 InkWell({ Object key, this.style, this.inlineStyle, this.children })
29 Object key, 18 : super(key: key);
30 this.style,
31 this.inlineStyle,
32 this.children,
33 this.level: 0 }) : super(key: key);
34 19
35 Node build() { 20 Node build() {
36 List<Node> childrenIncludingSplashes = []; 21 List<Node> childrenIncludingSplashes = [];
37 22
38 if (_splashes != null) { 23 if (_splashes != null) {
39 childrenIncludingSplashes.addAll( 24 childrenIncludingSplashes.addAll(
40 _splashes.map((s) => new InkSplash(s.onStyleChanged))); 25 _splashes.map((s) => new InkSplash(s.onStyleChanged)));
41 } 26 }
42 27
43 if (children != null) 28 if (children != null)
44 childrenIncludingSplashes.addAll(children); 29 childrenIncludingSplashes.addAll(children);
45 30
46 return new EventTarget( 31 return new EventTarget(
47 new Container( 32 new Container(
48 style: level > 0 ? style.extend(shadowStyle[level]) : style, 33 style: style,
49 inlineStyle: inlineStyle, 34 inlineStyle: inlineStyle,
50 children: childrenIncludingSplashes), 35 children: childrenIncludingSplashes),
51 onGestureScrollStart: _cancelSplashes, 36 onGestureTapDown: _startSplash,
52 onWheel: _cancelSplashes, 37 onGestureTap: _confirmSplash
53 onPointerDown: _startSplash
54 ); 38 );
55 } 39 }
56 40
57 sky.ClientRect _getBoundingRect() => (getRoot() as sky.Element).getBoundingCli entRect(); 41 sky.ClientRect _getBoundingRect() => (getRoot() as sky.Element).getBoundingCli entRect();
58 42
59 void _startSplash(sky.PointerEvent event) { 43 void _startSplash(sky.GestureEvent event) {
60 setState(() { 44 setState(() {
61 if (_splashes == null) { 45 if (_splashes == null)
62 _splashes = new LinkedHashSet<SplashAnimation>(); 46 _splashes = new LinkedHashSet<SplashController>();
63 }
64
65 var splash; 47 var splash;
66 splash = new SplashAnimation(_getBoundingRect(), event.x, event.y, 48 splash = new SplashController(_getBoundingRect(), event.x, event.y,
67 onDone: () { _splashDone(splash); }); 49 pointer: event.primaryPointer,
68 50 onDone: () { _splashDone(splash); });
69 _splashes.add(splash); 51 _splashes.add(splash);
70 }); 52 });
71 } 53 }
72 54
55 void _confirmSplash(sky.GestureEvent event) {
56 if (_splashes == null)
57 return;
58 _splashes.where((splash) => splash.pointer == event.primaryPointer)
59 .forEach((splash) { splash.confirm(); });
60 }
61
73 void _cancelSplashes(sky.Event event) { 62 void _cancelSplashes(sky.Event event) {
74 if (_splashes == null) { 63 if (_splashes == null)
75 return; 64 return;
76 }
77
78 setState(() { 65 setState(() {
79 var splashes = _splashes; 66 var splashes = _splashes;
80 _splashes = null; 67 _splashes = null;
81 splashes.forEach((s) { s.cancel(); }); 68 splashes.forEach((s) { s.cancel(); });
82 }); 69 });
83 } 70 }
84 71
85 void didUnmount() { 72 void didUnmount() {
86 _cancelSplashes(null); 73 _cancelSplashes(null);
87 } 74 }
88 75
89 void _splashDone(SplashAnimation splash) { 76 void _splashDone(SplashController splash) {
90 if (_splashes == null) { 77 if (_splashes == null)
91 return; 78 return;
92 }
93
94 setState(() { 79 setState(() {
95 _splashes.remove(splash); 80 _splashes.remove(splash);
96 if (_splashes.length == 0) { 81 if (_splashes.length == 0)
97 _splashes = null; 82 _splashes = null;
98 }
99 }); 83 });
100 } 84 }
101 } 85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698