This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Make SnackBar animate itself #124
Closed
Closed
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9d649ac
no.Builder
mpcomplete 41e865a
Merge remote-tracking branch 'upstream/master' into rm.builder
mpcomplete 21516ec
Merge remote-tracking branch 'upstream/master' into rm.builder
mpcomplete 2e818b3
unwatch
mpcomplete 526bb3e
shorten
mpcomplete 72ee618
keep.performance
mpcomplete 3994f51
snackbar.animates.self
mpcomplete cd2c7b3
Merge remote-tracking branch 'upstream/master' into rm.builder
mpcomplete f5af66e
revert.unwatch
mpcomplete 04010c1
animates.on.hide
mpcomplete 327f197
ANimatedContainer.doesnt.work
mpcomplete 52ce955
Revert "ANimatedContainer.doesnt.work"
mpcomplete 8c35346
rm.animation_builder
mpcomplete f6db9de
fix compile
mpcomplete 70181b2
SnackBarStatus
mpcomplete 90d9a02
Merge remote-tracking branch 'upstream/master' into rm.builder
mpcomplete File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,19 @@ | |
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:sky/animation/animation_performance.dart'; | ||
| import 'package:sky/painting/text_style.dart'; | ||
| import 'package:sky/theme/typography.dart' as typography; | ||
| import 'package:sky/widgets/animated_component.dart'; | ||
| import 'package:sky/widgets/basic.dart'; | ||
| import 'package:sky/widgets/default_text_style.dart'; | ||
| import 'package:sky/widgets/material.dart'; | ||
| import 'package:sky/widgets/theme.dart'; | ||
|
|
||
| import 'package:vector_math/vector_math.dart'; | ||
|
|
||
| const Duration _kSlideInDuration = const Duration(milliseconds: 200); | ||
|
|
||
| class SnackBarAction extends Component { | ||
| SnackBarAction({String key, this.label, this.onPressed }) : super(key: key) { | ||
| assert(label != null); | ||
|
|
@@ -29,18 +35,58 @@ class SnackBarAction extends Component { | |
| } | ||
| } | ||
|
|
||
| class SnackBar extends Component { | ||
| class SnackBar extends AnimatedComponent { | ||
|
|
||
| SnackBar({ | ||
| String key, | ||
| this.content, | ||
| this.actions | ||
| this.actions, | ||
| this.showing, | ||
| this.onHidden | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| }) : super(key: key) { | ||
| assert(content != null); | ||
| } | ||
|
|
||
| final Widget content; | ||
| final List<SnackBarAction> actions; | ||
| 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, 50.0), end: Point.origin); | ||
| _performance = new AnimationPerformance() | ||
| ..duration = _kSlideInDuration | ||
| ..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 = [ | ||
|
|
@@ -54,15 +100,21 @@ class SnackBar extends Component { | |
| ) | ||
| ) | ||
| ]..addAll(actions); | ||
| return new Material( | ||
| level: 2, | ||
| color: const Color(0xFF323232), | ||
| type: MaterialType.canvas, | ||
| child: new Container( | ||
| margin: const EdgeDims.symmetric(horizontal: 24.0), | ||
| child: new DefaultTextStyle( | ||
| style: new TextStyle(color: Theme.of(this).accentColor), | ||
| child: new Flex(children) | ||
|
|
||
| Matrix4 transform = new Matrix4.identity(); | ||
| transform.translate(_position.value.x, _position.value.y); | ||
| return new Transform( | ||
| transform: transform, | ||
| child: new Material( | ||
| level: 2, | ||
| color: const Color(0xFF323232), | ||
| type: MaterialType.canvas, | ||
| child: new Container( | ||
| margin: const EdgeDims.symmetric(horizontal: 24.0), | ||
| child: new DefaultTextStyle( | ||
| style: new TextStyle(color: Theme.of(this).accentColor), | ||
| child: new Flex(children) | ||
| ) | ||
| ) | ||
| ) | ||
| ); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe in the same file as AnimatedType?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to change this soon with a future CL.