|
1 | 1 | using System;
|
2 | 2 | using Unity.UIWidgets.animation;
|
3 | 3 | using Unity.UIWidgets.foundation;
|
| 4 | +using Unity.UIWidgets.painting; |
| 5 | +using Unity.UIWidgets.rendering; |
4 | 6 | using Unity.UIWidgets.ui;
|
5 | 7 | using Unity.UIWidgets.widgets;
|
6 | 8 |
|
@@ -41,6 +43,103 @@ public override Widget build(BuildContext context) {
|
41 | 43 | }
|
42 | 44 | }
|
43 | 45 |
|
| 46 | + class _OpenUpwardsPageTransition : StatelessWidget { |
| 47 | + public _OpenUpwardsPageTransition( |
| 48 | + Key key = null, |
| 49 | + Animation<float> animation = null, |
| 50 | + Animation<float> secondaryAnimation = null, |
| 51 | + Widget child = null |
| 52 | + ) : base(key: key) { |
| 53 | + this.animation = animation; |
| 54 | + this.secondaryAnimation = secondaryAnimation; |
| 55 | + this.child = child; |
| 56 | + } |
| 57 | + |
| 58 | + static readonly OffsetTween _primaryTranslationTween = new OffsetTween( |
| 59 | + begin: new Offset(0.0f, 0.05f), |
| 60 | + end: Offset.zero |
| 61 | + ); |
| 62 | + |
| 63 | + static readonly OffsetTween _secondaryTranslationTween = new OffsetTween( |
| 64 | + begin: Offset.zero, |
| 65 | + end: new Offset(0.0f, -0.025f) |
| 66 | + ); |
| 67 | + |
| 68 | + static readonly FloatTween _scrimOpacityTween = new FloatTween( |
| 69 | + begin: 0.0f, |
| 70 | + end: 0.25f |
| 71 | + ); |
| 72 | + |
| 73 | + static readonly Curve _transitionCurve = new Cubic(0.20f, 0.00f, 0.00f, 1.00f); |
| 74 | + |
| 75 | + public readonly Animation<float> animation; |
| 76 | + public readonly Animation<float> secondaryAnimation; |
| 77 | + public readonly Widget child; |
| 78 | + |
| 79 | + public override Widget build(BuildContext context) { |
| 80 | + return new LayoutBuilder( |
| 81 | + builder: (BuildContext _context, BoxConstraints constraints) => { |
| 82 | + Size size = constraints.biggest; |
| 83 | + |
| 84 | + CurvedAnimation primaryAnimation = new CurvedAnimation( |
| 85 | + parent: this.animation, |
| 86 | + curve: _transitionCurve, |
| 87 | + reverseCurve: _transitionCurve.flipped |
| 88 | + ); |
| 89 | + |
| 90 | + Animation<float> clipAnimation = new FloatTween( |
| 91 | + begin: 0.0f, |
| 92 | + end: size.height |
| 93 | + ).animate(primaryAnimation); |
| 94 | + |
| 95 | + Animation<float> opacityAnimation = _scrimOpacityTween.animate(primaryAnimation); |
| 96 | + Animation<Offset> primaryTranslationAnimation = _primaryTranslationTween.animate(primaryAnimation); |
| 97 | + |
| 98 | + Animation<Offset> secondaryTranslationAnimation = _secondaryTranslationTween.animate( |
| 99 | + new CurvedAnimation( |
| 100 | + parent: this.secondaryAnimation, |
| 101 | + curve: _transitionCurve, |
| 102 | + reverseCurve: _transitionCurve.flipped |
| 103 | + ) |
| 104 | + ); |
| 105 | + |
| 106 | + return new AnimatedBuilder( |
| 107 | + animation: this.animation, |
| 108 | + builder: (BuildContext _, Widget child) => { |
| 109 | + return new Container( |
| 110 | + color: Colors.black.withOpacity(opacityAnimation.value), |
| 111 | + alignment: Alignment.bottomLeft, |
| 112 | + child: new ClipRect( |
| 113 | + child: new SizedBox( |
| 114 | + height: clipAnimation.value, |
| 115 | + child: new OverflowBox( |
| 116 | + alignment: Alignment.bottomLeft, |
| 117 | + maxHeight: size.height, |
| 118 | + child: child |
| 119 | + ) |
| 120 | + ) |
| 121 | + ) |
| 122 | + ); |
| 123 | + }, |
| 124 | + child: new AnimatedBuilder( |
| 125 | + animation: this.secondaryAnimation, |
| 126 | + child: new FractionalTranslation( |
| 127 | + translation: primaryTranslationAnimation.value, |
| 128 | + child: this.child |
| 129 | + ), |
| 130 | + builder: (BuildContext _, Widget child) => { |
| 131 | + return new FractionalTranslation( |
| 132 | + translation: secondaryTranslationAnimation.value, |
| 133 | + child: child |
| 134 | + ); |
| 135 | + } |
| 136 | + ) |
| 137 | + ); |
| 138 | + } |
| 139 | + ); |
| 140 | + } |
| 141 | + } |
| 142 | + |
44 | 143 | public abstract class PageTransitionsBuilder {
|
45 | 144 | public PageTransitionsBuilder() {
|
46 | 145 | }
|
@@ -70,6 +169,25 @@ public override Widget buildTransitions(
|
70 | 169 | }
|
71 | 170 | }
|
72 | 171 |
|
| 172 | + public class OpenUpwardsPageTransitionsBuilder : PageTransitionsBuilder { |
| 173 | + public OpenUpwardsPageTransitionsBuilder() { |
| 174 | + } |
| 175 | + |
| 176 | + public override Widget buildTransitions( |
| 177 | + PageRoute route, |
| 178 | + BuildContext context, |
| 179 | + Animation<float> animation, |
| 180 | + Animation<float> secondaryAnimation, |
| 181 | + Widget child |
| 182 | + ) { |
| 183 | + return new _OpenUpwardsPageTransition( |
| 184 | + animation: animation, |
| 185 | + secondaryAnimation: secondaryAnimation, |
| 186 | + child: child |
| 187 | + ); |
| 188 | + } |
| 189 | + } |
| 190 | + |
73 | 191 | public class PageTransitionsTheme : Diagnosticable, IEquatable<PageTransitionsTheme> {
|
74 | 192 | public PageTransitionsTheme(
|
75 | 193 | PageTransitionsBuilder builder = null) {
|
|
0 commit comments