Commit dd9d72e5 authored by yangwu.jia's avatar yangwu.jia

修复FLUTTER_ACTIVITY_CREATED 模式下的问题

parent 0d019c12
package com.idlefish.flutterboost; package com.idlefish.flutterboost;
import android.os.Handler;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.idlefish.flutterboost.interfaces.IContainerRecord; import com.idlefish.flutterboost.interfaces.IContainerRecord;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.*;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel;
...@@ -217,6 +215,9 @@ public class FlutterBoostPlugin { ...@@ -217,6 +215,9 @@ public class FlutterBoostPlugin {
} }
result.success(pageInfo); result.success(pageInfo);
NewFlutterBoost.instance().setFlutterPostFrameCallTime(new Date().getTime());
} catch (Throwable t) { } catch (Throwable t) {
result.error("no flutter page found!", t.getMessage(), t); result.error("no flutter page found!", t.getMessage(), t);
} }
......
...@@ -31,6 +31,15 @@ public class NewFlutterBoost { ...@@ -31,6 +31,15 @@ public class NewFlutterBoost {
private PluginRegistry mRegistry; private PluginRegistry mRegistry;
static NewFlutterBoost sInstance = null; static NewFlutterBoost sInstance = null;
private long FlutterPostFrameCallTime=0;
public long getFlutterPostFrameCallTime(){
return FlutterPostFrameCallTime;
}
public void setFlutterPostFrameCallTime(long FlutterPostFrameCallTime){
this.FlutterPostFrameCallTime=FlutterPostFrameCallTime;
}
public static NewFlutterBoost instance() { public static NewFlutterBoost instance() {
if (sInstance == null) { if (sInstance == null) {
sInstance = new NewFlutterBoost(); sInstance = new NewFlutterBoost();
......
...@@ -3,6 +3,7 @@ package com.idlefish.flutterboost.containers; ...@@ -3,6 +3,7 @@ package com.idlefish.flutterboost.containers;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
...@@ -18,6 +19,8 @@ import io.flutter.embedding.android.SplashScreen; ...@@ -18,6 +19,8 @@ import io.flutter.embedding.android.SplashScreen;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener; import io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener;
import java.util.Date;
/** /**
* {@code View} that displays a {@link SplashScreen} until a given {@link FlutterView} * {@code View} that displays a {@link SplashScreen} until a given {@link FlutterView}
* renders its first frame. * renders its first frame.
...@@ -39,7 +42,7 @@ public class FlutterSplashView extends FrameLayout { ...@@ -39,7 +42,7 @@ public class FlutterSplashView extends FrameLayout {
@Nullable @Nullable
private String previousCompletedSplashIsolate; private String previousCompletedSplashIsolate;
private boolean hasRendered=false; private Handler handler = new Handler();
@NonNull @NonNull
private final FlutterView.FlutterEngineAttachmentListener flutterEngineAttachmentListener = new FlutterView.FlutterEngineAttachmentListener() { private final FlutterView.FlutterEngineAttachmentListener flutterEngineAttachmentListener = new FlutterView.FlutterEngineAttachmentListener() {
...@@ -57,11 +60,40 @@ public class FlutterSplashView extends FrameLayout { ...@@ -57,11 +60,40 @@ public class FlutterSplashView extends FrameLayout {
@NonNull @NonNull
private final OnFirstFrameRenderedListener onFirstFrameRenderedListener = new OnFirstFrameRenderedListener() { private final OnFirstFrameRenderedListener onFirstFrameRenderedListener = new OnFirstFrameRenderedListener() {
int i=0;
@Override @Override
public void onFirstFrameRendered() { public void onFirstFrameRendered() {
if (splashScreen != null) {
transitionToFlutter(); if(NewFlutterBoost.instance().platform().whenEngineStart()== NewFlutterBoost.ConfigBuilder.FLUTTER_ACTIVITY_CREATED){
long now=new Date().getTime();
long flutterPostFrameCallTime=NewFlutterBoost.instance().getFlutterPostFrameCallTime();
if(flutterPostFrameCallTime!=0&& (now-flutterPostFrameCallTime)>800){
if (splashScreen != null) {
transitionToFlutter();
}
return;
}
handler.postDelayed(new Runnable() {
@Override
public void run() {
onFirstFrameRenderedListener.onFirstFrameRendered();
}
}, 200);
}else{
if (splashScreen != null) {
transitionToFlutter();
}
} }
} }
}; };
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
import 'dart:async'; import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'container/boost_container.dart'; import 'container/boost_container.dart';
...@@ -60,6 +61,26 @@ class FlutterBoost { ...@@ -60,6 +61,26 @@ class FlutterBoost {
PrePushRoute prePush, PrePushRoute prePush,
PostPushRoute postPush}) { PostPushRoute postPush}) {
if(Platform.isAndroid){
WidgetsBinding.instance.addPostFrameCallback((_){
singleton.channel.invokeMethod<Map>('pageOnStart').then((Map pageInfo){
if (pageInfo == null || pageInfo.isEmpty) return;
if (pageInfo.containsKey("name") &&
pageInfo.containsKey("params") &&
pageInfo.containsKey("uniqueId")) {
ContainerCoordinator.singleton.nativeContainerDidShow(
pageInfo["name"], pageInfo["params"], pageInfo["uniqueId"]);
}
});
});
}
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?');
......
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