using System; using Unity.UIWidgets.animation; using Unity.UIWidgets.foundation; using Unity.UIWidgets.painting; using Unity.UIWidgets.rendering; using Unity.UIWidgets.ui; using Unity.UIWidgets.widgets; namespace Unity.UIWidgets.material { public class _FadeUpwardsPageTransition : StatelessWidget { public _FadeUpwardsPageTransition( Key key = null, Animation routeAnimation = null, Widget child = null) : base(key: key) { D.assert(routeAnimation != null); D.assert(child != null); _positionAnimation = routeAnimation.drive(_bottomUpTween.chain(_fastOutSlowInTween)); _opacityAnimation = routeAnimation.drive(_easeInTween); this.child = child; } static readonly Tween _bottomUpTween = new OffsetTween( begin: new Offset(0.0f, 0.25f), end: Offset.zero ); static readonly Animatable _fastOutSlowInTween = new CurveTween( curve: Curves.fastOutSlowIn); static readonly Animatable _easeInTween = new CurveTween( curve: Curves.easeIn); public readonly Animation _positionAnimation; public readonly Animation _opacityAnimation; public readonly Widget child; public override Widget build(BuildContext context) { return new SlideTransition( position: _positionAnimation, child: new FadeTransition( opacity: _opacityAnimation, child: child)); } } class _OpenUpwardsPageTransition : StatelessWidget { public _OpenUpwardsPageTransition( Key key = null, Animation animation = null, Animation secondaryAnimation = null, Widget child = null ) : base(key: key) { this.animation = animation; this.secondaryAnimation = secondaryAnimation; this.child = child; } static readonly OffsetTween _primaryTranslationTween = new OffsetTween( begin: new Offset(0.0f, 0.05f), end: Offset.zero ); static readonly OffsetTween _secondaryTranslationTween = new OffsetTween( begin: Offset.zero, end: new Offset(0.0f, -0.025f) ); static readonly FloatTween _scrimOpacityTween = new FloatTween( begin: 0.0f, end: 0.25f ); static readonly Curve _transitionCurve = new Cubic(0.20f, 0.00f, 0.00f, 1.00f); public readonly Animation animation; public readonly Animation secondaryAnimation; public readonly Widget child; public override Widget build(BuildContext context) { return new LayoutBuilder( builder: (BuildContext _context, BoxConstraints constraints) => { Size size = constraints.biggest; CurvedAnimation primaryAnimation = new CurvedAnimation( parent: animation, curve: _transitionCurve, reverseCurve: _transitionCurve.flipped ); Animation clipAnimation = new FloatTween( begin: 0.0f, end: size.height ).animate(primaryAnimation); Animation opacityAnimation = _scrimOpacityTween.animate(primaryAnimation); Animation primaryTranslationAnimation = _primaryTranslationTween.animate(primaryAnimation); Animation secondaryTranslationAnimation = _secondaryTranslationTween.animate( new CurvedAnimation( parent: secondaryAnimation, curve: _transitionCurve, reverseCurve: _transitionCurve.flipped ) ); return new AnimatedBuilder( animation: animation, builder: (BuildContext _, Widget child) => { return new Container( color: Colors.black.withOpacity(opacityAnimation.value), alignment: Alignment.bottomLeft, child: new ClipRect( child: new SizedBox( height: clipAnimation.value, child: new OverflowBox( alignment: Alignment.bottomLeft, maxHeight: size.height, child: child ) ) ) ); }, child: new AnimatedBuilder( animation: secondaryAnimation, child: new FractionalTranslation( translation: primaryTranslationAnimation.value, child: this.child ), builder: (BuildContext _, Widget child) => { return new FractionalTranslation( translation: secondaryTranslationAnimation.value, child: child ); } ) ); } ); } } public abstract class PageTransitionsBuilder { public PageTransitionsBuilder() { } public abstract Widget buildTransitions( PageRoute route, BuildContext context, Animation animation, Animation secondaryAnimation, Widget child); } public class FadeUpwardsPageTransitionsBuilder : PageTransitionsBuilder { public FadeUpwardsPageTransitionsBuilder() { } public override Widget buildTransitions( PageRoute route, BuildContext context, Animation animation, Animation secondaryAnimation, Widget child) { return new _FadeUpwardsPageTransition( routeAnimation: animation, child: child); } } public class OpenUpwardsPageTransitionsBuilder : PageTransitionsBuilder { public OpenUpwardsPageTransitionsBuilder() { } public override Widget buildTransitions( PageRoute route, BuildContext context, Animation animation, Animation secondaryAnimation, Widget child ) { return new _OpenUpwardsPageTransition( animation: animation, secondaryAnimation: secondaryAnimation, child: child ); } } public class PageTransitionsTheme : Diagnosticable, IEquatable { public PageTransitionsTheme( PageTransitionsBuilder builder = null) { _builder = builder; } static PageTransitionsBuilder _defaultBuilder = new FadeUpwardsPageTransitionsBuilder(); public PageTransitionsBuilder builder { get { return _builder ?? _defaultBuilder; } } readonly PageTransitionsBuilder _builder; public Widget buildTranstions( PageRoute route, BuildContext context, Animation animation, Animation secondaryAnimation, Widget child) { PageTransitionsBuilder matchingBuilder = builder; return matchingBuilder.buildTransitions(route, context, animation, secondaryAnimation, child); } PageTransitionsBuilder _all(PageTransitionsBuilder builder) { return builder; } public bool Equals(PageTransitionsTheme other) { if (ReferenceEquals(null, other)) { return false; } if (ReferenceEquals(this, other)) { return true; } return _all(builder) == _all(other.builder); } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) { return false; } if (ReferenceEquals(this, obj)) { return true; } if (obj.GetType() != GetType()) { return false; } return Equals((PageTransitionsTheme) obj); } public static bool operator ==(PageTransitionsTheme left, PageTransitionsTheme right) { return Equals(left, right); } public static bool operator !=(PageTransitionsTheme left, PageTransitionsTheme right) { return !Equals(left, right); } public override int GetHashCode() { unchecked { var hashCode = _all(builder).GetHashCode(); return hashCode; } } public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { base.debugFillProperties(properties); properties.add(new DiagnosticsProperty("builder", builder, defaultValue: _defaultBuilder)); } } }