diff --git a/packages/flutter/lib/src/material/bottom_sheet.dart b/packages/flutter/lib/src/material/bottom_sheet.dart index 922262a9845..bab65813aad 100644 --- a/packages/flutter/lib/src/material/bottom_sheet.dart +++ b/packages/flutter/lib/src/material/bottom_sheet.dart @@ -158,7 +158,7 @@ class _ModalBottomSheetRoute extends PopupRoute { return BottomSheet.createPerformance(); } - Widget buildPage(BuildContext context) { + Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) { return new _ModalBottomSheet(route: this); } } diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart index 9f3f4507be3..1810cd8bbd6 100644 --- a/packages/flutter/lib/src/material/dialog.dart +++ b/packages/flutter/lib/src/material/dialog.dart @@ -127,9 +127,11 @@ class _DialogRoute extends PopupRoute { bool get barrierDismissable => true; Color get barrierColor => Colors.black54; - Widget buildPage(BuildContext context) => child; + Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) { + return child; + } - Widget buildTransition(BuildContext context, PerformanceView performance, Widget child) { + Widget buildTransitions(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance, Widget child) { return new FadeTransition( performance: performance, opacity: new AnimatedValue(0.0, end: 1.0, curve: Curves.easeOut), diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index b685610051f..18b3e144d39 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -168,7 +168,9 @@ class _DropDownRoute extends PopupRoute { bool get barrierDismissable => true; Color get barrierColor => null; - Widget buildPage(BuildContext context) => new _DropDownMenu(route: this); + Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) { + return new _DropDownMenu(route: this); + } } class DropDownMenuItem extends StatelessComponent { diff --git a/packages/flutter/lib/src/material/page.dart b/packages/flutter/lib/src/material/page.dart index e3bfb730b4f..972d2e3ff15 100644 --- a/packages/flutter/lib/src/material/page.dart +++ b/packages/flutter/lib/src/material/page.dart @@ -53,7 +53,7 @@ class MaterialPageRoute extends PageRoute { Color get barrierColor => null; bool canTransitionFrom(TransitionRoute nextRoute) => false; - Widget buildPage(BuildContext context) { + Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) { Widget result = builder(context); assert(() { if (result == null) @@ -64,7 +64,7 @@ class MaterialPageRoute extends PageRoute { return result; } - Widget buildTransition(BuildContext context, PerformanceView performance, Widget child) { + Widget buildTransitions(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance, Widget child) { return new _MaterialPageTransition( performance: performance, child: child diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index c0a8ce6473e..14f4129e89e 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -109,7 +109,9 @@ class _PopupMenuRoute extends PopupRoute { bool get barrierDismissable => true; Color get barrierColor => null; - Widget buildPage(BuildContext context) => new _PopupMenu(route: this); + Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) { + return new _PopupMenu(route: this); + } } Future showMenu({ BuildContext context, ModalPosition position, List items, int elevation: 8 }) { diff --git a/packages/flutter/lib/src/widgets/routes.dart b/packages/flutter/lib/src/widgets/routes.dart index 1f2384a296d..fa40771a253 100644 --- a/packages/flutter/lib/src/widgets/routes.dart +++ b/packages/flutter/lib/src/widgets/routes.dart @@ -13,7 +13,6 @@ import 'modal_barrier.dart'; import 'navigator.dart'; import 'overlay.dart'; import 'page_storage.dart'; -import 'status_transitions.dart'; const _kTransparent = const Color(0x00000000); @@ -147,11 +146,12 @@ abstract class TransitionRoute extends OverlayRoute { } - final ProxyPerformance forwardPerformance = new ProxyPerformance(); + PerformanceView get forwardPerformance => _forwardPerformance; + final ProxyPerformance _forwardPerformance = new ProxyPerformance(); void didPushNext(Route nextRoute) { if (nextRoute is TransitionRoute && canTransitionTo(nextRoute) && nextRoute.canTransitionFrom(this)) { - PerformanceView current = forwardPerformance.masterPerformance; + PerformanceView current = _forwardPerformance.masterPerformance; if (current != null) { if (current is TrainHoppingPerformance) { TrainHoppingPerformance newPerformance; @@ -159,19 +159,19 @@ abstract class TransitionRoute extends OverlayRoute { current.currentTrain, nextRoute.performance, onSwitchedTrain: () { - assert(forwardPerformance.masterPerformance == newPerformance); + assert(_forwardPerformance.masterPerformance == newPerformance); assert(newPerformance.currentTrain == nextRoute.performance); - forwardPerformance.masterPerformance = newPerformance.currentTrain; + _forwardPerformance.masterPerformance = newPerformance.currentTrain; newPerformance.dispose(); } ); - forwardPerformance.masterPerformance = newPerformance; + _forwardPerformance.masterPerformance = newPerformance; current.dispose(); } else { - forwardPerformance.masterPerformance = new TrainHoppingPerformance(current, nextRoute.performance); + _forwardPerformance.masterPerformance = new TrainHoppingPerformance(current, nextRoute.performance); } } else { - forwardPerformance.masterPerformance = nextRoute.performance; + _forwardPerformance.masterPerformance = nextRoute.performance; } } super.didPushNext(nextRoute); @@ -180,21 +180,6 @@ abstract class TransitionRoute extends OverlayRoute { bool canTransitionTo(TransitionRoute nextRoute) => true; bool canTransitionFrom(TransitionRoute nextRoute) => true; - Widget wrapTransition(BuildContext context, Widget child) { - return buildForwardTransition( - context, - forwardPerformance, - buildTransition( - context, - performance, - child - ) - ); - } - - Widget buildTransition(BuildContext context, PerformanceView performance, Widget child) => child; - Widget buildForwardTransition(BuildContext context, PerformanceView performance, Widget child) => child; - String get debugLabel => '$runtimeType'; String toString() => '$runtimeType(performance: $_performance)'; } @@ -270,44 +255,85 @@ class _ModalScopeStatus extends InheritedWidget { } } -class _ModalScope extends StatusTransitionComponent { +class _ModalScope extends StatefulComponent { _ModalScope({ Key key, this.subtreeKey, this.storageBucket, - PerformanceView performance, + this.performance, + this.forwardPerformance, this.current, this.route - }) : super(key: key, performance: performance); + }) : super(key: key); final GlobalKey subtreeKey; final PageStorageBucket storageBucket; + final PerformanceView performance; + final PerformanceView forwardPerformance; final bool current; final ModalRoute route; + _ModalScopeState createState() => new _ModalScopeState(); +} + +class _ModalScopeState extends State<_ModalScope> { + void initState() { + super.initState(); + config.performance?.addStatusListener(_performanceStatusChanged); + config.forwardPerformance?.addStatusListener(_performanceStatusChanged); + } + + void didUpdateConfig(_ModalScope oldConfig) { + if (config.performance != oldConfig.performance) { + oldConfig.performance?.removeStatusListener(_performanceStatusChanged); + config.performance?.addStatusListener(_performanceStatusChanged); + } + if (config.forwardPerformance != oldConfig.forwardPerformance) { + oldConfig.forwardPerformance?.removeStatusListener(_performanceStatusChanged); + config.forwardPerformance?.addStatusListener(_performanceStatusChanged); + } + } + + void dispose() { + config.performance?.removeStatusListener(_performanceStatusChanged); + config.forwardPerformance?.removeStatusListener(_performanceStatusChanged); + super.dispose(); + } + + void _performanceStatusChanged(PerformanceStatus status) { + setState(() { + // The performances' states are our build state, and they changed already. + }); + } + Widget build(BuildContext context) { Widget contents = new PageStorage( - key: subtreeKey, - bucket: storageBucket, + key: config.subtreeKey, + bucket: config.storageBucket, child: new _ModalScopeStatus( - current: current, - route: route, - child: route.buildPage(context) + current: config.current, + route: config.route, + child: config.route.buildPage(context, config.performance, config.forwardPerformance) ) ); - if (route.offstage) { + if (config.route.offstage) { contents = new OffStage(child: contents); } else { contents = new Focus( - key: new GlobalObjectKey(route), + key: new GlobalObjectKey(config.route), child: new IgnorePointer( - ignoring: performance.status == PerformanceStatus.reverse, - child: route.wrapTransition(context, contents) + ignoring: config.performance?.status == PerformanceStatus.reverse, + child: config.route.buildTransitions( + context, + config.performance, + config.forwardPerformance, + contents + ) ) ); } contents = new RepaintBoundary(child: contents); - ModalPosition position = route.position; + ModalPosition position = config.route.position; if (position == null) return contents; return new Positioned( @@ -347,8 +373,8 @@ abstract class ModalRoute extends TransitionRoute with LocalHistoryRoute null; - Widget buildPage(BuildContext context); - Widget buildTransition(BuildContext context, PerformanceView performance, Widget child) { + Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance); + Widget buildTransitions(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance, Widget child) { return child; } @@ -385,7 +411,7 @@ abstract class ModalRoute extends TransitionRoute with LocalHistoryRoute _scopeKey = new GlobalKey(); + final GlobalKey<_ModalScopeState> _scopeKey = new GlobalKey<_ModalScopeState>(); final GlobalKey _subtreeKey = new GlobalKey(); final PageStorageBucket _storageBucket = new PageStorageBucket(); @@ -408,9 +434,10 @@ abstract class ModalRoute extends TransitionRoute with LocalHistoryRoute extends PageRoute { final Widget child; Duration get transitionDuration => kMaterialPageRouteTransitionDuration; Color get barrierColor => null; - Widget buildPage(BuildContext context) => child; + Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) { + return child; + } } void main() {