Commit 519b190c authored by Ian Hickson's avatar Ian Hickson

Merge pull request #745 from Hixie/yak2-better-transitions-api

Refactor forward transition building
parents 42eafce0 a83eadcc
...@@ -158,7 +158,7 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> { ...@@ -158,7 +158,7 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
return BottomSheet.createPerformance(); return BottomSheet.createPerformance();
} }
Widget buildPage(BuildContext context) { Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) {
return new _ModalBottomSheet(route: this); return new _ModalBottomSheet(route: this);
} }
} }
......
...@@ -127,9 +127,11 @@ class _DialogRoute<T> extends PopupRoute<T> { ...@@ -127,9 +127,11 @@ class _DialogRoute<T> extends PopupRoute<T> {
bool get barrierDismissable => true; bool get barrierDismissable => true;
Color get barrierColor => Colors.black54; 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( return new FadeTransition(
performance: performance, performance: performance,
opacity: new AnimatedValue<double>(0.0, end: 1.0, curve: Curves.easeOut), opacity: new AnimatedValue<double>(0.0, end: 1.0, curve: Curves.easeOut),
......
...@@ -168,7 +168,9 @@ class _DropDownRoute<T> extends PopupRoute<T> { ...@@ -168,7 +168,9 @@ class _DropDownRoute<T> extends PopupRoute<T> {
bool get barrierDismissable => true; bool get barrierDismissable => true;
Color get barrierColor => null; 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<T> extends StatelessComponent { class DropDownMenuItem<T> extends StatelessComponent {
......
...@@ -53,7 +53,7 @@ class MaterialPageRoute<T> extends PageRoute<T> { ...@@ -53,7 +53,7 @@ class MaterialPageRoute<T> extends PageRoute<T> {
Color get barrierColor => null; Color get barrierColor => null;
bool canTransitionFrom(TransitionRoute nextRoute) => false; bool canTransitionFrom(TransitionRoute nextRoute) => false;
Widget buildPage(BuildContext context) { Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) {
Widget result = builder(context); Widget result = builder(context);
assert(() { assert(() {
if (result == null) if (result == null)
...@@ -64,7 +64,7 @@ class MaterialPageRoute<T> extends PageRoute<T> { ...@@ -64,7 +64,7 @@ class MaterialPageRoute<T> extends PageRoute<T> {
return result; return result;
} }
Widget buildTransition(BuildContext context, PerformanceView performance, Widget child) { Widget buildTransitions(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance, Widget child) {
return new _MaterialPageTransition( return new _MaterialPageTransition(
performance: performance, performance: performance,
child: child child: child
......
...@@ -109,7 +109,9 @@ class _PopupMenuRoute<T> extends PopupRoute<T> { ...@@ -109,7 +109,9 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
bool get barrierDismissable => true; bool get barrierDismissable => true;
Color get barrierColor => null; 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<PopupMenuItem> items, int elevation: 8 }) { Future showMenu({ BuildContext context, ModalPosition position, List<PopupMenuItem> items, int elevation: 8 }) {
......
...@@ -13,7 +13,6 @@ import 'modal_barrier.dart'; ...@@ -13,7 +13,6 @@ import 'modal_barrier.dart';
import 'navigator.dart'; import 'navigator.dart';
import 'overlay.dart'; import 'overlay.dart';
import 'page_storage.dart'; import 'page_storage.dart';
import 'status_transitions.dart';
const _kTransparent = const Color(0x00000000); const _kTransparent = const Color(0x00000000);
...@@ -147,11 +146,12 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> { ...@@ -147,11 +146,12 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
} }
final ProxyPerformance forwardPerformance = new ProxyPerformance(); PerformanceView get forwardPerformance => _forwardPerformance;
final ProxyPerformance _forwardPerformance = new ProxyPerformance();
void didPushNext(Route nextRoute) { void didPushNext(Route nextRoute) {
if (nextRoute is TransitionRoute && canTransitionTo(nextRoute) && nextRoute.canTransitionFrom(this)) { if (nextRoute is TransitionRoute && canTransitionTo(nextRoute) && nextRoute.canTransitionFrom(this)) {
PerformanceView current = forwardPerformance.masterPerformance; PerformanceView current = _forwardPerformance.masterPerformance;
if (current != null) { if (current != null) {
if (current is TrainHoppingPerformance) { if (current is TrainHoppingPerformance) {
TrainHoppingPerformance newPerformance; TrainHoppingPerformance newPerformance;
...@@ -159,19 +159,19 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> { ...@@ -159,19 +159,19 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
current.currentTrain, current.currentTrain,
nextRoute.performance, nextRoute.performance,
onSwitchedTrain: () { onSwitchedTrain: () {
assert(forwardPerformance.masterPerformance == newPerformance); assert(_forwardPerformance.masterPerformance == newPerformance);
assert(newPerformance.currentTrain == nextRoute.performance); assert(newPerformance.currentTrain == nextRoute.performance);
forwardPerformance.masterPerformance = newPerformance.currentTrain; _forwardPerformance.masterPerformance = newPerformance.currentTrain;
newPerformance.dispose(); newPerformance.dispose();
} }
); );
forwardPerformance.masterPerformance = newPerformance; _forwardPerformance.masterPerformance = newPerformance;
current.dispose(); current.dispose();
} else { } else {
forwardPerformance.masterPerformance = new TrainHoppingPerformance(current, nextRoute.performance); _forwardPerformance.masterPerformance = new TrainHoppingPerformance(current, nextRoute.performance);
} }
} else { } else {
forwardPerformance.masterPerformance = nextRoute.performance; _forwardPerformance.masterPerformance = nextRoute.performance;
} }
} }
super.didPushNext(nextRoute); super.didPushNext(nextRoute);
...@@ -180,21 +180,6 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> { ...@@ -180,21 +180,6 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
bool canTransitionTo(TransitionRoute nextRoute) => true; bool canTransitionTo(TransitionRoute nextRoute) => true;
bool canTransitionFrom(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 get debugLabel => '$runtimeType';
String toString() => '$runtimeType(performance: $_performance)'; String toString() => '$runtimeType(performance: $_performance)';
} }
...@@ -270,44 +255,85 @@ class _ModalScopeStatus extends InheritedWidget { ...@@ -270,44 +255,85 @@ class _ModalScopeStatus extends InheritedWidget {
} }
} }
class _ModalScope extends StatusTransitionComponent { class _ModalScope extends StatefulComponent {
_ModalScope({ _ModalScope({
Key key, Key key,
this.subtreeKey, this.subtreeKey,
this.storageBucket, this.storageBucket,
PerformanceView performance, this.performance,
this.forwardPerformance,
this.current, this.current,
this.route this.route
}) : super(key: key, performance: performance); }) : super(key: key);
final GlobalKey subtreeKey; final GlobalKey subtreeKey;
final PageStorageBucket storageBucket; final PageStorageBucket storageBucket;
final PerformanceView performance;
final PerformanceView forwardPerformance;
final bool current; final bool current;
final ModalRoute route; 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 build(BuildContext context) {
Widget contents = new PageStorage( Widget contents = new PageStorage(
key: subtreeKey, key: config.subtreeKey,
bucket: storageBucket, bucket: config.storageBucket,
child: new _ModalScopeStatus( child: new _ModalScopeStatus(
current: current, current: config.current,
route: route, route: config.route,
child: route.buildPage(context) child: config.route.buildPage(context, config.performance, config.forwardPerformance)
) )
); );
if (route.offstage) { if (config.route.offstage) {
contents = new OffStage(child: contents); contents = new OffStage(child: contents);
} else { } else {
contents = new Focus( contents = new Focus(
key: new GlobalObjectKey(route), key: new GlobalObjectKey(config.route),
child: new IgnorePointer( child: new IgnorePointer(
ignoring: performance.status == PerformanceStatus.reverse, ignoring: config.performance?.status == PerformanceStatus.reverse,
child: route.wrapTransition(context, contents) child: config.route.buildTransitions(
context,
config.performance,
config.forwardPerformance,
contents
)
) )
); );
} }
contents = new RepaintBoundary(child: contents); contents = new RepaintBoundary(child: contents);
ModalPosition position = route.position; ModalPosition position = config.route.position;
if (position == null) if (position == null)
return contents; return contents;
return new Positioned( return new Positioned(
...@@ -347,8 +373,8 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T ...@@ -347,8 +373,8 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
// The API for subclasses to override - used by _ModalScope // The API for subclasses to override - used by _ModalScope
ModalPosition get position => null; ModalPosition get position => null;
Widget buildPage(BuildContext context); Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance);
Widget buildTransition(BuildContext context, PerformanceView performance, Widget child) { Widget buildTransitions(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance, Widget child) {
return child; return child;
} }
...@@ -385,7 +411,7 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T ...@@ -385,7 +411,7 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
// Internals // Internals
final GlobalKey<StatusTransitionState> _scopeKey = new GlobalKey<StatusTransitionState>(); final GlobalKey<_ModalScopeState> _scopeKey = new GlobalKey<_ModalScopeState>();
final GlobalKey _subtreeKey = new GlobalKey(); final GlobalKey _subtreeKey = new GlobalKey();
final PageStorageBucket _storageBucket = new PageStorageBucket(); final PageStorageBucket _storageBucket = new PageStorageBucket();
...@@ -408,9 +434,10 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T ...@@ -408,9 +434,10 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
subtreeKey: _subtreeKey, subtreeKey: _subtreeKey,
storageBucket: _storageBucket, storageBucket: _storageBucket,
performance: performance, performance: performance,
forwardPerformance: forwardPerformance,
current: isCurrent, current: isCurrent,
route: this route: this
// calls buildTransition()/buildForwardTransition() and buildPage(), defined above // calls buildTransitions() and buildPage(), defined above
); );
} }
......
...@@ -30,7 +30,9 @@ class TestRoute<T> extends PageRoute<T> { ...@@ -30,7 +30,9 @@ class TestRoute<T> extends PageRoute<T> {
final Widget child; final Widget child;
Duration get transitionDuration => kMaterialPageRouteTransitionDuration; Duration get transitionDuration => kMaterialPageRouteTransitionDuration;
Color get barrierColor => null; Color get barrierColor => null;
Widget buildPage(BuildContext context) => child; Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) {
return child;
}
} }
void main() { void main() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment