Commit a5a01532 authored by justin's avatar justin Committed by GitHub

Merge pull request #556 from sundayman/master

解决iOS hot restart 白屏问题
parents 81925f8e 6c758ae6
...@@ -44,7 +44,6 @@ typedef void PostPushRoute( ...@@ -44,7 +44,6 @@ typedef void PostPushRoute(
String url, String uniqueId, Map params, Route route, Future result); String url, String uniqueId, Map params, Route route, Future result);
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>();
...@@ -56,23 +55,14 @@ class FlutterBoost { ...@@ -56,23 +55,14 @@ class FlutterBoost {
static ContainerManagerState get containerManager => static ContainerManagerState get containerManager =>
_instance.containerManagerKey.currentState; _instance.containerManagerKey.currentState;
static TransitionBuilder init( static void onPageStart() {
{TransitionBuilder builder, WidgetsBinding.instance.addPostFrameCallback((_) {
PrePushRoute prePush, singleton.channel.invokeMethod<Map>('pageOnStart').then((Map pageInfo) {
PostPushRoute postPush}) {
if(Platform.isAndroid){
WidgetsBinding.instance.addPostFrameCallback((_){
singleton.channel.invokeMethod<Map>('pageOnStart').then((Map pageInfo){
if (pageInfo == null || pageInfo.isEmpty) return; if (pageInfo == null || pageInfo.isEmpty) return;
if (pageInfo.containsKey("name") && if (pageInfo.containsKey("name") &&
pageInfo.containsKey("params") && pageInfo.containsKey("params") &&
pageInfo.containsKey("uniqueId")) { pageInfo.containsKey("uniqueId")) {
ContainerCoordinator.singleton.nativeContainerDidShow( ContainerCoordinator.singleton.nativeContainerDidShow(
pageInfo["name"], pageInfo["params"], pageInfo["uniqueId"]); pageInfo["name"], pageInfo["params"], pageInfo["uniqueId"]);
} }
...@@ -80,6 +70,22 @@ class FlutterBoost { ...@@ -80,6 +70,22 @@ class FlutterBoost {
}); });
} }
static TransitionBuilder init(
{TransitionBuilder builder,
PrePushRoute prePush,
PostPushRoute postPush}) {
if (Platform.isAndroid) {
onPageStart();
}
assert(() {
() async {
if (Platform.isIOS) {
onPageStart();
}
}();
return true;
}());
return (BuildContext context, Widget child) { return (BuildContext context, Widget child) {
assert(child is Navigator, 'child must be Navigator, what is wrong?'); assert(child is Navigator, 'child must be Navigator, what is wrong?');
...@@ -102,7 +108,7 @@ class FlutterBoost { ...@@ -102,7 +108,7 @@ class FlutterBoost {
BoostChannel get channel => _boostChannel; BoostChannel get channel => _boostChannel;
FlutterBoost(){ FlutterBoost() {
ContainerCoordinator(_boostChannel); ContainerCoordinator(_boostChannel);
} }
...@@ -116,30 +122,29 @@ class FlutterBoost { ...@@ -116,30 +122,29 @@ class FlutterBoost {
ContainerCoordinator.singleton.registerPageBuilders(builders); ContainerCoordinator.singleton.registerPageBuilders(builders);
} }
Future<Map<dynamic,dynamic>> open(String url,{Map<dynamic,dynamic> urlParams,Map<dynamic,dynamic> exts}){ Future<Map<dynamic, dynamic>> open(String url,
{Map<dynamic, dynamic> urlParams, Map<dynamic, dynamic> exts}) {
Map<dynamic, dynamic> properties = new Map<dynamic, dynamic>(); Map<dynamic, dynamic> properties = new Map<dynamic, dynamic>();
properties["url"] = url; properties["url"] = url;
properties["urlParams"] = urlParams; properties["urlParams"] = urlParams;
properties["exts"] = exts; properties["exts"] = exts;
return channel.invokeMethod<Map<dynamic,dynamic>>( return channel.invokeMethod<Map<dynamic, dynamic>>('openPage', properties);
'openPage', properties);
} }
Future<bool> close(String id,{Map<dynamic,dynamic> result,Map<dynamic,dynamic> exts}){ Future<bool> close(String id,
{Map<dynamic, dynamic> result, Map<dynamic, dynamic> exts}) {
assert(id != null); assert(id != null);
BoostContainerSettings settings = containerManager?.onstageSettings; BoostContainerSettings settings = containerManager?.onstageSettings;
Map<dynamic, dynamic> properties = new Map<dynamic, dynamic>(); Map<dynamic, dynamic> properties = new Map<dynamic, dynamic>();
if(exts == null){ if (exts == null) {
exts = Map<dynamic,dynamic>(); exts = Map<dynamic, dynamic>();
} }
exts["params"] = settings.params; exts["params"] = settings.params;
if(!exts.containsKey("animated")){ if (!exts.containsKey("animated")) {
exts["animated"] = true; exts["animated"] = true;
} }
...@@ -155,28 +160,30 @@ class FlutterBoost { ...@@ -155,28 +160,30 @@ class FlutterBoost {
return channel.invokeMethod<bool>('closePage', properties); return channel.invokeMethod<bool>('closePage', properties);
} }
Future<bool> closeCurrent({Map<String,dynamic> result,Map<String,dynamic> exts}) { Future<bool> closeCurrent(
{Map<String, dynamic> result, Map<String, dynamic> exts}) {
BoostContainerSettings settings = containerManager?.onstageSettings; BoostContainerSettings settings = containerManager?.onstageSettings;
if(exts == null){ if (exts == null) {
exts = Map<String,dynamic>(); exts = Map<String, dynamic>();
} }
exts["params"] = settings.params; exts["params"] = settings.params;
if(!exts.containsKey("animated")){ if (!exts.containsKey("animated")) {
exts["animated"] = true; exts["animated"] = true;
} }
return close(settings.uniqueId,result: result,exts: exts); return close(settings.uniqueId, result: result, exts: exts);
} }
Future<bool> closeByContext(BuildContext context,{Map<String,dynamic> result,Map<String,dynamic> exts}) { Future<bool> closeByContext(BuildContext context,
{Map<String, dynamic> result, Map<String, dynamic> exts}) {
BoostContainerSettings settings = containerManager?.onstageSettings; BoostContainerSettings settings = containerManager?.onstageSettings;
if(exts == null){ if (exts == null) {
exts = Map<String,dynamic>(); exts = Map<String, dynamic>();
} }
exts["params"] = settings.params; exts["params"] = settings.params;
if(!exts.containsKey("animated")){ if (!exts.containsKey("animated")) {
exts["animated"] = true; exts["animated"] = true;
} }
return close(settings.uniqueId,result: result,exts: exts); return close(settings.uniqueId, result: result, exts: exts);
} }
///register for Container changed callbacks ///register for Container changed callbacks
...@@ -191,6 +198,4 @@ class FlutterBoost { ...@@ -191,6 +198,4 @@ class FlutterBoost {
///register callbacks for Navigators push & pop ///register callbacks for Navigators push & pop
VoidCallback addBoostNavigatorObserver(BoostNavigatorObserver observer) => VoidCallback addBoostNavigatorObserver(BoostNavigatorObserver observer) =>
_observersHolder.addObserver<BoostNavigatorObserver>(observer); _observersHolder.addObserver<BoostNavigatorObserver>(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