Commit 658f7707 authored by Hixie's avatar Hixie

fn: make menu items have material splashes also, by factoring out the splashes

TBR=raf

Review URL: https://codereview.chromium.org/974903005
parent 3c5df69a
...@@ -3,6 +3,7 @@ part of widgets; ...@@ -3,6 +3,7 @@ part of widgets;
class Button extends ButtonBase { class Button extends ButtonBase {
static Style _style = new Style(''' static Style _style = new Style('''
transform: translateX(0);
display: inline-flex; display: inline-flex;
border-radius: 4px; border-radius: 4px;
justify-content: center; justify-content: center;
...@@ -13,6 +14,7 @@ class Button extends ButtonBase { ...@@ -13,6 +14,7 @@ class Button extends ButtonBase {
); );
static Style _highlightStyle = new Style(''' static Style _highlightStyle = new Style('''
transform: translateX(0);
display: inline-flex; display: inline-flex;
border-radius: 4px; border-radius: 4px;
justify-content: center; justify-content: center;
...@@ -36,7 +38,7 @@ class Button extends ButtonBase { ...@@ -36,7 +38,7 @@ class Button extends ButtonBase {
onPointerDown: _handlePointerDown, onPointerDown: _handlePointerDown,
onPointerUp: _handlePointerUp, onPointerUp: _handlePointerUp,
onPointerCancel: _handlePointerCancel, onPointerCancel: _handlePointerCancel,
children: [content] children: [super.render(), content]
); );
} }
} }
part of widgets; part of widgets;
abstract class ButtonBase extends Component { abstract class ButtonBase extends MaterialComponent {
bool _highlight = false; bool _highlight = false;
......
...@@ -6,6 +6,7 @@ class Checkbox extends ButtonBase { ...@@ -6,6 +6,7 @@ class Checkbox extends ButtonBase {
ValueChanged onChanged; ValueChanged onChanged;
static Style _style = new Style(''' static Style _style = new Style('''
transform: translateX(0);
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
...@@ -61,6 +62,7 @@ class Checkbox extends ButtonBase { ...@@ -61,6 +62,7 @@ class Checkbox extends ButtonBase {
onPointerUp: _handlePointerUp, onPointerUp: _handlePointerUp,
onPointerCancel: _handlePointerCancel, onPointerCancel: _handlePointerCancel,
children: [ children: [
super.render(),
new Container( new Container(
style: _highlight ? _containerHighlightStyle : _containerStyle, style: _highlight ? _containerHighlightStyle : _containerStyle,
children: [ children: [
......
...@@ -120,6 +120,7 @@ class Drawer extends Component { ...@@ -120,6 +120,7 @@ class Drawer extends Component {
background-color: #FAFAFA; background-color: #FAFAFA;
will-change: transform; will-change: transform;
position: absolute; position: absolute;
z-index: 3;
width: 256px; width: 256px;
top: 0; top: 0;
left: 0; left: 0;
......
part of widgets;
abstract class MaterialComponent extends Component {
static const _splashesKey = const Object();
static Style _style = new Style('''
transform: translateX(0);
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0'''
);
LinkedHashSet<SplashAnimation> _splashes;
MaterialComponent({ Object key }) : super(key: key);
Node render() {
List<Node> children = [];
if (_splashes != null) {
children.addAll(_splashes.map((s) => new InkSplash(s.onStyleChanged)));
}
return new Container(
style: _style,
onScrollStart: _cancelSplashes,
onWheel: _cancelSplashes,
onPointerDown: _startSplash,
children: children,
key: _splashesKey
);
}
sky.ClientRect _getBoundingRect() => getRoot().getBoundingClientRect();
void _startSplash(sky.Event 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 willUnmount() {
_cancelSplashes(null);
}
void _splashDone(SplashAnimation splash) {
if (_splashes == null) {
return;
}
setState(() {
_splashes.remove(splash);
if (_splashes.length == 0) {
_splashes = null;
}
});
}
}
part of widgets; part of widgets;
class MenuItem extends Component { class MenuItem extends ButtonBase {
static Style _style = new Style(''' static Style _style = new Style('''
transform: translateX(0);
display: flex; display: flex;
align-items: center; align-items: center;
height: 48px; height: 48px;
-webkit-user-select: none;''' -webkit-user-select: none;'''
); );
static Style _highlightStyle = new Style('''
transform: translateX(0);
display: flex;
align-items: center;
height: 48px;
background: rgba(153, 153, 153, 0.4);
-webkit-user-select: none;'''
);
static Style _iconStyle = new Style(''' static Style _iconStyle = new Style('''
padding: 0px 16px;''' padding: 0px 16px;'''
); );
...@@ -23,13 +33,20 @@ class MenuItem extends Component { ...@@ -23,13 +33,20 @@ class MenuItem extends Component {
List<Node> children; List<Node> children;
String icon; String icon;
MenuItem({ Object key, this.icon, this.children }) : super(key: key) { sky.EventListener onClick;
MenuItem({ Object key, this.icon, this.children, this.onClick }) : super(key: key) {
} }
Node render() { Node render() {
return new Container( return new Container(
style: _style, style: _highlight ? _highlightStyle : _style,
onClick: onClick,
onPointerDown: _handlePointerDown,
onPointerUp: _handlePointerUp,
onPointerCancel: _handlePointerCancel,
children: [ children: [
super.render(),
new Icon( new Icon(
style: _iconStyle, style: _iconStyle,
size: 24, size: 24,
......
...@@ -7,6 +7,7 @@ class Radio extends ButtonBase { ...@@ -7,6 +7,7 @@ class Radio extends ButtonBase {
ValueChanged onChanged; ValueChanged onChanged;
static Style _style = new Style(''' static Style _style = new Style('''
transform: translateX(0);
display: inline-block; display: inline-block;
-webkit-user-select: none; -webkit-user-select: none;
width: 14px; width: 14px;
...@@ -17,6 +18,7 @@ class Radio extends ButtonBase { ...@@ -17,6 +18,7 @@ class Radio extends ButtonBase {
); );
static Style _highlightStyle = new Style(''' static Style _highlightStyle = new Style('''
transform: translateX(0);
display: inline-block; display: inline-block;
-webkit-user-select: none; -webkit-user-select: none;
width: 14px; width: 14px;
...@@ -51,7 +53,7 @@ class Radio extends ButtonBase { ...@@ -51,7 +53,7 @@ class Radio extends ButtonBase {
onPointerUp: _handlePointerUp, onPointerUp: _handlePointerUp,
onPointerCancel: _handlePointerCancel, onPointerCancel: _handlePointerCancel,
children: value == groupValue ? children: value == groupValue ?
[new Container( style : _dotStyle )] : null [super.render(), new Container( style : _dotStyle )] : [super.render()]
); );
} }
......
library widgets; library widgets;
import '../lib/fn.dart'; import '../lib/fn.dart';
import 'dart:collection';
import 'dart:async'; import 'dart:async';
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:sky' as sky; import 'dart:sky' as sky;
...@@ -16,6 +17,7 @@ part 'fixedheightscrollable.dart'; ...@@ -16,6 +17,7 @@ part 'fixedheightscrollable.dart';
part 'flingcurve.dart'; part 'flingcurve.dart';
part 'icon.dart'; part 'icon.dart';
part 'inksplash.dart'; part 'inksplash.dart';
part 'material.dart';
part 'menudivider.dart'; part 'menudivider.dart';
part 'menuitem.dart'; part 'menuitem.dart';
part 'radio.dart'; part 'radio.dart';
......
part of stocksapp; part of stocksapp;
class StockRow extends Component { class StockRow extends MaterialComponent {
Stock stock; Stock stock;
LinkedHashSet<SplashAnimation> _splashes;
static Style _style = new Style(''' static Style _style = new Style('''
transform: translateX(0); transform: translateX(0);
...@@ -64,61 +63,11 @@ class StockRow extends Component { ...@@ -64,61 +63,11 @@ class StockRow extends Component {
) )
]; ];
if (_splashes != null) { children.add(super.render());
children.addAll(_splashes.map((s) => new InkSplash(s.onStyleChanged)));
}
return new Container( return new Container(
style: _style, style: _style,
onScrollStart: _cancelSplashes,
onWheel: _cancelSplashes,
onPointerDown: _handlePointerDown,
children: children children: children
); );
} }
sky.ClientRect _getBoundingRect() => getRoot().getBoundingClientRect();
void _handlePointerDown(sky.Event 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 willUnmount() {
_cancelSplashes(null);
}
void _splashDone(SplashAnimation splash) {
if (_splashes == null) {
return;
}
setState(() {
_splashes.remove(splash);
if (_splashes.length == 0) {
_splashes = null;
}
});
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment