-
Notifications
You must be signed in to change notification settings - Fork 3.8k
OpenContainer Transition Updates #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
dc56e83
a82165e
da554b2
9ea0588
b27e346
050ddbb
9d260fa
6c0ef06
5c0d358
6fbe0ca
a7a3d97
8bcefbc
0426a16
d14cb60
588d0c1
1a178e8
f6e5543
1075530
49d35b3
0eec306
e37f271
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,19 @@ typedef OpenContainerBuilder = Widget Function( | |
| VoidCallback action, | ||
| ); | ||
|
|
||
| /// The [OpenContainer] widget's fade transition type. | ||
| /// | ||
| /// This determines the type of fade transition that the incoming and outgoing | ||
| /// contents will use. | ||
| enum ContainerTransitionType { | ||
| /// Fades the incoming element in over the outgoing element. | ||
| fade, | ||
|
|
||
| /// First fades the outgoing element out, and starts fading the incoming | ||
| /// element in once the outgoing element has completely faded out. | ||
| fadeThrough, | ||
| } | ||
|
|
||
| /// A container that grows to fill the screen to reveal new content when tapped. | ||
| /// | ||
| /// While the container is closed, it shows the [Widget] returned by | ||
|
|
@@ -57,6 +70,7 @@ class OpenContainer extends StatefulWidget { | |
| @required this.openBuilder, | ||
| this.tappable = true, | ||
| this.transitionDuration = const Duration(milliseconds: 300), | ||
| this.transitionType = ContainerTransitionType.fade, | ||
| }) : assert(closedColor != null), | ||
| assert(openColor != null), | ||
| assert(closedElevation != null), | ||
|
|
@@ -66,6 +80,7 @@ class OpenContainer extends StatefulWidget { | |
| assert(closedBuilder != null), | ||
| assert(openBuilder != null), | ||
| assert(tappable != null), | ||
| assert(transitionType != null), | ||
| super(key: key); | ||
|
|
||
| /// Background color of the container while it is closed. | ||
|
|
@@ -182,6 +197,12 @@ class OpenContainer extends StatefulWidget { | |
| /// Defaults to 300ms. | ||
| final Duration transitionDuration; | ||
|
|
||
| /// The type of fade transition that the container will use for its | ||
| /// incoming and outgoing widgets. | ||
| /// | ||
| /// Defaults to [ContainerTransitionType.fade]. | ||
| final ContainerTransitionType transitionType; | ||
|
|
||
| @override | ||
| _OpenContainerState createState() => _OpenContainerState(); | ||
| } | ||
|
|
@@ -212,6 +233,7 @@ class _OpenContainerState extends State<OpenContainer> { | |
| hideableKey: _hideableKey, | ||
| closedBuilderKey: _closedBuilderKey, | ||
| transitionDuration: widget.transitionDuration, | ||
| transitionType: widget.transitionType, | ||
| )); | ||
| } | ||
|
|
||
|
|
@@ -309,7 +331,7 @@ class _HideableState extends State<_Hideable> { | |
|
|
||
| class _OpenContainerRoute extends ModalRoute<void> { | ||
| _OpenContainerRoute({ | ||
| @required Color closedColor, | ||
| @required this.closedColor, | ||
| @required this.openColor, | ||
| @required double closedElevation, | ||
| @required this.openElevation, | ||
|
|
@@ -320,6 +342,7 @@ class _OpenContainerRoute extends ModalRoute<void> { | |
| @required this.hideableKey, | ||
| @required this.closedBuilderKey, | ||
| @required this.transitionDuration, | ||
| @required this.transitionType, | ||
| }) : assert(closedColor != null), | ||
| assert(openColor != null), | ||
| assert(closedElevation != null), | ||
|
|
@@ -329,25 +352,17 @@ class _OpenContainerRoute extends ModalRoute<void> { | |
| assert(closedBuilder != null), | ||
| assert(hideableKey != null), | ||
| assert(closedBuilderKey != null), | ||
| assert(transitionType != null), | ||
| _elevationTween = Tween<double>( | ||
| begin: closedElevation, | ||
| end: openElevation, | ||
| ), | ||
| _shapeTween = ShapeBorderTween( | ||
| begin: closedShape, | ||
| end: openShape, | ||
| ), | ||
| _colorTween = _FlippableTweenSequence<Color>(<TweenSequenceItem<Color>>[ | ||
| TweenSequenceItem<Color>( | ||
| tween: ColorTween(begin: closedColor, end: Colors.white), | ||
| weight: 4 / 12, | ||
| ), | ||
| TweenSequenceItem<Color>( | ||
| tween: ColorTween(begin: Colors.white, end: openColor), | ||
| weight: 8 / 12, | ||
| ), | ||
| ]); | ||
| ); | ||
|
|
||
| final Color closedColor; | ||
| final Color openColor; | ||
| final double openElevation; | ||
| final ShapeBorder openShape; | ||
|
|
@@ -362,42 +377,70 @@ class _OpenContainerRoute extends ModalRoute<void> { | |
|
|
||
| @override | ||
| final Duration transitionDuration; | ||
| final ContainerTransitionType transitionType; | ||
|
|
||
| final Tween<double> _elevationTween; | ||
| final ShapeBorderTween _shapeTween; | ||
| final _FlippableTweenSequence<Color> _colorTween; | ||
|
|
||
| final _FlippableTweenSequence<double> _closedOpacityTween = | ||
| // Fade transition opacity tweens | ||
| static final _FlippableTweenSequence<double> _fadeOpenOpacityTween = | ||
|
Member
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. nit: can you switch open and close tween around so it has the same order ad the fadeThrough tweens?
Author
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. Done |
||
| _FlippableTweenSequence<double>(<TweenSequenceItem<double>>[ | ||
| TweenSequenceItem<double>( | ||
| tween: ConstantTween<double>(0.0), | ||
| weight: 1 / 5, | ||
| ), | ||
| TweenSequenceItem<double>( | ||
| tween: Tween<double>(begin: 0.0, end: 1.0), | ||
| weight: 1 / 5, | ||
| ), | ||
| TweenSequenceItem<double>( | ||
| tween: ConstantTween<double>(1.0), | ||
| weight: 3 / 5, | ||
| ), | ||
| ]); | ||
| static final _FlippableTweenSequence<double> _fadeClosedOpacityTween = | ||
| _FlippableTweenSequence<double>( | ||
| <TweenSequenceItem<double>>[ | ||
| TweenSequenceItem<double>( | ||
| tween: ConstantTween<double>(1.0), | ||
| weight: 1, | ||
| ), | ||
| ], | ||
| ); | ||
|
|
||
| // Fade through transition opacity tweens | ||
|
Member
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. Can you update all the weights of the existing tweens?
Author
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. Done |
||
| static final _FlippableTweenSequence<double> _fadeThroughClosedOpacityTween = | ||
| _FlippableTweenSequence<double>(<TweenSequenceItem<double>>[ | ||
| TweenSequenceItem<double>( | ||
| tween: Tween<double>(begin: 1.0, end: 0.0), | ||
| weight: 4 / 12, | ||
| weight: 1 / 5, | ||
| ), | ||
| TweenSequenceItem<double>( | ||
| tween: ConstantTween<double>(0.0), | ||
| weight: 8 / 12, | ||
| weight: 4 / 5, | ||
| ), | ||
| ]); | ||
| final _FlippableTweenSequence<double> _openOpacityTween = | ||
| static final _FlippableTweenSequence<double> _fadeThroughOpenOpacityTween = | ||
| _FlippableTweenSequence<double>(<TweenSequenceItem<double>>[ | ||
| TweenSequenceItem<double>( | ||
| tween: ConstantTween<double>(0.0), | ||
| weight: 4 / 12, | ||
| weight: 1 / 5, | ||
| ), | ||
| TweenSequenceItem<double>( | ||
| tween: Tween<double>(begin: 0.0, end: 1.0), | ||
| weight: 8 / 12, | ||
| weight: 4 / 5, | ||
| ), | ||
| ]); | ||
|
|
||
| final TweenSequence<Color> _scrimFadeInTween = TweenSequence<Color>( | ||
|
Member
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. (not part of your PR, but maybe you can fix it): These two could also be statics.
Author
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. Done |
||
| <TweenSequenceItem<Color>>[ | ||
| TweenSequenceItem<Color>( | ||
| tween: ColorTween(begin: Colors.transparent, end: Colors.black54), | ||
| weight: 4 / 12, | ||
| weight: 1 / 5, | ||
| ), | ||
| TweenSequenceItem<Color>( | ||
| tween: ConstantTween<Color>(Colors.black54), | ||
| weight: 8 / 12, | ||
| weight: 4 / 5, | ||
| ), | ||
| ], | ||
| ); | ||
|
|
@@ -535,6 +578,51 @@ class _OpenContainerRoute extends ModalRoute<void> { | |
| Animation<double> animation, | ||
| Animation<double> secondaryAnimation, | ||
| ) { | ||
| _FlippableTweenSequence<double> _closedOpacityTween; | ||
| _FlippableTweenSequence<double> _openOpacityTween; | ||
| _FlippableTweenSequence<Color> _colorTween; | ||
|
|
||
| switch (transitionType) { | ||
|
Member
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. We could do this switching in the constructor and save the result in instance variables since the value of transitionType doesn't change for the duration of this object.
Author
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. I moved colorTween, openOpacityTween and closedOpacityTween to be defined in the constructor. |
||
| case ContainerTransitionType.fade: | ||
| _closedOpacityTween = _fadeClosedOpacityTween; | ||
| _openOpacityTween = _fadeOpenOpacityTween; | ||
| _colorTween = _FlippableTweenSequence<Color>( | ||
| <TweenSequenceItem<Color>>[ | ||
| TweenSequenceItem<Color>( | ||
| tween: ConstantTween<Color>(closedColor), | ||
| weight: 1 / 5, | ||
| ), | ||
| TweenSequenceItem<Color>( | ||
| tween: ColorTween(begin: closedColor, end: openColor), | ||
| weight: 1 / 5, | ||
| ), | ||
| TweenSequenceItem<Color>( | ||
| tween: ConstantTween<Color>(openColor), | ||
| weight: 3 / 5, | ||
| ), | ||
| ], | ||
| ); | ||
| break; | ||
| case ContainerTransitionType.fadeThrough: | ||
| _closedOpacityTween = _fadeThroughClosedOpacityTween; | ||
| _openOpacityTween = _fadeThroughOpenOpacityTween; | ||
| _colorTween = _FlippableTweenSequence<Color>( | ||
| <TweenSequenceItem<Color>>[ | ||
| TweenSequenceItem<Color>( | ||
| tween: ColorTween(begin: closedColor, end: Colors.white), | ||
| weight: 1 / 5, | ||
| ), | ||
| TweenSequenceItem<Color>( | ||
| tween: ColorTween(begin: Colors.white, end: openColor), | ||
| weight: 4 / 5, | ||
| ), | ||
| ], | ||
| ); | ||
| break; | ||
| } | ||
| assert(_closedOpacityTween != null); | ||
| assert(_openOpacityTween != null); | ||
|
Member
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. add an assert for _colorTween?
Author
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. Done |
||
|
|
||
| return Align( | ||
| alignment: Alignment.topLeft, | ||
| child: AnimatedBuilder( | ||
|
|
||
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.
(can't comment on the right line, but) do we need to update the color tween?
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.
Done