mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This CL is a warmup for using a more sophisticated gesture disambiguation. 1) Use gesturetap instead of click. We should probably remove click events because folks should use gesturetap to integrate with the gesture system. 2) Handle the case where you swipe the drawer during an animation. Previously we had an assert which triggered in some multitouch scenarios. We'll eventually move this over to gestureswipe. 3) Remove an extra container for ink splashes. There's no need to group all the ink splashes in a container. They can all just be children of the Material component itself. This structure is left over from when Material was a base class. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/1013713005
101 lines
2.4 KiB
Dart
101 lines
2.4 KiB
Dart
// Copyright 2015 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import '../fn.dart';
|
|
import '../theme/shadows.dart';
|
|
import 'dart:collection';
|
|
import 'dart:sky' as sky;
|
|
import 'ink_splash.dart';
|
|
|
|
class Material extends Component {
|
|
static final List<Style> shadowStyle = [
|
|
null,
|
|
new Style('box-shadow: ${Shadow[1]}'),
|
|
new Style('box-shadow: ${Shadow[2]}'),
|
|
new Style('box-shadow: ${Shadow[3]}'),
|
|
new Style('box-shadow: ${Shadow[4]}'),
|
|
new Style('box-shadow: ${Shadow[5]}'),
|
|
];
|
|
|
|
LinkedHashSet<SplashAnimation> _splashes;
|
|
|
|
Style style;
|
|
String inlineStyle;
|
|
List<Node> children;
|
|
int level;
|
|
|
|
Material({
|
|
Object key,
|
|
this.style,
|
|
this.inlineStyle,
|
|
this.children,
|
|
this.level: 0 }) : super(key: key) {
|
|
events.listen('gesturescrollstart', _cancelSplashes);
|
|
events.listen('wheel', _cancelSplashes);
|
|
events.listen('pointerdown', _startSplash);
|
|
}
|
|
|
|
Node build() {
|
|
List<Node> childrenIncludingSplashes = [];
|
|
|
|
if (_splashes != null) {
|
|
childrenIncludingSplashes.addAll(
|
|
_splashes.map((s) => new InkSplash(s.onStyleChanged)));
|
|
}
|
|
|
|
if (children != null)
|
|
childrenIncludingSplashes.addAll(children);
|
|
|
|
return new Container(
|
|
style: level > 0 ? style.extend(shadowStyle[level]) : style,
|
|
inlineStyle: inlineStyle,
|
|
children: childrenIncludingSplashes);
|
|
}
|
|
|
|
sky.ClientRect _getBoundingRect() => (getRoot() as sky.Element).getBoundingClientRect();
|
|
|
|
void _startSplash(sky.PointerEvent event) {
|
|
setState(() {
|
|
if (_splashes == null) {
|
|
_splashes = new LinkedHashSet<SplashAnimation>();
|
|
}
|
|
|
|
var splash;
|
|
splash = new SplashAnimation(_getBoundingRect(), event.x, event.y,
|
|
onDone: () { _splashDone(splash); });
|
|
|
|
_splashes.add(splash);
|
|
});
|
|
}
|
|
|
|
void _cancelSplashes(sky.Event event) {
|
|
if (_splashes == null) {
|
|
return;
|
|
}
|
|
|
|
setState(() {
|
|
var splashes = _splashes;
|
|
_splashes = null;
|
|
splashes.forEach((s) { s.cancel(); });
|
|
});
|
|
}
|
|
|
|
void didUnmount() {
|
|
_cancelSplashes(null);
|
|
}
|
|
|
|
void _splashDone(SplashAnimation splash) {
|
|
if (_splashes == null) {
|
|
return;
|
|
}
|
|
|
|
setState(() {
|
|
_splashes.remove(splash);
|
|
if (_splashes.length == 0) {
|
|
_splashes = null;
|
|
}
|
|
});
|
|
}
|
|
}
|