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