OLD | NEW |
(Empty) | |
| 1 part of widgets; |
| 2 |
| 3 abstract class MaterialComponent extends Component { |
| 4 |
| 5 static const _splashesKey = const Object(); |
| 6 |
| 7 static Style _style = new Style(''' |
| 8 transform: translateX(0); |
| 9 position: absolute; |
| 10 top: 0; |
| 11 left: 0; |
| 12 right: 0; |
| 13 bottom: 0''' |
| 14 ); |
| 15 |
| 16 LinkedHashSet<SplashAnimation> _splashes; |
| 17 |
| 18 MaterialComponent({ Object key }) : super(key: key); |
| 19 |
| 20 Node render() { |
| 21 List<Node> children = []; |
| 22 |
| 23 if (_splashes != null) { |
| 24 children.addAll(_splashes.map((s) => new InkSplash(s.onStyleChanged))); |
| 25 } |
| 26 |
| 27 return new Container( |
| 28 style: _style, |
| 29 onScrollStart: _cancelSplashes, |
| 30 onWheel: _cancelSplashes, |
| 31 onPointerDown: _startSplash, |
| 32 children: children, |
| 33 key: _splashesKey |
| 34 ); |
| 35 } |
| 36 |
| 37 sky.ClientRect _getBoundingRect() => getRoot().getBoundingClientRect(); |
| 38 |
| 39 void _startSplash(sky.Event event) { |
| 40 setState(() { |
| 41 if (_splashes == null) { |
| 42 _splashes = new LinkedHashSet<SplashAnimation>(); |
| 43 } |
| 44 |
| 45 var splash; |
| 46 splash = new SplashAnimation(_getBoundingRect(), event.x, event.y, |
| 47 onDone: () { _splashDone(splash); }); |
| 48 |
| 49 _splashes.add(splash); |
| 50 }); |
| 51 } |
| 52 |
| 53 void _cancelSplashes(sky.Event event) { |
| 54 if (_splashes == null) { |
| 55 return; |
| 56 } |
| 57 |
| 58 setState(() { |
| 59 var splashes = _splashes; |
| 60 _splashes = null; |
| 61 splashes.forEach((s) { s.cancel(); }); |
| 62 }); |
| 63 } |
| 64 |
| 65 void willUnmount() { |
| 66 _cancelSplashes(null); |
| 67 } |
| 68 |
| 69 void _splashDone(SplashAnimation splash) { |
| 70 if (_splashes == null) { |
| 71 return; |
| 72 } |
| 73 |
| 74 setState(() { |
| 75 _splashes.remove(splash); |
| 76 if (_splashes.length == 0) { |
| 77 _splashes = null; |
| 78 } |
| 79 }); |
| 80 } |
| 81 } |
OLD | NEW |