Commit e26ead11 authored by justin's avatar justin

新增openInCurrentContainer 接口

parent accf615f
...@@ -31,7 +31,7 @@ class F2FFirstPageState extends State<F2FFirstPage>{ ...@@ -31,7 +31,7 @@ class F2FFirstPageState extends State<F2FFirstPage>{
RaisedButton( RaisedButton(
child: Text('Open second without native container'), child: Text('Open second without native container'),
onPressed: () { onPressed: () {
FlutterBoostAPI.singleton.open("f2f_second",noNeedNativeContainer: true); FlutterBoost.singleton.openInCurrentContainer("f2f_second");
}, },
), ),
], ],
......
...@@ -73,6 +73,11 @@ class ContainerCoordinator { ...@@ -73,6 +73,11 @@ class ContainerCoordinator {
return routeSettings; return routeSettings;
} }
bool isFlutterPageUrl(String url){
return _pageBuilders.containsKey(url);
}
Widget createPage(String name, Map params, String pageId) { Widget createPage(String name, Map params, String pageId) {
Widget page; Widget page;
......
...@@ -39,16 +39,18 @@ export 'flutter_boost_api.dart'; ...@@ -39,16 +39,18 @@ export 'flutter_boost_api.dart';
typedef Widget PageBuilder(String pageName, Map params, String uniqueId); typedef Widget PageBuilder(String pageName, Map params, String uniqueId);
typedef Route PrePushRoute( typedef Route PrePushRoute(String url, String uniqueId, Map params,
String url, String uniqueId, Map params, Route route); Route route);
typedef void PostPushRoute( typedef void PostPushRoute(String url, String uniqueId, Map params, Route route,
String url, String uniqueId, Map params, Route route, Future result); Future result);
typedef Route FlutterBoostRouteBuilder(Widget widget);
class FlutterBoost { class FlutterBoost {
static final FlutterBoost _instance = FlutterBoost(); static final FlutterBoost _instance = FlutterBoost();
final GlobalKey<ContainerManagerState> containerManagerKey = final GlobalKey<ContainerManagerState> containerManagerKey =
GlobalKey<ContainerManagerState>(); GlobalKey<ContainerManagerState>();
final ObserversHolder _observersHolder = ObserversHolder(); final ObserversHolder _observersHolder = ObserversHolder();
final BoostChannel _boostChannel = BoostChannel(); final BoostChannel _boostChannel = BoostChannel();
...@@ -72,15 +74,14 @@ class FlutterBoost { ...@@ -72,15 +74,14 @@ class FlutterBoost {
}); });
} }
static TransitionBuilder init( static TransitionBuilder init({TransitionBuilder builder,
{TransitionBuilder builder, PrePushRoute prePush,
PrePushRoute prePush, PostPushRoute postPush}) {
PostPushRoute postPush}) {
if (Platform.isAndroid) { if (Platform.isAndroid) {
onPageStart(); onPageStart();
} else if (Platform.isIOS) { } else if (Platform.isIOS) {
assert(() { assert(() {
() async { () async {
onPageStart(); onPageStart();
}(); }();
return true; return true;
...@@ -124,16 +125,51 @@ class FlutterBoost { ...@@ -124,16 +125,51 @@ class FlutterBoost {
Future<Map<dynamic, dynamic>> open(String url, Future<Map<dynamic, dynamic>> open(String url,
{Map<String, dynamic> urlParams, {Map<String, dynamic> urlParams,
Map<String, dynamic> exts}) { Map<String, dynamic> exts}) {
Map<String, dynamic> properties = new Map<String, dynamic>(); Map<String, dynamic> properties = new Map<String, dynamic>();
properties["url"] = url; properties["url"] = url;
properties["urlParams"] = urlParams; properties["urlParams"] = urlParams;
properties["exts"] = exts; properties["exts"] = exts;
//TODO 判断是不是需要跳Flutter,有没有前置拦截逻辑,如果都没有,就找到Navigator去把页面推进去 return channel.invokeMethod<Map<dynamic, dynamic>>('openPage', properties);
}
/**
*
* when flutter page->flutter page,do not open the new Activity Container
*
**/
Future<Map<dynamic, dynamic>> openInCurrentContainer(String url,
{Map<String, dynamic> urlParams,
Map<String, dynamic> exts,
FlutterBoostRouteBuilder routeBuilder}) {
return channel.invokeMethod<Map<dynamic, dynamic>>('openPage', properties); if(!ContainerCoordinator.singleton.isFlutterPageUrl(url)){
return open(url, urlParams: urlParams, exts: exts);
}
String uniqueId='${url}_${DateTime.now().millisecondsSinceEpoch}';
final Widget page = ContainerCoordinator.singleton.createPage(
url, urlParams, uniqueId);
final Route<Map<dynamic, dynamic>> route = routeBuilder != null
? routeBuilder(page)
: PageRouteBuilder<Map<dynamic, dynamic>>(
pageBuilder: (BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,) =>
page);
return FlutterBoost.containerManager?.onstageContainer?.push(route);
}
/**
* close flutter page but not close container
*/
bool closeInCurrentContainer<T extends Object>([T result]) {
return FlutterBoost.containerManager?.onstageContainer?.pop(result);
} }
Future<bool> close(String id, Future<bool> close(String id,
...@@ -197,7 +233,7 @@ class FlutterBoost { ...@@ -197,7 +233,7 @@ class FlutterBoost {
///register for Container lifecycle callbacks ///register for Container lifecycle callbacks
VoidCallback addBoostContainerLifeCycleObserver( VoidCallback addBoostContainerLifeCycleObserver(
BoostContainerLifeCycleObserver observer) => BoostContainerLifeCycleObserver observer) =>
_observersHolder.addObserver<BoostContainerLifeCycleObserver>(observer); _observersHolder.addObserver<BoostContainerLifeCycleObserver>(observer);
///register callbacks for Navigators push & pop ///register callbacks for Navigators push & pop
......
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