Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
animates.on.hide
  • Loading branch information
mpcomplete committed Jul 17, 2015
commit 04010c19a85a196fc6884986aa1f99cfb2a11247
14 changes: 9 additions & 5 deletions sky/sdk/example/stocks/lib/stock_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class StockHome extends StatefulComponent {
bool _isSearching = false;
String _searchQuery;

bool _isShowingSnackBar = false;
bool _isSnackBarLive = false; // Is it on screen at all (maybe dismissing)?
bool _isSnackBarShowing = false; // Should it be showing?

void _handleSearchBegin() {
navigator.pushState(this, (_) {
Expand Down Expand Up @@ -261,22 +262,25 @@ class StockHome extends StatefulComponent {

void _handleUndo() {
setState(() {
_isShowingSnackBar = false;
_isSnackBarShowing = false;
});
}

Widget buildSnackBar() {
if (!_isShowingSnackBar)
if (!_isSnackBarLive)
return null;
return new SnackBar(
showing: _isSnackBarShowing,
content: new Text("Stock purchased!"),
actions: [new SnackBarAction(label: "UNDO", onPressed: _handleUndo)]
actions: [new SnackBarAction(label: "UNDO", onPressed: _handleUndo)],
onHidden: () { setState(() { _isSnackBarLive = false; }); }
);
}

void _handleStockPurchased() {
setState(() {
_isShowingSnackBar = true;
_isSnackBarShowing = true;
_isSnackBarLive = true;
});
}

Expand Down
29 changes: 26 additions & 3 deletions sky/sdk/lib/widgets/snack_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,53 @@ class SnackBar extends AnimatedComponent {
SnackBar({
String key,
this.content,
this.actions
this.actions,
this.showing,
this.onHidden
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Drawer and PopupMenu, we introduced an enum to differentiate this state more clearly from showing.

}) : super(key: key) {
assert(content != null);
}

Widget content;
List<SnackBarAction> actions;
bool showing;
Function onHidden;

void syncFields(SnackBar source) {
content = source.content;
actions = source.actions;
onHidden = source.onHidden;
if (showing != source.showing) {
showing = source.showing;
showing ? _show() : _hide();
}
}

AnimatedType<Point> _position;
AnimationPerformance _performance;

void initState() {
_position = new AnimatedType<Point>(new Point(0.0, 48.0), end: Point.origin);
_position = new AnimatedType<Point>(new Point(0.0, 50.0), end: Point.origin);
_performance = new AnimationPerformance()
..duration = _kSlideInDuration
..variable = _position;
..variable = _position
..addListener(_checkCompleted);
watch(_performance);
if (showing)
_show();
}

void _show() {
_performance.play();
}
void _hide() {
_performance.reverse();
}
void _checkCompleted() {
if (!_performance.isAnimating && _performance.isDismissed && onHidden != null) {
onHidden();
}
}

Widget build() {
List<Widget> children = [
Expand Down