Commit b55554f0 authored by xgz's avatar xgz

修改flutter动画

parent 5822c69d
......@@ -42,19 +42,18 @@ export 'container/container_coordinator.dart' show BoostRouteSettings;
typedef Widget PageBuilder(String pageName, Map params, String uniqueId);
typedef Route PrePushRoute(String url, String uniqueId, Map params,
Route route);
typedef Route PrePushRoute(
String url, String uniqueId, Map params, Route route);
typedef void PostPushRoute(String url, String uniqueId, Map params, Route route,
Future result);
typedef void PostPushRoute(
String url, String uniqueId, Map params, Route route, Future result);
typedef Route FlutterBoostRouteBuilder(Widget widget);
class FlutterBoost {
static final FlutterBoost _instance = FlutterBoost();
final GlobalKey<ContainerManagerState> containerManagerKey =
GlobalKey<ContainerManagerState>();
GlobalKey<ContainerManagerState>();
final ObserversHolder _observersHolder = ObserversHolder();
final BoostChannel _boostChannel = BoostChannel();
......@@ -84,14 +83,15 @@ class FlutterBoost {
});
}
static TransitionBuilder init({TransitionBuilder builder,
PrePushRoute prePush,
PostPushRoute postPush}) {
static TransitionBuilder init(
{TransitionBuilder builder,
PrePushRoute prePush,
PostPushRoute postPush}) {
if (Platform.isAndroid) {
onPageStart();
} else if (Platform.isIOS) {
assert(() {
() async {
() async {
onPageStart();
}();
return true;
......@@ -139,8 +139,7 @@ class FlutterBoost {
}
Future<Map<dynamic, dynamic>> open(String url,
{Map<String, dynamic> urlParams,
Map<String, dynamic> exts}) {
{Map<String, dynamic> urlParams, Map<String, dynamic> exts}) {
Map<String, dynamic> properties = new Map<String, dynamic>();
properties["url"] = url;
properties["urlParams"] = urlParams;
......@@ -148,7 +147,6 @@ class FlutterBoost {
return channel.invokeMethod<Map<dynamic, dynamic>>('openPage', properties);
}
/**
*
* when flutter page->flutter page,do not open the new Activity Container
......@@ -156,8 +154,8 @@ class FlutterBoost {
**/
Future<Map<dynamic, dynamic>> openInCurrentContainer(String url,
{Map<String, dynamic> urlParams,
Map<String, dynamic> exts,
FlutterBoostRouteBuilder routeBuilder}) {
Map<String, dynamic> exts,
FlutterBoostRouteBuilder routeBuilder}) {
final BoostRouteSettings routeSettings = ContainerCoordinator.singleton
.createRouteSettings(url, urlParams: urlParams, exts: exts);
......@@ -168,9 +166,12 @@ class FlutterBoost {
return open(url, urlParams: urlParams, exts: exts);
}
final Route<Map<dynamic, dynamic>> route = routeBuilder != null
Route<Map<dynamic, dynamic>> route = routeBuilder != null
? routeBuilder(page)
: defaultRoute(page, routeSettings);
if (exts != null && exts.containsKey('present')) {
route = presentStyleRoute(page, routeSettings);
}
GlobalRouteSettingsManager.instance.addSettings(route, routeSettings);
......@@ -178,26 +179,23 @@ class FlutterBoost {
return FlutterBoost.containerManager?.onstageContainer?.push(route);
}
Route<Map<dynamic, dynamic>> defaultRoute(Widget page,
BoostRouteSettings settings) {
RouteSettings routeSettings = new RouteSettings(
name: settings.name, arguments: settings.params);
Route<Map<dynamic, dynamic>> defaultRoute(
Widget page, BoostRouteSettings settings) {
RouteSettings routeSettings =
new RouteSettings(name: settings.name, arguments: settings.params);
if (Platform.isIOS) {
return CupertinoPageRoute<Map<dynamic, dynamic>>(
settings: routeSettings,
builder: (BuildContext context) => page
);
settings: routeSettings, builder: (BuildContext context) => page);
}
return PageRouteBuilder(
transitionDuration: Duration(milliseconds: 300),
settings: routeSettings,
pageBuilder: (context, animation, secondaryAnimation) => page,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
var offsetAnimation = Tween<Offset>(
begin: Offset(1.0, 0.0), end: Offset(0.0, 0.0))
.animate(
CurvedAnimation(parent: animation, curve: Curves.fastOutSlowIn));
var offsetAnimation =
Tween<Offset>(begin: Offset(1.0, 0.0), end: Offset(0.0, 0.0))
.animate(CurvedAnimation(
parent: animation, curve: Curves.fastOutSlowIn));
return SlideTransition(
position: offsetAnimation,
child: child,
......@@ -205,6 +203,31 @@ class FlutterBoost {
});
}
//从下往上的跳转动画
Route<Map<dynamic, dynamic>> presentStyleRoute(
Widget page, BoostRouteSettings settings) {
RouteSettings routeSettings =
new RouteSettings(name: settings.name, arguments: settings.params);
// if (Platform.isIOS) {
// return CupertinoPageRoute<Map<dynamic, dynamic>>(
// settings: routeSettings, builder: (BuildContext context) => page,
// );
// }
return PageRouteBuilder(
transitionDuration: Duration(milliseconds: 300),
settings: routeSettings,
pageBuilder: (context, animation, secondaryAnimation) => page,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
return SlideTransition(
position:
Tween<Offset>(begin: Offset(0.0, 1.0), end: Offset(0.0, 0.0))
.animate(CurvedAnimation(
parent: animation, curve: Curves.fastOutSlowIn)),
child: child,
);
});
}
/**
* close flutter page but not close container if there has more than one page in contaienr
*/
......@@ -284,7 +307,7 @@ class FlutterBoost {
///register for Container lifecycle callbacks
VoidCallback addBoostContainerLifeCycleObserver(
BoostContainerLifeCycleObserver observer) =>
BoostContainerLifeCycleObserver observer) =>
_observersHolder.addObserver<BoostContainerLifeCycleObserver>(observer);
///unregister for Container changed callbacks
......@@ -293,8 +316,9 @@ class FlutterBoost {
///unregister for Container lifecycle callbacks
void removeBoostContainerLifeCycleObserver(
BoostContainerLifeCycleObserver observer) =>
_observersHolder.removeObserver<BoostContainerLifeCycleObserver>(observer);
BoostContainerLifeCycleObserver observer) =>
_observersHolder
.removeObserver<BoostContainerLifeCycleObserver>(observer);
///register callbacks for Navigators push & pop
void addBoostNavigatorObserver(NavigatorObserver observer) =>
......
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