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 { ...@@ -445,6 +445,9 @@ public class XFlutterView extends FrameLayout {
this.flutterEngine = flutterEngine; 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. // Instruct our FlutterRenderer that we are now its designated RenderSurface.
this.flutterEngine.getRenderer().attachToRenderSurface(renderSurface); this.flutterEngine.getRenderer().attachToRenderSurface(renderSurface);
...@@ -524,6 +527,10 @@ public class XFlutterView extends FrameLayout { ...@@ -524,6 +527,10 @@ public class XFlutterView extends FrameLayout {
} }
Log.d(TAG, "Detaching from Flutter Engine"); 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 // Inform the Android framework that it should retrieve a new InputConnection
// now that the engine is detached. The new InputConnection will be null, which // 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). // signifies that this View does not process input (until a new engine is attached).
......
...@@ -3,6 +3,7 @@ package com.taobao.idlefish.flutterboostexample; ...@@ -3,6 +3,7 @@ package com.taobao.idlefish.flutterboostexample;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import com.idlefish.flutterboost.BoostChannel;
import com.idlefish.flutterboost.BoostEngineProvider; import com.idlefish.flutterboost.BoostEngineProvider;
import com.idlefish.flutterboost.BoostFlutterEngine; import com.idlefish.flutterboost.BoostFlutterEngine;
import com.idlefish.flutterboost.FlutterBoost; import com.idlefish.flutterboost.FlutterBoost;
...@@ -34,18 +35,18 @@ public class MyApplication extends FlutterApplication { ...@@ -34,18 +35,18 @@ public class MyApplication extends FlutterApplication {
@Override @Override
public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) { 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 @Override
public IFlutterEngineProvider engineProvider() { public IFlutterEngineProvider engineProvider() {
return new BoostEngineProvider(){ return new BoostEngineProvider() {
@Override @Override
public BoostFlutterEngine createEngine(Context context) { public BoostFlutterEngine createEngine(Context context) {
return new BoostFlutterEngine(context, new DartExecutor.DartEntrypoint( return new BoostFlutterEngine(context, new DartExecutor.DartEntrypoint(
context.getResources().getAssets(), context.getResources().getAssets(),
FlutterMain.findAppBundlePath(context), FlutterMain.findAppBundlePath(context),
"main"),"/"); "main"), "/");
} }
}; };
} }
...@@ -55,5 +56,13 @@ public class MyApplication extends FlutterApplication { ...@@ -55,5 +56,13 @@ public class MyApplication extends FlutterApplication {
return ANY_ACTIVITY_CREATED; 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 { ...@@ -12,13 +12,11 @@ class FirstRouteWidget extends StatelessWidget {
child: RaisedButton( child: RaisedButton(
child: Text('Open second route'), child: Text('Open second route'),
onPressed: () { onPressed: () {
print("open second page!"); 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");
print("did recieve second route result $value"); print("did recieve second route result $value");
}); });
}, },
), ),
), ),
...@@ -37,9 +35,11 @@ class SecondRouteWidget extends StatelessWidget { ...@@ -37,9 +35,11 @@ class SecondRouteWidget extends StatelessWidget {
child: RaisedButton( child: RaisedButton(
onPressed: () { onPressed: () {
// Navigate back to first route when tapped. // Navigate back to first route when tapped.
BoostContainerSettings settings = BoostContainer.of(context).settings; BoostContainerSettings settings =
FlutterBoost.singleton.close(settings.uniqueId,result: {"result":"data from second"}); BoostContainer.of(context).settings;
FlutterBoost.singleton.close(settings.uniqueId,
result: {"result": "data from second"});
}, },
child: Text('Go back with result!'), child: Text('Go back with result!'),
), ),
...@@ -103,7 +103,7 @@ class FlutterRouteWidget extends StatelessWidget { ...@@ -103,7 +103,7 @@ class FlutterRouteWidget extends StatelessWidget {
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。 ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb ///例如:sample://nativePage?aaa=bbb
onTap: () => onTap: () =>
FlutterBoost.singleton.open("sample://nativePage", urlParams:{ FlutterBoost.singleton.open("sample://nativePage", urlParams: {
"query": {"aaa": "bbb"} "query": {"aaa": "bbb"}
}), }),
), ),
...@@ -120,7 +120,7 @@ class FlutterRouteWidget extends StatelessWidget { ...@@ -120,7 +120,7 @@ class FlutterRouteWidget extends StatelessWidget {
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。 ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb ///例如:sample://nativePage?aaa=bbb
onTap: () => onTap: () =>
FlutterBoost.singleton.open("sample://flutterPage", urlParams:{ FlutterBoost.singleton.open("sample://flutterPage", urlParams: {
"query": {"aaa": "bbb"} "query": {"aaa": "bbb"}
}), }),
), ),
...@@ -141,15 +141,15 @@ class FlutterRouteWidget extends StatelessWidget { ...@@ -141,15 +141,15 @@ class FlutterRouteWidget extends StatelessWidget {
InkWell( InkWell(
child: Container( child: Container(
padding: const EdgeInsets.all(8.0), 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, color: Colors.yellow,
child: Text( child: Text(
'open flutter fragment page', 'open flutter fragment page',
style: TextStyle(fontSize: 22.0, color: Colors.black), style: TextStyle(fontSize: 22.0, color: Colors.black),
)), )),
onTap: () => FlutterBoost.singleton onTap: () =>
.open("sample://flutterFragmentPage"), FlutterBoost.singleton.open("sample://flutterFragmentPage"),
) ),
], ],
), ),
); );
...@@ -196,8 +196,7 @@ class FragmentRouteWidget extends StatelessWidget { ...@@ -196,8 +196,7 @@ class FragmentRouteWidget extends StatelessWidget {
'open native page', 'open native page',
style: TextStyle(fontSize: 22.0, color: Colors.black), style: TextStyle(fontSize: 22.0, color: Colors.black),
)), )),
onTap: () => onTap: () => FlutterBoost.singleton.open("sample://nativePage"),
FlutterBoost.singleton.open("sample://nativePage"),
), ),
InkWell( InkWell(
child: Container( child: Container(
...@@ -208,8 +207,7 @@ class FragmentRouteWidget extends StatelessWidget { ...@@ -208,8 +207,7 @@ class FragmentRouteWidget extends StatelessWidget {
'open flutter page', 'open flutter page',
style: TextStyle(fontSize: 22.0, color: Colors.black), style: TextStyle(fontSize: 22.0, color: Colors.black),
)), )),
onTap: () => onTap: () => FlutterBoost.singleton.open("sample://flutterPage"),
FlutterBoost.singleton.open("sample://flutterPage"),
), ),
InkWell( InkWell(
child: Container( child: Container(
...@@ -220,8 +218,8 @@ class FragmentRouteWidget extends StatelessWidget { ...@@ -220,8 +218,8 @@ class FragmentRouteWidget extends StatelessWidget {
'open flutter fragment page', 'open flutter fragment page',
style: TextStyle(fontSize: 22.0, color: Colors.black), style: TextStyle(fontSize: 22.0, color: Colors.black),
)), )),
onTap: () => FlutterBoost.singleton onTap: () =>
.open("sample://flutterFragmentPage"), FlutterBoost.singleton.open("sample://flutterFragmentPage"),
) )
], ],
), ),
...@@ -268,6 +266,6 @@ class _PushWidgetState extends State<PushWidget> { ...@@ -268,6 +266,6 @@ class _PushWidgetState extends State<PushWidget> {
@override @override
Widget build(BuildContext context) { 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