mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Merge pull request #745 from Hixie/yak2-better-transitions-api
Refactor forward transition building
This commit is contained in:
commit
519b190c0f
@ -158,7 +158,7 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
|
||||
return BottomSheet.createPerformance();
|
||||
}
|
||||
|
||||
Widget buildPage(BuildContext context) {
|
||||
Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) {
|
||||
return new _ModalBottomSheet(route: this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,9 +127,11 @@ class _DialogRoute<T> extends PopupRoute<T> {
|
||||
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<double>(0.0, end: 1.0, curve: Curves.easeOut),
|
||||
|
||||
@ -168,7 +168,9 @@ class _DropDownRoute<T> extends PopupRoute<T> {
|
||||
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<T> extends StatelessComponent {
|
||||
|
||||
@ -53,7 +53,7 @@ class MaterialPageRoute<T> extends PageRoute<T> {
|
||||
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<T> extends PageRoute<T> {
|
||||
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
|
||||
|
||||
@ -109,7 +109,9 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
|
||||
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<PopupMenuItem> items, int elevation: 8 }) {
|
||||
|
||||
@ -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<T> extends OverlayRoute<T> {
|
||||
}
|
||||
|
||||
|
||||
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<T> extends OverlayRoute<T> {
|
||||
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<T> extends OverlayRoute<T> {
|
||||
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<T> extends TransitionRoute<T> with LocalHistoryRoute<T
|
||||
// The API for subclasses to override - used by _ModalScope
|
||||
|
||||
ModalPosition get position => 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<T> extends TransitionRoute<T> with LocalHistoryRoute<T
|
||||
|
||||
// Internals
|
||||
|
||||
final GlobalKey<StatusTransitionState> _scopeKey = new GlobalKey<StatusTransitionState>();
|
||||
final GlobalKey<_ModalScopeState> _scopeKey = new GlobalKey<_ModalScopeState>();
|
||||
final GlobalKey _subtreeKey = new GlobalKey();
|
||||
final PageStorageBucket _storageBucket = new PageStorageBucket();
|
||||
|
||||
@ -408,9 +434,10 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
|
||||
subtreeKey: _subtreeKey,
|
||||
storageBucket: _storageBucket,
|
||||
performance: performance,
|
||||
forwardPerformance: forwardPerformance,
|
||||
current: isCurrent,
|
||||
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> {
|
||||
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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user