Commit 092117c2 authored by yangwu.jia's avatar yangwu.jia

Merge branch 'master' into v0.1.61-androidx-hotfixes

# Conflicts:
#	README.md
#	README_CN.md
#	android/src/main/java/com/idlefish/flutterboost/FlutterBoostPlugin.java
#	android/src/main/java/com/idlefish/flutterboost/FlutterViewContainerManager.java
parents 8adac44a 1720a621
---
name: Bug report
about: Describe this issue template's purpose here.
title: ''
labels: ''
assignees: ''
---
<!-- Thank you for using Flutter Boost!
If you are looking for support about how to get start, please read README first
-->
## Steps to Reproduce
**A small application to reproduce the bug(最小化可复现的demo)**
<!--
Please tell us exactly how to reproduce the problem you are running into.
Please attach a small application (ideally just one main.dart file) that
reproduces the problem. You could use https://gist.github.com/ for this.
If the problem is with your application's rendering, then please attach
a screenshot and explain what the problem is.
-->
1. ...
2. ...
3. ...
<!--
Please tell us which target platform(s) the problem occurs (Android / iOS / Web / macOS / Linux / Windows)
Which target OS version, for Web, browser, is the test system running?
Does the problem occur on emulator/simulator as well as on physical devices?
-->
**Flutter Boost Version**
**Target Platform:**
**Target OS version/browser:**
**Devices:**
## Logs
add your crash log or something else.
<!-- Finally, paste the output of running `flutter doctor -v` here. -->
```
```
......@@ -9,6 +9,35 @@ The main changes are as following:
4. We did some code refactoring, the main logic became more straightforward.
## 0.1.60
A better implementation to support Flutter v1.9.1+hotfixes
Change the content
android:
1. based on the v1.9.1+hotfixes branch of flutter
2. Solve major bugs, such as page parameter passing
3. Support platformview
4. Support androidx branch :feature/flutter_1.9_androidx_upgrade
5. Resolve memory leaks
6. Rewrite part of the code
7. API changes
8. Improved demo and added many demo cases
ios:
1.based on the v1.9.1+hotfixes branch of flutter
2.bugfixed
## 0.1.61
android:
Fixed bugs
iOS:
no change
### API changes
From the point of API changes, we did some refactoring as following:
#### iOS API changes
......
This diff is collapsed.
This diff is collapsed.
......@@ -5,7 +5,6 @@ import android.content.Context;
import androidx.annotation.NonNull;
import io.flutter.Log;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.BinaryMessenger;
......@@ -46,8 +45,8 @@ class BoostRegistrar implements Registrar, FlutterPlugin, ActivityAware {
if(this.activityPluginBinding != null){
return this.activityPluginBinding.getActivity();
}
if(NewFlutterBoost.instance().currentActivity()!=null){
return NewFlutterBoost.instance().currentActivity();
if(FlutterBoost.instance().currentActivity()!=null){
return FlutterBoost.instance().currentActivity();
}
return null;
}
......
......@@ -154,7 +154,7 @@ public class ContainerRecord implements IContainerRecord {
map.put("name", mContainer.getContainerUrl());
map.put("uniqueId", mUniqueId);
NewFlutterBoost.instance().channel().sendEvent("lifecycle", map);
FlutterBoost.instance().channel().sendEvent("lifecycle", map);
// mContainer.getBoostFlutterView().onBackPressed();
}
......@@ -253,7 +253,7 @@ public class ContainerRecord implements IContainerRecord {
args.put("pageName", url);
args.put("params", params);
args.put("uniqueId", uniqueId);
NewFlutterBoost.instance().channel().invokeMethod(method, args);
FlutterBoost.instance().channel().invokeMethod(method, args);
}
public void invokeChannelUnsafe(String method, String url, Map params, String uniqueId) {
......@@ -261,7 +261,7 @@ public class ContainerRecord implements IContainerRecord {
args.put("pageName", url);
args.put("params", params);
args.put("uniqueId", uniqueId);
NewFlutterBoost.instance().channel().invokeMethodUnsafe(method, args);
FlutterBoost.instance().channel().invokeMethodUnsafe(method, args);
}
}
......
......@@ -60,7 +60,7 @@ public class Debuger {
public static boolean isDebug(){
try {
return NewFlutterBoost.instance().platform().isDebug();
return FlutterBoost.instance().platform().isDebug();
}catch (Throwable t){
return false;
}
......
......@@ -7,13 +7,10 @@ import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import com.idlefish.flutterboost.interfaces.*;
import io.flutter.Log;
import io.flutter.embedding.android.FlutterView;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.view.FlutterMain;
......@@ -21,7 +18,7 @@ import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
public class NewFlutterBoost {
public class FlutterBoost {
private Platform mPlatform;
......@@ -29,20 +26,21 @@ public class NewFlutterBoost {
private FlutterEngine mEngine;
private Activity mCurrentActiveActivity;
private PluginRegistry mRegistry;
static NewFlutterBoost sInstance = null;
static FlutterBoost sInstance = null;
private long FlutterPostFrameCallTime=0;
private long FlutterPostFrameCallTime = 0;
public long getFlutterPostFrameCallTime(){
public long getFlutterPostFrameCallTime() {
return FlutterPostFrameCallTime;
}
public void setFlutterPostFrameCallTime(long FlutterPostFrameCallTime){
this.FlutterPostFrameCallTime=FlutterPostFrameCallTime;
public void setFlutterPostFrameCallTime(long FlutterPostFrameCallTime) {
this.FlutterPostFrameCallTime = FlutterPostFrameCallTime;
}
public static NewFlutterBoost instance() {
public static FlutterBoost instance() {
if (sInstance == null) {
sInstance = new NewFlutterBoost();
sInstance = new FlutterBoost();
}
return sInstance;
}
......@@ -53,19 +51,13 @@ public class NewFlutterBoost {
mPlatform = platform;
mManager = new FlutterViewContainerManager();
platform.getApplication().registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
Log.e("bbbb1", "xxxxx");
mCurrentActiveActivity=activity;
mCurrentActiveActivity = activity;
if (mPlatform.whenEngineStart() == ConfigBuilder.ANY_ACTIVITY_CREATED) {
Log.e("bbbb2", "xxxxx");
doInitialFlutter();
}
}
......@@ -133,33 +125,24 @@ public class NewFlutterBoost {
}
}
public void doInitialFlutter() {
if(mEngine!=null) return;
if (mEngine != null) return;
FlutterEngine flutterEngine = createEngine();
if(mPlatform.lifecycleListener!=null){
if (mPlatform.lifecycleListener != null) {
mPlatform.lifecycleListener.onEngineCreated();
}
if (flutterEngine.getDartExecutor().isExecutingDart()) {
// No warning is logged because this situation will happen on every config
// change if the developer does not choose to retain the Fragment instance.
// So this is expected behavior in many cases.
return;
}
// The engine needs to receive the Flutter app's initial route before executing any
// Dart code to ensure that the initial route arrives in time to be applied.
if (mPlatform.initialRoute() != null) {
flutterEngine.getNavigationChannel().setInitialRoute(mPlatform.initialRoute());
}
// Configure the Dart entrypoint and execute it.
DartExecutor.DartEntrypoint entrypoint = new DartExecutor.DartEntrypoint(
FlutterMain.findAppBundlePath(),
"main"
......@@ -167,7 +150,7 @@ public class NewFlutterBoost {
flutterEngine.getDartExecutor().executeDartEntrypoint(entrypoint);
mRegistry = new BoostPluginRegistry(createEngine());
registerPlugins();
mPlatform.registerPlugins(mRegistry);
}
......@@ -202,6 +185,10 @@ public class NewFlutterBoost {
private BoostLifecycleListener lifecycleListener;
private BoostPluginsRegister boostPluginsRegister;
public ConfigBuilder(Application app, INativeRouter router) {
this.router = router;
this.mApp = app;
......@@ -227,19 +214,24 @@ public class NewFlutterBoost {
return this;
}
public ConfigBuilder whenEngineStart( int whenEngineStart) {
public ConfigBuilder whenEngineStart(int whenEngineStart) {
this.whenEngineStart = whenEngineStart;
return this;
}
public ConfigBuilder whenEngineDestory( int whenEngineDestory) {
public ConfigBuilder whenEngineDestory(int whenEngineDestory) {
this.whenEngineDestory = whenEngineDestory;
return this;
}
public ConfigBuilder lifecycleListener( BoostLifecycleListener lifecycleListener) {
public ConfigBuilder lifecycleListener(BoostLifecycleListener lifecycleListener) {
this.lifecycleListener = lifecycleListener;
return this;
}
public ConfigBuilder pluginsRegister(BoostPluginsRegister boostPluginsRegister) {
this.boostPluginsRegister = boostPluginsRegister;
return this;
}
public Platform build() {
Platform platform = new Platform() {
......@@ -277,8 +269,8 @@ public class NewFlutterBoost {
}
};
platform.lifecycleListener=this.lifecycleListener;
platform.lifecycleListener = this.lifecycleListener;
platform.pluginsRegister=this.boostPluginsRegister;
return platform;
}
......@@ -305,11 +297,11 @@ public class NewFlutterBoost {
return mManager.findContainerById(id);
}
public PluginRegistry getPluginRegistry(){
public PluginRegistry getPluginRegistry() {
return mRegistry;
}
private FlutterEngine createEngine(){
private FlutterEngine createEngine() {
if (mEngine == null) {
FlutterMain.startInitialization(mPlatform.getApplication());
......@@ -324,44 +316,36 @@ public class NewFlutterBoost {
}
private void registerPlugins() {
try {
Class clz = Class.forName("io.flutter.plugins.GeneratedPluginRegistrant");
Method method = clz.getDeclaredMethod("registerWith", PluginRegistry.class);
method.invoke(null, mRegistry);
} catch (Throwable t) {
throw new RuntimeException(t);
}
if(mPlatform.lifecycleListener!=null){
mPlatform.lifecycleListener.onPluginsRegistered();
}
}
public FlutterEngine engineProvider() {
return mEngine;
}
public void boostDestroy(){
if(mEngine!=null){
public void boostDestroy() {
if (mEngine != null) {
mEngine.destroy();
}
if(mPlatform.lifecycleListener!=null){
if (mPlatform.lifecycleListener != null) {
mPlatform.lifecycleListener.onEngineDestroy();
}
mEngine=null;
mRegistry=null;
mCurrentActiveActivity=null;
mEngine = null;
mRegistry = null;
mCurrentActiveActivity = null;
}
public interface BoostLifecycleListener {
void onEngineCreated();
void onPluginsRegistered();
void onEngineDestroy();
}
public interface BoostPluginsRegister {
void registerPlugins(PluginRegistry mRegistry);
}
}
......@@ -47,13 +47,6 @@ public class FlutterBoostPlugin {
a.onChannelRegistered(sInstance);
}
// if (NewFlutterBoost.instance() != null) {
// final IStateListener stateListener = NewFlutterBoost.instance().mStateListener;
// if (stateListener != null) {
// stateListener.onChannelRegistered(registrar, sInstance);
// }
// }
sActions.clear();
}
......@@ -196,7 +189,7 @@ public class FlutterBoostPlugin {
@Override
public void onMethodCall(MethodCall methodCall, final MethodChannel.Result result) {
FlutterViewContainerManager mManager = (FlutterViewContainerManager) NewFlutterBoost.instance().containerManager();
FlutterViewContainerManager mManager = (FlutterViewContainerManager) FlutterBoost.instance().containerManager();
switch (methodCall.method) {
case "pageOnStart": {
Map<String, Object> pageInfo = new HashMap<>();
......@@ -215,7 +208,7 @@ public class FlutterBoostPlugin {
}
result.success(pageInfo);
NewFlutterBoost.instance().setFlutterPostFrameCallTime(new Date().getTime());
FlutterBoost.instance().setFlutterPostFrameCallTime(new Date().getTime());
} catch (Throwable t) {
......
......@@ -25,7 +25,6 @@ package com.idlefish.flutterboost;
import android.content.Context;
import android.text.TextUtils;
import android.util.SparseArray;
import com.idlefish.flutterboost.interfaces.IContainerManager;
import com.idlefish.flutterboost.interfaces.IContainerRecord;
......@@ -41,7 +40,6 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.concurrent.atomic.AtomicInteger;
public class FlutterViewContainerManager implements IContainerManager {
......@@ -85,8 +83,8 @@ public class FlutterViewContainerManager implements IContainerManager {
mRecordStack.remove(record);
mRecordMap.remove(record.getContainer());
if(mRecordMap.isEmpty()){
if( NewFlutterBoost.instance().platform().whenEngineDestroy()== NewFlutterBoost.ConfigBuilder.All_FLUTTER_ACTIVITY_DESTROY){
NewFlutterBoost.instance().boostDestroy();
if( FlutterBoost.instance().platform().whenEngineDestroy()== FlutterBoost.ConfigBuilder.All_FLUTTER_ACTIVITY_DESTROY){
FlutterBoost.instance().boostDestroy();
}
}
......@@ -118,9 +116,9 @@ public class FlutterViewContainerManager implements IContainerManager {
}
void openContainer(String url, Map<String, Object> urlParams, Map<String, Object> exts,OnResult onResult) {
Context context = NewFlutterBoost.instance().currentActivity();
Context context = FlutterBoost.instance().currentActivity();
if(context == null) {
context =NewFlutterBoost.instance().platform().getApplication();
context = FlutterBoost.instance().platform().getApplication();
}
if(urlParams == null) {
......@@ -141,7 +139,7 @@ public class FlutterViewContainerManager implements IContainerManager {
mOnResults.put(currentTopRecord.uniqueId(),onResult);
}
NewFlutterBoost.instance().platform().openContainer(context,url,urlParams,requestCode,exts);
FlutterBoost.instance().platform().openContainer(context,url,urlParams,requestCode,exts);
}
IContainerRecord closeContainer(String uniqueId, Map<String, Object> result,Map<String,Object> exts) {
......@@ -157,7 +155,7 @@ public class FlutterViewContainerManager implements IContainerManager {
Debuger.exception("closeContainer can not find uniqueId:" + uniqueId);
}
NewFlutterBoost.instance().platform().closeContainer(targetRecord,result,exts);
FlutterBoost.instance().platform().closeContainer(targetRecord,result,exts);
return targetRecord;
}
......
......@@ -2,6 +2,7 @@ package com.idlefish.flutterboost;
import android.app.Application;
import android.content.Context;
import android.util.Log;
import com.idlefish.flutterboost.interfaces.IContainerRecord;
import java.lang.reflect.Method;
......@@ -17,6 +18,7 @@ public abstract class Platform {
public abstract void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts);
public abstract int whenEngineStart();
public abstract int whenEngineDestroy();
public abstract FlutterView.RenderMode renderMode();
......@@ -25,7 +27,9 @@ public abstract class Platform {
public abstract String initialRoute();
public NewFlutterBoost.BoostLifecycleListener lifecycleListener;
public FlutterBoost.BoostLifecycleListener lifecycleListener;
public FlutterBoost.BoostPluginsRegister pluginsRegister;
public void closeContainer(IContainerRecord record, Map<String, Object> result, Map<String, Object> exts) {
if (record == null) return;
......@@ -34,7 +38,21 @@ public abstract class Platform {
}
public void registerPlugins(PluginRegistry mRegistry) {
try {
Class clz = Class.forName("io.flutter.plugins.GeneratedPluginRegistrant");
Method method = clz.getDeclaredMethod("registerWith", PluginRegistry.class);
method.invoke(null, mRegistry);
} catch (Throwable t) {
Log.i("flutterboost.platform",t.toString());
}
if(pluginsRegister!=null){
pluginsRegister.registerPlugins(mRegistry);
}
if (lifecycleListener!= null) {
lifecycleListener.onPluginsRegistered();
}
}
}
......@@ -19,8 +19,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.*;
import android.widget.*;
import com.idlefish.flutterboost.NewFlutterBoost;
import com.idlefish.flutterboost.Utils;
import com.idlefish.flutterboost.FlutterBoost;
import com.idlefish.flutterboost.XFlutterView;
import io.flutter.Log;
import io.flutter.embedding.android.DrawableSplashScreen;
......@@ -29,13 +28,12 @@ import io.flutter.embedding.android.SplashScreen;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.plugin.platform.PlatformPlugin;
import io.flutter.view.FlutterMain;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
public class NewBoostFlutterActivity extends Activity
public class BoostFlutterActivity extends Activity
implements FlutterActivityAndFragmentDelegate.Host,
LifecycleOwner {
......@@ -64,38 +62,34 @@ public class NewBoostFlutterActivity extends Activity
public static NewEngineIntentBuilder withNewEngine() {
return new NewEngineIntentBuilder(NewBoostFlutterActivity.class);
return new NewEngineIntentBuilder(BoostFlutterActivity.class);
}
public static class NewEngineIntentBuilder {
private final Class<? extends NewBoostFlutterActivity> activityClass;
private final Class<? extends BoostFlutterActivity> activityClass;
private String backgroundMode = DEFAULT_BACKGROUND_MODE;
private String url = "";
private Map params = new HashMap();
protected NewEngineIntentBuilder(@NonNull Class<? extends NewBoostFlutterActivity> activityClass) {
protected NewEngineIntentBuilder(@NonNull Class<? extends BoostFlutterActivity> activityClass) {
this.activityClass = activityClass;
}
public NewEngineIntentBuilder url (@NonNull String url) {
public NewEngineIntentBuilder url(@NonNull String url) {
this.url = url;
return this;
}
public NewEngineIntentBuilder params (@NonNull Map params) {
public NewEngineIntentBuilder params(@NonNull Map params) {
this.params = params;
return this;
}
public NewEngineIntentBuilder backgroundMode(@NonNull BackgroundMode backgroundMode) {
this.backgroundMode = backgroundMode.name();
return this;
......@@ -104,7 +98,7 @@ public class NewBoostFlutterActivity extends Activity
public Intent build(@NonNull Context context) {
SerializableMap serializableMap=new SerializableMap();
SerializableMap serializableMap = new SerializableMap();
serializableMap.setMap(params);
return new Intent(context, activityClass)
......@@ -117,7 +111,7 @@ public class NewBoostFlutterActivity extends Activity
public static class SerializableMap implements Serializable {
private Map<String,Object> map;
private Map<String, Object> map;
public Map<String, Object> getMap() {
return map;
......@@ -133,7 +127,7 @@ public class NewBoostFlutterActivity extends Activity
@NonNull
private LifecycleRegistry lifecycle;
public NewBoostFlutterActivity() {
public BoostFlutterActivity() {
lifecycle = new LifecycleRegistry(this);
}
......@@ -175,7 +169,7 @@ public class NewBoostFlutterActivity extends Activity
public SplashScreen provideSplashScreen() {
Drawable manifestSplashDrawable = getSplashScreenFromManifest();
if (manifestSplashDrawable != null) {
return new DrawableSplashScreen(manifestSplashDrawable, ImageView.ScaleType.CENTER,500L);
return new DrawableSplashScreen(manifestSplashDrawable, ImageView.ScaleType.CENTER, 500L);
} else {
return null;
}
......@@ -246,7 +240,7 @@ public class NewBoostFlutterActivity extends Activity
}
protected XFlutterView getFlutterView(){
protected XFlutterView getFlutterView() {
return delegate.getFlutterView();
}
......@@ -372,7 +366,6 @@ public class NewBoostFlutterActivity extends Activity
}
/**
* Returns true if Flutter is running in "debug mode", and false otherwise.
* <p>
......@@ -432,7 +425,7 @@ public class NewBoostFlutterActivity extends Activity
@Override
public FlutterEngine provideFlutterEngine(@NonNull Context context) {
// No-op. Hook for subclasses.
return NewFlutterBoost.instance().engineProvider();
return FlutterBoost.instance().engineProvider();
}
/**
......@@ -472,9 +465,6 @@ public class NewBoostFlutterActivity extends Activity
}
@Override
public String getContainerUrl() {
if (getIntent().hasExtra(EXTRA_URL)) {
......@@ -488,11 +478,11 @@ public class NewBoostFlutterActivity extends Activity
public Map getContainerUrlParams() {
if (getIntent().hasExtra(EXTRA_PARAMS)) {
SerializableMap serializableMap= (SerializableMap)getIntent().getSerializableExtra(EXTRA_PARAMS);
SerializableMap serializableMap = (SerializableMap) getIntent().getSerializableExtra(EXTRA_PARAMS);
return serializableMap.getMap();
}
Map<String,String> params = new HashMap<>();
Map<String, String> params = new HashMap<>();
return params;
}
......
......@@ -21,7 +21,7 @@ import java.util.Map;
import com.idlefish.flutterboost.BoostPluginRegistry;
import com.idlefish.flutterboost.NewFlutterBoost;
import com.idlefish.flutterboost.FlutterBoost;
import com.idlefish.flutterboost.Utils;
import com.idlefish.flutterboost.XFlutterView;
import com.idlefish.flutterboost.interfaces.IFlutterViewContainer;
......@@ -33,7 +33,6 @@ import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.platform.PlatformPlugin;
import io.flutter.view.FlutterMain;
import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW;
......@@ -59,8 +58,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
protected IOperateSyncer mSyncer;
FlutterActivityAndFragmentDelegate(@NonNull Host host) {
this.host = host;
}
......@@ -78,14 +75,14 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
return flutterEngine;
}
XFlutterView getFlutterView(){
XFlutterView getFlutterView() {
return flutterView;
}
void onAttach(@NonNull Context context) {
ensureAlive();
if (NewFlutterBoost.instance().platform().whenEngineStart() == NewFlutterBoost.ConfigBuilder.FLUTTER_ACTIVITY_CREATED) {
NewFlutterBoost.instance().doInitialFlutter();
if (FlutterBoost.instance().platform().whenEngineStart() == FlutterBoost.ConfigBuilder.FLUTTER_ACTIVITY_CREATED) {
FlutterBoost.instance().doInitialFlutter();
}
// When "retain instance" is true, the FlutterEngine will survive configuration
// changes. Therefore, we create a new one only if one does not already exist.
......@@ -108,8 +105,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
}
private void setupFlutterEngine() {
Log.d(TAG, "Setting up FlutterEngine.");
......@@ -139,10 +134,10 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
);
mSyncer = NewFlutterBoost.instance().containerManager().generateSyncer(this);
mSyncer = FlutterBoost.instance().containerManager().generateSyncer(this);
ensureAlive();
flutterView = new XFlutterView(host.getActivity(), NewFlutterBoost.instance().platform().renderMode(), host.getTransparencyMode());
flutterView = new XFlutterView(host.getActivity(), FlutterBoost.instance().platform().renderMode(), host.getTransparencyMode());
flutterSplashView = new FlutterSplashView(host.getContext());
......@@ -173,7 +168,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
}
void onResume() {
mSyncer.onAppear();
......@@ -181,9 +175,9 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
ensureAlive();
flutterEngine.getLifecycleChannel().appIsResumed();
BoostPluginRegistry registry= (BoostPluginRegistry)NewFlutterBoost.instance().getPluginRegistry();
ActivityPluginBinding binding=registry.getRegistrarAggregate().getActivityPluginBinding();
if(binding!=null&&(binding.getActivity()!=this.host.getActivity())){
BoostPluginRegistry registry = (BoostPluginRegistry) FlutterBoost.instance().getPluginRegistry();
ActivityPluginBinding binding = registry.getRegistrarAggregate().getActivityPluginBinding();
if (binding != null && (binding.getActivity() != this.host.getActivity())) {
flutterEngine.getActivityControlSurface().attachToActivity(
host.getActivity(),
host.getLifecycle()
......@@ -196,7 +190,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
void onPostResume() {
Log.v(TAG, "onPostResume()");
ensureAlive();
Utils.setStatusBarLightMode(host.getActivity(),true);
Utils.setStatusBarLightMode(host.getActivity(), true);
}
......@@ -222,13 +216,17 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
mSyncer.onDestroy();
ensureAlive();
BoostPluginRegistry registry= (BoostPluginRegistry)NewFlutterBoost.instance().getPluginRegistry();
ActivityPluginBinding binding=registry.getRegistrarAggregate().getActivityPluginBinding();
if(binding!=null&&(binding.getActivity()==this.host.getActivity())){
BoostPluginRegistry registry = (BoostPluginRegistry) FlutterBoost.instance().getPluginRegistry();
if (registry != null) {
ActivityPluginBinding binding = registry.getRegistrarAggregate().getActivityPluginBinding();
if (binding != null && (binding.getActivity() == this.host.getActivity())) {
registry.getRegistrarAggregate().onDetachedFromActivityForConfigChanges();
flutterEngine.getActivityControlSurface().detachFromActivityForConfigChanges();
}
}
flutterView.release();
}
......@@ -238,7 +236,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
ensureAlive();
// Null out the platformPlugin to avoid a possible retain cycle between the plugin, this Fragment,
// and this Fragment's Activity.
if (platformPlugin != null) {
......@@ -288,16 +285,16 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
void onActivityResult(int requestCode, int resultCode, Intent data) {
mSyncer.onActivityResult(requestCode,resultCode,data);
Map<String,Object> result = null;
if(data != null) {
mSyncer.onActivityResult(requestCode, resultCode, data);
Map<String, Object> result = null;
if (data != null) {
Serializable rlt = data.getSerializableExtra(RESULT_KEY);
if(rlt instanceof Map) {
result = (Map<String,Object>)rlt;
if (rlt instanceof Map) {
result = (Map<String, Object>) rlt;
}
}
mSyncer.onContainerResult(requestCode,resultCode,result);
mSyncer.onContainerResult(requestCode, resultCode, result);
ensureAlive();
......@@ -361,7 +358,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
@Override
public Activity getContextActivity() {
return (Activity)this.host.getActivity();
return (Activity) this.host.getActivity();
}
@Override
......@@ -372,10 +369,10 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
@Override
public void finishContainer(Map<String, Object> result) {
if(result != null) {
setBoostResult(this.host.getActivity(),new HashMap<>(result));
if (result != null) {
setBoostResult(this.host.getActivity(), new HashMap<>(result));
this.host.getActivity().finish();
}else{
} else {
this.host.getActivity().finish();
}
......@@ -383,7 +380,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
}
public void setBoostResult(Activity activity, HashMap result) {
Intent intent = new Intent();
if (result != null) {
......@@ -391,6 +387,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
}
activity.setResult(Activity.RESULT_OK, intent);
}
@Override
public String getContainerUrl() {
return this.host.getContainerUrl();
......@@ -413,7 +410,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
}
/**
* The {@link FlutterActivity} or {@link NewFlutterFragment} that owns this
* The {@link FlutterActivity} or {@link FlutterFragment} that owns this
* {@code FlutterActivityAndFragmentDelegate}.
*/
/* package */ interface Host extends SplashScreenProvider, FlutterEngineProvider, FlutterEngineConfigurator {
......@@ -487,12 +484,9 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
boolean shouldAttachEngineToActivity();
String getContainerUrl();
String getContainerUrl() ;
Map getContainerUrlParams() ;
Map getContainerUrlParams();
}
......
......@@ -14,20 +14,18 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.idlefish.flutterboost.NewFlutterBoost;
import com.idlefish.flutterboost.FlutterBoost;
import com.idlefish.flutterboost.XFlutterView;
import io.flutter.embedding.android.*;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener;
import io.flutter.plugin.platform.PlatformPlugin;
import io.flutter.view.FlutterMain;
import java.util.HashMap;
import java.util.Map;
public class NewFlutterFragment extends Fragment implements FlutterActivityAndFragmentDelegate.Host {
public class FlutterFragment extends Fragment implements FlutterActivityAndFragmentDelegate.Host {
private static final String TAG = "NewFlutterFragment";
......@@ -94,7 +92,7 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
* To use a cached {@link FlutterEngine} instead of creating a new one, use
*/
@NonNull
public static NewFlutterFragment createDefault() {
public static FlutterFragment createDefault() {
return new NewEngineFragmentBuilder().build();
}
......@@ -109,7 +107,7 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
public static class NewEngineFragmentBuilder {
private final Class<? extends NewFlutterFragment> fragmentClass;
private final Class<? extends FlutterFragment> fragmentClass;
private FlutterShellArgs shellArgs = null;
private FlutterView.RenderMode renderMode = FlutterView.RenderMode.surface;
......@@ -117,24 +115,24 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
private boolean shouldAttachEngineToActivity = true;
private String url = "";
private Map params = new HashMap();
/**
* Constructs a {@code NewEngineFragmentBuilder} that is configured to construct an instance of
* {@code NewFlutterFragment}.
*/
public NewEngineFragmentBuilder() {
fragmentClass = NewFlutterFragment.class;
fragmentClass = FlutterFragment.class;
}
/**
* Constructs a {@code NewEngineFragmentBuilder} that is configured to construct an instance of
* {@code subclass}, which extends {@code NewFlutterFragment}.
*/
public NewEngineFragmentBuilder(@NonNull Class<? extends NewFlutterFragment> subclass) {
public NewEngineFragmentBuilder(@NonNull Class<? extends FlutterFragment> subclass) {
fragmentClass = subclass;
}
/**
* Any special configuration arguments for the Flutter engine
*/
......@@ -157,16 +155,18 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
this.renderMode = renderMode;
return this;
}
public NewEngineFragmentBuilder url (@NonNull String url) {
public NewEngineFragmentBuilder url(@NonNull String url) {
this.url = url;
return this;
}
public NewEngineFragmentBuilder params (@NonNull Map params) {
public NewEngineFragmentBuilder params(@NonNull Map params) {
this.params = params;
return this;
}
/**
* Support a {@link FlutterView.TransparencyMode#transparent} background within {@link FlutterView},
* or force an {@link FlutterView.TransparencyMode#opaque} background.
......@@ -180,7 +180,6 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
}
@NonNull
protected Bundle createArgs() {
Bundle args = new Bundle();
......@@ -190,7 +189,7 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
args.putStringArray(ARG_FLUTTER_INITIALIZATION_ARGS, shellArgs.toArray());
}
NewBoostFlutterActivity.SerializableMap serializableMap=new NewBoostFlutterActivity.SerializableMap();
BoostFlutterActivity.SerializableMap serializableMap = new BoostFlutterActivity.SerializableMap();
serializableMap.setMap(params);
args.putString(EXTRA_URL, url);
......@@ -208,7 +207,7 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
* properties set on this {@code Builder}.
*/
@NonNull
public <T extends NewFlutterFragment> T build() {
public <T extends FlutterFragment> T build() {
try {
@SuppressWarnings("unchecked")
T frag = (T) fragmentClass.getDeclaredConstructor().newInstance();
......@@ -234,11 +233,11 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
private FlutterActivityAndFragmentDelegate delegate;
protected XFlutterView getFlutterView(){
protected XFlutterView getFlutterView() {
return delegate.getFlutterView();
}
public NewFlutterFragment() {
public FlutterFragment() {
// Ensure that we at least have an empty Bundle of arguments so that we don't
// need to continually check for null arguments before grabbing one.
setArguments(new Bundle());
......@@ -435,7 +434,7 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
@Nullable
public FlutterEngine provideFlutterEngine(@NonNull Context context) {
return NewFlutterBoost.instance().engineProvider();
return FlutterBoost.instance().engineProvider();
}
/**
......@@ -494,8 +493,6 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
}
@Override
public String getContainerUrl() {
......@@ -507,7 +504,7 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
@Override
public Map getContainerUrlParams() {
NewBoostFlutterActivity.SerializableMap serializableMap= (NewBoostFlutterActivity.SerializableMap) getArguments().getSerializable(EXTRA_PARAMS);
BoostFlutterActivity.SerializableMap serializableMap = (BoostFlutterActivity.SerializableMap) getArguments().getSerializable(EXTRA_PARAMS);
return serializableMap.getMap();
}
......
......@@ -49,8 +49,6 @@ public class FlutterSplashView extends FrameLayout {
@Override
public void onFlutterEngineAttachedToFlutterView(@NonNull FlutterEngine engine) {
flutterView.removeFlutterEngineAttachmentListener(this);
// displayFlutterViewWithSplash(flutterView, splashScreen);
// splashScreenTransitionNeededNow();
}
@Override
......@@ -60,15 +58,16 @@ public class FlutterSplashView extends FrameLayout {
@NonNull
private final OnFirstFrameRenderedListener onFirstFrameRenderedListener = new OnFirstFrameRenderedListener() {
int i=0;
int i = 0;
@Override
public void onFirstFrameRendered() {
if(NewFlutterBoost.instance().platform().whenEngineStart()== NewFlutterBoost.ConfigBuilder.FLUTTER_ACTIVITY_CREATED){
long now=new Date().getTime();
long flutterPostFrameCallTime=NewFlutterBoost.instance().getFlutterPostFrameCallTime();
if (FlutterBoost.instance().platform().whenEngineStart() == FlutterBoost.ConfigBuilder.FLUTTER_ACTIVITY_CREATED) {
long now = new Date().getTime();
long flutterPostFrameCallTime = FlutterBoost.instance().getFlutterPostFrameCallTime();
if(flutterPostFrameCallTime!=0&& (now-flutterPostFrameCallTime)>800){
if (flutterPostFrameCallTime != 0 && (now - flutterPostFrameCallTime) > 800) {
if (splashScreen != null) {
transitionToFlutter();
}
......@@ -83,17 +82,13 @@ public class FlutterSplashView extends FrameLayout {
}, 200);
}else{
} else {
if (splashScreen != null) {
transitionToFlutter();
}
}
}
};
......@@ -119,7 +114,7 @@ public class FlutterSplashView extends FrameLayout {
setSaveEnabled(true);
if (mFlutterEngine == null) {
mFlutterEngine = NewFlutterBoost.instance().engineProvider();
mFlutterEngine = FlutterBoost.instance().engineProvider();
}
}
......@@ -155,79 +150,9 @@ public class FlutterSplashView extends FrameLayout {
splashScreenView.setBackgroundColor(Color.WHITE);
addView(this.splashScreenView);
flutterView.addOnFirstFrameRenderedListener(onFirstFrameRenderedListener);
// if (splashScreen != null) {
// if (this.isSplashScreenNeededNow()) {
// Log.v(TAG, "Showing splash screen UI.");
// this.splashScreenView = splashScreen.createSplashView(this.getContext(), this.splashScreenState);
// this.addView(this.splashScreenView);
// flutterView.addOnFirstFrameRenderedListener(this.onFirstFrameRenderedListener);
// } else if (this.isSplashScreenTransitionNeededNow()) {
// Log.v(TAG, "Showing an immediate splash transition to Flutter due to previously interrupted transition.");
// this.splashScreenView = splashScreen.createSplashView(this.getContext(), this.splashScreenState);
// this.addView(this.splashScreenView);
// this.transitionToFlutter();
// } else if (!flutterView.isAttachedToFlutterEngine()) {
// Log.v(TAG, "FlutterView is not yet attached to a FlutterEngine. Showing nothing until a FlutterEngine is attached.");
// flutterView.addFlutterEngineAttachmentListener(this.flutterEngineAttachmentListener);
// }
// }
}
}
/**
* Returns true if current conditions require a splash UI to be displayed.
* <p>
* This method does not evaluate whether a previously interrupted splash transition needs
* to resume. See {@link #isSplashScreenTransitionNeededNow()} to answer that question.
*/
private boolean isSplashScreenNeededNow() {
return flutterView != null
&& flutterView.isAttachedToFlutterEngine()
&& !flutterView.hasRenderedFirstFrame()
&& !hasSplashCompleted();
}
/**
* Returns true if a previous splash transition was interrupted by recreation, e.g., an
* orientation change, and that previous transition should be resumed.
* <p>
* Not all splash screens are capable of remembering their transition progress. In those
* cases, this method will return false even if a previous visual transition was
* interrupted.
*/
private boolean isSplashScreenTransitionNeededNow() {
return flutterView != null
&& flutterView.isAttachedToFlutterEngine()
&& splashScreen != null
&& splashScreen.doesSplashViewRememberItsTransition()
&& wasPreviousSplashTransitionInterrupted();
}
/**
* Returns true if a splash screen was transitioning to a Flutter experience and was then
* interrupted, e.g., by an Android configuration change. Returns false otherwise.
* <p>
* Invoking this method expects that a {@code flutterView} exists and it is attached to a
* {@code FlutterEngine}.
*/
private boolean wasPreviousSplashTransitionInterrupted() {
if (flutterView == null) {
throw new IllegalStateException("Cannot determine if previous splash transition was " +
"interrupted when no FlutterView is set.");
}
if (!flutterView.isAttachedToFlutterEngine()) {
throw new IllegalStateException("Cannot determine if previous splash transition was "
+ "interrupted when no FlutterEngine is attached to our FlutterView. This question "
+ "depends on an isolate ID to differentiate Flutter experiences.");
}
return flutterView.hasRenderedFirstFrame() && !hasSplashCompleted();
}
/**
* Returns true if a splash UI for a specific Flutter experience has already completed.
......@@ -271,37 +196,6 @@ public class FlutterSplashView extends FrameLayout {
splashScreen.transitionToFlutter(onTransitionComplete);
}
public static class SavedState extends BaseSavedState {
public static Creator CREATOR = new Creator() {
public FlutterSplashView.SavedState createFromParcel(Parcel source) {
return new FlutterSplashView.SavedState(source);
}
public FlutterSplashView.SavedState[] newArray(int size) {
return new FlutterSplashView.SavedState[size];
}
};
private String previousCompletedSplashIsolate;
private Bundle splashScreenState;
SavedState(Parcelable superState) {
super(superState);
}
SavedState(Parcel source) {
super(source);
this.previousCompletedSplashIsolate = source.readString();
this.splashScreenState = source.readBundle(this.getClass().getClassLoader());
}
public void writeToParcel(Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeString(this.previousCompletedSplashIsolate);
out.writeBundle(this.splashScreenState);
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
......
......@@ -36,7 +36,7 @@
<activity
android:name="com.idlefish.flutterboost.containers.NewBoostFlutterActivity"
android:name="com.idlefish.flutterboost.containers.BoostFlutterActivity"
android:theme="@style/Theme.AppCompat"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
......
......@@ -13,7 +13,7 @@ import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import com.idlefish.flutterboost.containers.NewFlutterFragment;
import com.idlefish.flutterboost.containers.FlutterFragment;
import io.flutter.embedding.android.DrawableSplashScreen;
import io.flutter.embedding.android.SplashScreen;
import io.flutter.embedding.android.SplashScreenProvider;
......@@ -22,7 +22,7 @@ import io.flutter.plugin.platform.PlatformPlugin;
public class FlutterFragmentPageActivity extends AppCompatActivity implements View.OnClickListener, SplashScreenProvider {
protected static final String SPLASH_SCREEN_META_DATA_KEY = "io.flutter.embedding.android.SplashScreenDrawable";
private NewFlutterFragment mFragment;
private FlutterFragment mFragment;
private View mTab1;
private View mTab2;
......@@ -70,17 +70,17 @@ public class FlutterFragmentPageActivity extends AppCompatActivity implements Vi
if(mTab1 == v) {
mTab1.setBackgroundColor(Color.YELLOW);
mFragment= new NewFlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
mFragment= new FlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
}else if(mTab2 == v) {
mTab2.setBackgroundColor(Color.YELLOW);
mFragment= new NewFlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
mFragment= new FlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
}else if(mTab3 == v) {
mTab3.setBackgroundColor(Color.YELLOW);
mFragment= new NewFlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
mFragment= new FlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
}else{
mTab4.setBackgroundColor(Color.YELLOW);
mFragment= new NewFlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
mFragment= new FlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
}
getSupportFragmentManager()
......
......@@ -11,6 +11,8 @@ import java.util.Map;
import com.idlefish.flutterboost.interfaces.INativeRouter;
import io.flutter.embedding.android.FlutterView;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MyApplication extends Application {
......@@ -18,6 +20,7 @@ public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
INativeRouter router =new INativeRouter() {
@Override
public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) {
......@@ -27,34 +30,24 @@ public class MyApplication extends Application {
};
NewFlutterBoost.BoostLifecycleListener lifecycleListener= new NewFlutterBoost.BoostLifecycleListener() {
@Override
public void onEngineCreated() {
}
@Override
public void onPluginsRegistered() {
MethodChannel mMethodChannel = new MethodChannel( NewFlutterBoost.instance().engineProvider().getDartExecutor(), "methodChannel");
Log.e("MyApplication","MethodChannel create");
TextPlatformViewPlugin.register(NewFlutterBoost.instance().getPluginRegistry().registrarFor("TextPlatformViewPlugin"));
}
FlutterBoost.BoostPluginsRegister pluginsRegister= new FlutterBoost.BoostPluginsRegister(){
@Override
public void onEngineDestroy() {
public void registerPlugins(PluginRegistry mRegistry) {
GeneratedPluginRegistrant.registerWith(mRegistry);
TextPlatformViewPlugin.register(mRegistry.registrarFor("TextPlatformViewPlugin"));
}
};
Platform platform= new NewFlutterBoost
Platform platform= new FlutterBoost
.ConfigBuilder(this,router)
.isDebug(true)
.whenEngineStart(NewFlutterBoost.ConfigBuilder.ANY_ACTIVITY_CREATED)
.whenEngineStart(FlutterBoost.ConfigBuilder.ANY_ACTIVITY_CREATED)
.renderMode(FlutterView.RenderMode.texture)
.lifecycleListener(lifecycleListener)
.pluginsRegister(pluginsRegister)
.build();
NewFlutterBoost.instance().init(platform);
FlutterBoost.instance().init(platform);
......
package com.taobao.idlefish.flutterboostexample;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import com.idlefish.flutterboost.containers.NewBoostFlutterActivity;
import com.idlefish.flutterboost.containers.BoostFlutterActivity;
import java.util.HashMap;
import java.util.Map;
......@@ -13,11 +13,9 @@ public class PageRouter {
public final static Map<String, String> pageName = new HashMap<String, String>() {{
put("first", "first");
put("second", "second");
put("tab", "tab");
put("sample://flutterPage", "flutterPage");
}};
......@@ -37,23 +35,27 @@ public class PageRouter {
try {
if (pageName.containsKey(path)) {
Intent intent = NewBoostFlutterActivity.withNewEngine().url(pageName.get(path)).params(params)
.backgroundMode(NewBoostFlutterActivity.BackgroundMode.opaque).build(context);
Intent intent = BoostFlutterActivity.withNewEngine().url(pageName.get(path)).params(params)
.backgroundMode(BoostFlutterActivity.BackgroundMode.opaque).build(context);
if(context instanceof Activity){
Activity activity=(Activity)context;
activity.startActivityForResult(intent,requestCode);
}else{
context.startActivity(intent);
}
return true;
} else if (url.startsWith(FLUTTER_FRAGMENT_PAGE_URL)) {
context.startActivity(new Intent(context, FlutterFragmentPageActivity.class));
return true;
} else if (url.startsWith(NATIVE_PAGE_URL)) {
context.startActivity(new Intent(context, NativePageActivity.class));
return true;
} else {
return false;
}
return false;
} catch (Throwable t) {
return false;
}
return false;
}
}
......@@ -56,8 +56,11 @@
if(!_existedID[vc.uniqueIDString]){
[_idStk addObject:vc.uniqueIDString];
}
_existedID[vc.uniqueIDString] = vc.uniqueIDString;
_existedID[vc.uniqueIDString] = vc.name;
}
#if DEBUG
[self dump:@"ADD"];
#endif
}
- (void)remove:(id<FLBFlutterContainer>)vc
......@@ -66,6 +69,9 @@
[_existedID removeObjectForKey:vc.uniqueIDString];
[_idStk removeObject:vc.uniqueIDString];
}
#if DEBUG
[self dump:@"REMOVE"];
#endif
}
- (NSString *)peak
......@@ -73,4 +79,13 @@
return _idStk.lastObject;
}
#if DEBUG
- (void)dump:(NSString*)flag{
NSMutableString *log = [[NSMutableString alloc]initWithFormat:@"[DEBUG]--%@--PageStack uid/name", flag];
for(NSString *uid in _idStk){
[log appendFormat:@"-->%@/%@",uid, _existedID[uid]];
}
NSLog(@"%@\n", log);
}
#endif
@end
......@@ -111,26 +111,16 @@
return _instance;
}
- (id<FLBFlutterApplicationInterface>)application
{
return _application;
}
- (id<FLBAbstractFactory>)factory
{
return _factory;
}
- (void)startFlutterWithPlatform:(id<FLBPlatform>)platform
onStart:(void (^)(FlutterEngine *engine))callback;
{
static dispatch_once_t onceToken;
__weak __typeof__(self) weakSelf = self;
dispatch_once(&onceToken, ^{
self->_factory = FLBFactory.new;
self->_application = [self->_factory createApplication:platform];
[self->_application startFlutterWithPlatform:platform
__strong __typeof__(weakSelf) self = weakSelf;
self.factory = FLBFactory.new;
self.application = [self->_factory createApplication:platform];
[self.application startFlutterWithPlatform:platform
onStart:callback];
});
}
......
......@@ -26,14 +26,11 @@
#import "FLBFlutterApplicationInterface.h"
#import "FLBAbstractFactory.h"
#import "FlutterBoostPlugin.h"
@interface FlutterBoostPlugin(){
id<FLBFlutterApplicationInterface> _application;
id<FLBAbstractFactory> _factory;
}
@interface FlutterBoostPlugin()
@property (nonatomic,strong) id<FLBFlutterApplicationInterface> application;
@property (nonatomic,strong) id<FLBAbstractFactory> factory;
@property (nonatomic,strong) FlutterMethodChannel *methodChannel;
@property (nonatomic,copy) NSString *fPageId;
@property (nonatomic,copy) NSString *fPagename;
@property (nonatomic,strong) NSDictionary *fParams;
- (id<FLBFlutterApplicationInterface>)application;
- (id<FLBAbstractFactory>)factory;
@end
......@@ -30,7 +30,7 @@
- (id<FLBFlutterApplicationInterface>)createApplication:(id<FLBPlatform>)platform
{
return [FLBFlutterApplication sharedApplication];
return [FLBFlutterApplication new];
}
- (id<FLBFlutterContainer>)createFlutterContainer
......
......@@ -30,6 +30,5 @@
NS_ASSUME_NONNULL_BEGIN
@interface FLBFlutterApplication : NSObject<FLBFlutterApplicationInterface>
+ (FLBFlutterApplication *)sharedApplication;
@end
NS_ASSUME_NONNULL_END
......@@ -39,16 +39,6 @@
@implementation FLBFlutterApplication
@synthesize platform;
+ (FLBFlutterApplication *)sharedApplication
{
static FLBFlutterApplication *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [self new];
});
return instance;
}
- (BOOL)isRunning
{
return _isRunning;
......
......@@ -91,14 +91,14 @@
- (void)didEnterBackground
{
[BoostMessageChannel sendEvent:@"background"
arguments:nil];
[BoostMessageChannel sendEvent:@"lifecycle"
arguments:@{@"type":@"background"}];
}
- (void)willEnterForeground
{
[BoostMessageChannel sendEvent:@"foreground"
arguments:nil];
[BoostMessageChannel sendEvent:@"lifecycle"
arguments:@{@"type":@"foreground"}];
}
- (FlutterEngine *)engine
......
......@@ -29,6 +29,7 @@
NS_ASSUME_NONNULL_BEGIN
@interface FLBFlutterViewContainer : FlutterViewController<FLBFlutterContainer>
@property (nonatomic,copy,readwrite) NSString *name;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
- (void)surfaceUpdated:(BOOL)appeared;
- (void)setEnableForRunnersBatch:(BOOL)enable;
@end
......
......@@ -37,6 +37,8 @@
@interface FLBFlutterViewContainer ()
@property (nonatomic,strong,readwrite) NSDictionary *params;
@property (nonatomic,assign) long long identifier;
@property (nonatomic, copy) NSString *flbNibName;
@property (nonatomic, strong) NSBundle *flbNibBundle;
@end
#pragma clang diagnostic push
......@@ -47,13 +49,15 @@
{
[FLUTTER_APP.flutterProvider prepareEngineIfNeeded];
if(self = [super initWithEngine:FLUTTER_APP.flutterProvider.engine
nibName:nil
bundle:nil]){
nibName:_flbNibName
bundle:_flbNibBundle]){
[self _setup];
}
return self;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-designated-initializers"
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
if (self = [super initWithCoder: aDecoder]) {
NSAssert(NO, @"unsupported init method!");
......@@ -61,6 +65,13 @@
}
return self;
}
#pragma pop
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
_flbNibName = nibNameOrNil;
_flbNibBundle = nibBundleOrNil;
return [self init];
}
- (void)setName:(NSString *)name params:(NSDictionary *)params
{
......
......@@ -39,7 +39,7 @@ class BoostPageRoute<T> extends MaterialPageRoute<T> {
@override
Widget buildTransitions(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
return child;
return super.buildTransitions(context, animation, secondaryAnimation, child);
}
BoostPageRoute(
......
......@@ -206,6 +206,18 @@ class ContainerCoordinator {
?.pushContainer(_createContainerSettings(name, params, pageId));
}
//TODO, 需要验证android代码是否也可以移到这里
if (Platform.isIOS) {
try {
final SemanticsOwner owner =
WidgetsBinding.instance.pipelineOwner?.semanticsOwner;
final SemanticsNode root = owner?.rootSemanticsNode;
root?.detach();
root?.attach(owner);
} catch (e) {
assert(false, e.toString());
}
}
return true;
}
......@@ -254,9 +266,14 @@ class ContainerCoordinator {
}
bool _nativeContainerWillDealloc(String name, Map params, String pageId) {
try{
performContainerLifeCycle(_createContainerSettings(name, params, pageId),
ContainerLifeCycle.Destroy);
} catch (e){
Logger.log(
'nativeContainerWillDealloc error: ${e}' );
}
FlutterBoost.containerManager?.remove(pageId);
Logger.log(
......
name: flutter_boost
description: A next-generation Flutter-Native hybrid solution. FlutterBoost is a Flutter plugin which enables hybrid integration of Flutter for your existing native apps with minimum efforts.
version: 0.1.54
version: 0.1.61
author: Alibaba Xianyu
homepage: https://github.com/alibaba/flutter_boost
......
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