Commit 05a6dec5 authored by justin's avatar justin Committed by GitHub

Merge pull request #365 from Jaysonss/master

add platformview support to boost && add platform view example
parents 6afd80fb feab757a
......@@ -445,6 +445,9 @@ public class XFlutterView extends FrameLayout {
this.flutterEngine = flutterEngine;
// initialize PlatformViewsController
this.flutterEngine.getPluginRegistry().getPlatformViewsController().attach(getContext(),flutterEngine.getRenderer(),flutterEngine.getDartExecutor());
// Instruct our FlutterRenderer that we are now its designated RenderSurface.
this.flutterEngine.getRenderer().attachToRenderSurface(renderSurface);
......@@ -524,6 +527,10 @@ public class XFlutterView extends FrameLayout {
}
Log.d(TAG, "Detaching from Flutter Engine");
// detach platformviews in page in case memory leak
flutterEngine.getPluginRegistry().getPlatformViewsController().detach();
flutterEngine.getPluginRegistry().getPlatformViewsController().onFlutterViewDestroyed();
// Inform the Android framework that it should retrieve a new InputConnection
// now that the engine is detached. The new InputConnection will be null, which
// signifies that this View does not process input (until a new engine is attached).
......
......@@ -3,6 +3,7 @@ package com.taobao.idlefish.flutterboostexample;
import android.app.Application;
import android.content.Context;
import com.idlefish.flutterboost.BoostChannel;
import com.idlefish.flutterboost.BoostEngineProvider;
import com.idlefish.flutterboost.BoostFlutterEngine;
import com.idlefish.flutterboost.FlutterBoost;
......@@ -34,18 +35,18 @@ public class MyApplication extends FlutterApplication {
@Override
public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) {
PageRouter.openPageByUrl(context,url,urlParams,requestCode);
PageRouter.openPageByUrl(context, url, urlParams, requestCode);
}
@Override
public IFlutterEngineProvider engineProvider() {
return new BoostEngineProvider(){
return new BoostEngineProvider() {
@Override
public BoostFlutterEngine createEngine(Context context) {
return new BoostFlutterEngine(context, new DartExecutor.DartEntrypoint(
context.getResources().getAssets(),
FlutterMain.findAppBundlePath(context),
"main"),"/");
"main"), "/");
}
};
}
......@@ -55,5 +56,13 @@ public class MyApplication extends FlutterApplication {
return ANY_ACTIVITY_CREATED;
}
});
BoostChannel.addActionAfterRegistered(new BoostChannel.ActionAfterRegistered() {
@Override
public void onChannelRegistered(BoostChannel channel) {
//platform view register should use FlutterPluginRegistry instread of BoostPluginRegistry
TextPlatformViewPlugin.register(FlutterBoost.singleton().engineProvider().tryGetEngine().getPluginRegistry());
}
});
}
}
package com.taobao.idlefish.flutterboostexample;
import android.content.Context;
import android.view.View;
import android.widget.TextView;
import io.flutter.plugin.common.MessageCodec;
import io.flutter.plugin.platform.PlatformView;
import io.flutter.plugin.platform.PlatformViewFactory;
public class TextPlatformViewFactory extends PlatformViewFactory {
public TextPlatformViewFactory(MessageCodec<Object> createArgsCodec) {
super(createArgsCodec);
}
@Override
public PlatformView create(Context context, int i, Object o) {
return new TextPlatformView(context);
}
private static class TextPlatformView implements PlatformView {
private TextView platformTv;
public TextPlatformView(Context context) {
platformTv = new TextView(context);
platformTv.setText("PlatformView Demo");
}
@Override
public View getView() {
return platformTv;
}
@Override
public void dispose() {
}
}
}
package com.taobao.idlefish.flutterboostexample;
import io.flutter.app.FlutterPluginRegistry;
import io.flutter.plugin.common.StandardMessageCodec;
public class TextPlatformViewPlugin {
public static void register(FlutterPluginRegistry registry) {
registry.getPlatformViewsController().getRegistry().registerViewFactory("plugins.test/view",
new TextPlatformViewFactory(StandardMessageCodec.INSTANCE));
}
}
......@@ -12,13 +12,11 @@ class FirstRouteWidget extends StatelessWidget {
child: RaisedButton(
child: Text('Open second route'),
onPressed: () {
print("open second page!");
FlutterBoost.singleton.open("second").then((Map value){
FlutterBoost.singleton.open("second").then((Map value) {
print("did recieve second route result");
print("did recieve second route result $value");
});
},
),
),
......@@ -38,8 +36,10 @@ class SecondRouteWidget extends StatelessWidget {
onPressed: () {
// Navigate back to first route when tapped.
BoostContainerSettings settings = BoostContainer.of(context).settings;
FlutterBoost.singleton.close(settings.uniqueId,result: {"result":"data from second"});
BoostContainerSettings settings =
BoostContainer.of(context).settings;
FlutterBoost.singleton.close(settings.uniqueId,
result: {"result": "data from second"});
},
child: Text('Go back with result!'),
),
......@@ -103,7 +103,7 @@ class FlutterRouteWidget extends StatelessWidget {
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap: () =>
FlutterBoost.singleton.open("sample://nativePage", urlParams:{
FlutterBoost.singleton.open("sample://nativePage", urlParams: {
"query": {"aaa": "bbb"}
}),
),
......@@ -120,7 +120,7 @@ class FlutterRouteWidget extends StatelessWidget {
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap: () =>
FlutterBoost.singleton.open("sample://flutterPage", urlParams:{
FlutterBoost.singleton.open("sample://flutterPage", urlParams: {
"query": {"aaa": "bbb"}
}),
),
......@@ -141,15 +141,15 @@ class FlutterRouteWidget extends StatelessWidget {
InkWell(
child: Container(
padding: const EdgeInsets.all(8.0),
margin: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 80.0),
margin: const EdgeInsets.all(8.0),
color: Colors.yellow,
child: Text(
'open flutter fragment page',
style: TextStyle(fontSize: 22.0, color: Colors.black),
)),
onTap: () => FlutterBoost.singleton
.open("sample://flutterFragmentPage"),
)
onTap: () =>
FlutterBoost.singleton.open("sample://flutterFragmentPage"),
),
],
),
);
......@@ -196,8 +196,7 @@ class FragmentRouteWidget extends StatelessWidget {
'open native page',
style: TextStyle(fontSize: 22.0, color: Colors.black),
)),
onTap: () =>
FlutterBoost.singleton.open("sample://nativePage"),
onTap: () => FlutterBoost.singleton.open("sample://nativePage"),
),
InkWell(
child: Container(
......@@ -208,8 +207,7 @@ class FragmentRouteWidget extends StatelessWidget {
'open flutter page',
style: TextStyle(fontSize: 22.0, color: Colors.black),
)),
onTap: () =>
FlutterBoost.singleton.open("sample://flutterPage"),
onTap: () => FlutterBoost.singleton.open("sample://flutterPage"),
),
InkWell(
child: Container(
......@@ -220,8 +218,8 @@ class FragmentRouteWidget extends StatelessWidget {
'open flutter fragment page',
style: TextStyle(fontSize: 22.0, color: Colors.black),
)),
onTap: () => FlutterBoost.singleton
.open("sample://flutterFragmentPage"),
onTap: () =>
FlutterBoost.singleton.open("sample://flutterFragmentPage"),
)
],
),
......@@ -268,6 +266,6 @@ class _PushWidgetState extends State<PushWidget> {
@override
Widget build(BuildContext context) {
return FlutterRouteWidget(message:"Pushed Widget");
return FlutterRouteWidget(message: "Pushed Widget");
}
}
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