Dismissable animation simplifications; added backgrounds to CardCollection cards
This commit is contained in:
@@ -9,10 +9,12 @@ import 'package:sky/widgets/basic.dart';
|
|||||||
import 'package:sky/widgets/block_viewport.dart';
|
import 'package:sky/widgets/block_viewport.dart';
|
||||||
import 'package:sky/widgets/card.dart';
|
import 'package:sky/widgets/card.dart';
|
||||||
import 'package:sky/widgets/dismissable.dart';
|
import 'package:sky/widgets/dismissable.dart';
|
||||||
|
import 'package:sky/widgets/icon.dart';
|
||||||
import 'package:sky/widgets/variable_height_scrollable.dart';
|
import 'package:sky/widgets/variable_height_scrollable.dart';
|
||||||
import 'package:sky/widgets/scaffold.dart';
|
import 'package:sky/widgets/scaffold.dart';
|
||||||
import 'package:sky/widgets/theme.dart';
|
import 'package:sky/widgets/theme.dart';
|
||||||
import 'package:sky/widgets/tool_bar.dart';
|
import 'package:sky/widgets/tool_bar.dart';
|
||||||
|
import 'package:sky/theme/typography.dart' as typography;
|
||||||
import 'package:sky/widgets/widget.dart';
|
import 'package:sky/widgets/widget.dart';
|
||||||
import 'package:sky/widgets/task_description.dart';
|
import 'package:sky/widgets/task_description.dart';
|
||||||
|
|
||||||
@@ -27,8 +29,11 @@ class CardModel {
|
|||||||
|
|
||||||
class CardCollectionApp extends App {
|
class CardCollectionApp extends App {
|
||||||
|
|
||||||
final TextStyle cardLabelStyle =
|
static const TextStyle cardLabelStyle =
|
||||||
new TextStyle(color: white, fontSize: 18.0, fontWeight: bold);
|
const TextStyle(color: white, fontSize: 18.0, fontWeight: bold);
|
||||||
|
|
||||||
|
final TextStyle backgroundTextStyle =
|
||||||
|
typography.white.title.copyWith(textAlign: TextAlign.center);
|
||||||
|
|
||||||
BlockViewportLayoutState layoutState = new BlockViewportLayoutState();
|
BlockViewportLayoutState layoutState = new BlockViewportLayoutState();
|
||||||
List<CardModel> cardModels;
|
List<CardModel> cardModels;
|
||||||
@@ -57,21 +62,50 @@ class CardCollectionApp extends App {
|
|||||||
Widget builder(int index) {
|
Widget builder(int index) {
|
||||||
if (index >= cardModels.length)
|
if (index >= cardModels.length)
|
||||||
return null;
|
return null;
|
||||||
CardModel card = cardModels[index];
|
|
||||||
|
|
||||||
return new Dismissable(
|
CardModel cardModel = cardModels[index];
|
||||||
key: card.key,
|
Widget card = new Dismissable(
|
||||||
onResized: () { layoutState.invalidate([index]); },
|
onResized: () { layoutState.invalidate([index]); },
|
||||||
onDismissed: () { dismissCard(card); },
|
onDismissed: () { dismissCard(cardModel); },
|
||||||
child: new Card(
|
child: new Card(
|
||||||
color: card.color,
|
color: cardModel.color,
|
||||||
child: new Container(
|
child: new Container(
|
||||||
height: card.height,
|
height: cardModel.height,
|
||||||
padding: const EdgeDims.all(8.0),
|
padding: const EdgeDims.all(8.0),
|
||||||
child: new Center(child: new Text(card.label, style: cardLabelStyle))
|
child: new Center(child: new Text(cardModel.label, style: cardLabelStyle))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Widget backgroundText = new Center(
|
||||||
|
child: new Text("Swipe in either direction", style: backgroundTextStyle)
|
||||||
|
);
|
||||||
|
|
||||||
|
// The background Widget appears behind the Dismissable card when the card
|
||||||
|
// moves to the left or right. The Positioned widget ensures that the
|
||||||
|
// size of the background,card Stack will be based only on the card. The
|
||||||
|
// Viewport ensures that when the card's resize animation occurs, the
|
||||||
|
// background (text and icons) will just be clipped, not resized.
|
||||||
|
Widget background = new Positioned(
|
||||||
|
top: 0.0,
|
||||||
|
left: 0.0,
|
||||||
|
child: new Container(
|
||||||
|
margin: const EdgeDims.all(4.0),
|
||||||
|
child: new Viewport(
|
||||||
|
child: new Container(
|
||||||
|
height: cardModel.height,
|
||||||
|
decoration: new BoxDecoration(backgroundColor: Theme.of(this).primaryColor),
|
||||||
|
child: new Flex([
|
||||||
|
new Icon(type: 'navigation/arrow_back', size: 36),
|
||||||
|
new Flexible(child: backgroundText),
|
||||||
|
new Icon(type: 'navigation/arrow_forward', size: 36)
|
||||||
|
])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Stack([background, card], key: cardModel.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget build() {
|
Widget build() {
|
||||||
@@ -85,17 +119,20 @@ class CardCollectionApp extends App {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return new Theme(
|
return new IconTheme(
|
||||||
data: new ThemeData(
|
data: const IconThemeData(color: IconThemeColor.white),
|
||||||
brightness: ThemeBrightness.light,
|
child: new Theme(
|
||||||
primarySwatch: Blue,
|
data: new ThemeData(
|
||||||
accentColor: RedAccent[200]
|
brightness: ThemeBrightness.light,
|
||||||
),
|
primarySwatch: Blue,
|
||||||
child: new TaskDescription(
|
accentColor: RedAccent[200]
|
||||||
label: 'Cards',
|
),
|
||||||
child: new Scaffold(
|
child: new TaskDescription(
|
||||||
toolbar: new ToolBar(center: new Text('Swipe Away')),
|
label: 'Cards',
|
||||||
body: cardCollection
|
child: new Scaffold(
|
||||||
|
toolbar: new ToolBar(center: new Text('Swipe Away')),
|
||||||
|
body: cardCollection
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ class Dismissable extends AnimatedComponent {
|
|||||||
..duration = _kCardDismissFadeout
|
..duration = _kCardDismissFadeout
|
||||||
..variable = new AnimatedList([_position, _opacity])
|
..variable = new AnimatedList([_position, _opacity])
|
||||||
..addListener(_handleFadeProgressChanged);
|
..addListener(_handleFadeProgressChanged);
|
||||||
watch(_fadePerformance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleFadeProgressChanged() {
|
void _handleFadeProgressChanged() {
|
||||||
@@ -85,8 +84,6 @@ class Dismissable extends AnimatedComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _maybeCallOnDismissed() {
|
void _maybeCallOnDismissed() {
|
||||||
_resizePerformance.stop();
|
|
||||||
_resizePerformance.removeListener(_handleResizeProgressChanged);
|
|
||||||
if (onDismissed != null)
|
if (onDismissed != null)
|
||||||
onDismissed();
|
onDismissed();
|
||||||
}
|
}
|
||||||
@@ -96,22 +93,19 @@ class Dismissable extends AnimatedComponent {
|
|||||||
assert(_fadePerformance != null);
|
assert(_fadePerformance != null);
|
||||||
assert(_resizePerformance == null);
|
assert(_resizePerformance == null);
|
||||||
|
|
||||||
|
// TODO(hansmuller): _fadePerformance is completed; stop shouldn't be needed.
|
||||||
_fadePerformance.stop();
|
_fadePerformance.stop();
|
||||||
_fadePerformance.removeListener(_handleFadeProgressChanged);
|
|
||||||
|
|
||||||
_maybeCallOnResized();
|
|
||||||
|
|
||||||
AnimatedValue<double> dismissHeight = new AnimatedValue<double>(_size.height,
|
AnimatedValue<double> dismissHeight = new AnimatedValue<double>(_size.height,
|
||||||
end: 0.0,
|
end: 0.0,
|
||||||
curve: ease,
|
curve: ease,
|
||||||
interval: new Interval(_kCardDismissResizeDelay, 1.0)
|
interval: new Interval(_kCardDismissResizeDelay, 1.0)
|
||||||
);
|
);
|
||||||
_resizePerformance = new AnimationPerformance()
|
_resizePerformance = new AnimationPerformance()
|
||||||
..variable = dismissHeight
|
..variable = dismissHeight
|
||||||
..duration = _kCardDismissResize
|
..duration = _kCardDismissResize
|
||||||
..addListener(_handleResizeProgressChanged)
|
..addListener(_handleResizeProgressChanged)
|
||||||
..play();
|
..play();
|
||||||
watch(_resizePerformance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleResizeProgressChanged() {
|
void _handleResizeProgressChanged() {
|
||||||
|
|||||||
Reference in New Issue
Block a user