RenderInkWell should use gestures

After this patch, InkWell is driven by gesture recognizers, which lets us
cleanly cancel splashes when the user actually scrolls.

I've also refactored all the clients of InkWell to use InkWell to detect
gestures instead of wrapping InkWell in a GestureDetector.

Fixes #1271
This commit is contained in:
Adam Barth
2015-10-03 01:09:14 -07:00
parent 445c512d2c
commit cf88993492
21 changed files with 320 additions and 207 deletions

View File

@@ -42,8 +42,8 @@ void launch(String relativeUrl, String bundle) {
activity.startActivity(intent);
}
class SkyDemo {
SkyDemo({
class FlutterDemo {
FlutterDemo({
name,
this.href,
this.bundle,
@@ -60,8 +60,8 @@ class SkyDemo {
final BoxDecoration decoration;
}
List<SkyDemo> demos = [
new SkyDemo(
List<FlutterDemo> demos = [
new FlutterDemo(
name: 'Stocks',
href: '../../stocks/lib/main.dart',
bundle: 'stocks.skyx',
@@ -74,7 +74,7 @@ List<SkyDemo> demos = [
)
)
),
new SkyDemo(
new FlutterDemo(
name: 'Asteroids',
href: '../../game/lib/main.dart',
bundle: 'game.skyx',
@@ -87,7 +87,7 @@ List<SkyDemo> demos = [
)
)
),
new SkyDemo(
new FlutterDemo(
name: 'Fitness',
href: '../../fitness/lib/main.dart',
bundle: 'fitness.skyx',
@@ -97,7 +97,7 @@ List<SkyDemo> demos = [
backgroundColor: Colors.indigo[500]
)
),
new SkyDemo(
new FlutterDemo(
name: 'Swipe Away',
href: '../../widgets/card_collection.dart',
bundle: 'cards.skyx',
@@ -107,7 +107,7 @@ List<SkyDemo> demos = [
backgroundColor: Colors.redAccent[200]
)
),
new SkyDemo(
new FlutterDemo(
name: 'Interactive Text',
href: '../../rendering/interactive_flex.dart',
bundle: 'interactive_flex.skyx',
@@ -120,7 +120,7 @@ List<SkyDemo> demos = [
// new SkyDemo(
// 'Touch Demo', '../../rendering/touch_demo.dart', 'Simple example showing handling of touch events at a low level'),
new SkyDemo(
new FlutterDemo(
name: 'Minedigger Game',
href: '../../mine_digger/lib/main.dart',
bundle: 'mine_digger.skyx',
@@ -138,44 +138,47 @@ List<SkyDemo> demos = [
const double kCardHeight = 120.0;
const EdgeDims kListPadding = const EdgeDims.all(4.0);
class DemoList extends StatelessComponent {
Widget buildCardContents(SkyDemo demo) {
return new Container(
decoration: demo.decoration,
child: new InkWell(
child: new Container(
margin: const EdgeDims.only(top: 24.0, left: 24.0),
child: new Column([
new Text(demo.name, style: demo.textTheme.title),
new Flexible(
child: new Text(demo.description, style: demo.textTheme.subhead)
)
],
alignItems: FlexAlignItems.start
class DemoCard extends StatelessComponent {
DemoCard({ Key key, this.demo }) : super(key: key);
final FlutterDemo demo;
Widget build(BuildContext context) {
return new Container(
height: kCardHeight,
child: new Card(
child: new Container(
decoration: demo.decoration,
child: new InkWell(
onTap: () => launch(demo.href, demo.bundle),
child: new Container(
margin: const EdgeDims.only(top: 24.0, left: 24.0),
child: new Column([
new Text(demo.name, style: demo.textTheme.title),
new Flexible(
child: new Text(demo.description, style: demo.textTheme.subhead)
)
],
alignItems: FlexAlignItems.start
)
)
)
)
);
}
Widget buildDemo(BuildContext context, SkyDemo demo) {
return new GestureDetector(
key: demo.key,
onTap: () => launch(demo.href, demo.bundle),
child: new Container(
height: kCardHeight,
child: new Card(
child: buildCardContents(demo)
)
)
);
}
}
class DemoList extends StatelessComponent {
Widget _buildDemoCard(BuildContext context, FlutterDemo demo) {
return new DemoCard(key: demo.key, demo: demo);
}
Widget build(BuildContext context) {
return new ScrollableList<SkyDemo>(
return new ScrollableList<FlutterDemo>(
items: demos,
itemExtent: kCardHeight,
itemBuilder: buildDemo,
itemBuilder: _buildDemoCard,
padding: kListPadding
);
}
@@ -200,7 +203,7 @@ class DemoHome extends StatelessComponent {
void main() {
runApp(new App(
title: 'Sky Demos',
title: 'Flutter Demos',
theme: _theme,
routes: {
'/': (NavigatorState navigator, Route route) => new DemoHome()

View File

@@ -33,15 +33,13 @@ class DialogMenuItem extends StatelessComponent {
Function onPressed;
Widget build(BuildContext context) {
return new GestureDetector(
onTap: onPressed,
child: new Container(
height: 48.0,
child: new InkWell(
child: new Padding(
padding: const EdgeDims.symmetric(horizontal: 16.0),
child: new Row(children)
)
return new Container(
height: 48.0,
child: new InkWell(
onTap: onPressed,
child: new Padding(
padding: const EdgeDims.symmetric(horizontal: 16.0),
child: new Row(children)
)
)
);

View File

@@ -65,12 +65,13 @@ class MealFragmentState extends State<MealFragment> {
icon: "navigation/close",
onPressed: config.navigator.pop),
center: new Text('New Meal'),
right: [new InkWell(
child: new GestureDetector(
right: [
// TODO(abarth): Should this be a FlatButton?
new InkWell(
onTap: _handleSave,
child: new Text('SAVE')
)
)]
]
);
}

View File

@@ -136,12 +136,13 @@ class MeasurementFragmentState extends State<MeasurementFragment> {
icon: "navigation/close",
onPressed: config.navigator.pop),
center: new Text('New Measurement'),
right: [new InkWell(
child: new GestureDetector(
right: [
// TODO(abarth): Should this be a FlatButton?
new InkWell(
onTap: _handleSave,
child: new Text('SAVE')
)
)]
]
);
}

View File

@@ -55,52 +55,50 @@ class StockRow extends StatelessComponent {
String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%";
if (stock.percentChange > 0) changeInPrice = "+" + changeInPrice;
return new GestureDetector(
return new InkWell(
onTap: _getTapHandler(onPressed),
onLongPress: _getLongPressHandler(onLongPressed),
child: new InkWell(
child: new Container(
padding: const EdgeDims.TRBL(16.0, 16.0, 20.0, 16.0),
decoration: new BoxDecoration(
border: new Border(
bottom: new BorderSide(color: Theme.of(context).dividerColor)
)
child: new Container(
padding: const EdgeDims.TRBL(16.0, 16.0, 20.0, 16.0),
decoration: new BoxDecoration(
border: new Border(
bottom: new BorderSide(color: Theme.of(context).dividerColor)
)
),
child: new Row([
new Container(
key: arrowKey,
child: new StockArrow(percentChange: stock.percentChange),
margin: const EdgeDims.only(right: 5.0)
),
child: new Row([
new Container(
key: arrowKey,
child: new StockArrow(percentChange: stock.percentChange),
margin: const EdgeDims.only(right: 5.0)
),
new Flexible(
child: new Row([
new Flexible(
flex: 2,
child: new Text(
stock.symbol,
key: symbolKey
)
),
new Flexible(
child: new Text(
lastSale,
style: const TextStyle(textAlign: TextAlign.right),
key: priceKey
)
),
new Flexible(
child: new Text(
changeInPrice,
style: Theme.of(context).text.caption.copyWith(textAlign: TextAlign.right)
)
),
],
alignItems: FlexAlignItems.baseline,
textBaseline: DefaultTextStyle.of(context).textBaseline
)
new Flexible(
child: new Row([
new Flexible(
flex: 2,
child: new Text(
stock.symbol,
key: symbolKey
)
),
new Flexible(
child: new Text(
lastSale,
style: const TextStyle(textAlign: TextAlign.right),
key: priceKey
)
),
new Flexible(
child: new Text(
changeInPrice,
style: Theme.of(context).text.caption.copyWith(textAlign: TextAlign.right)
)
),
],
alignItems: FlexAlignItems.baseline,
textBaseline: DefaultTextStyle.of(context).textBaseline
)
])
)
)
])
)
);
}