Commit d284055d authored by Yacumima's avatar Yacumima

merge

parents 0e7d161c 3a16ccfd
...@@ -63,7 +63,7 @@ public class BoostFlutterView extends FrameLayout { ...@@ -63,7 +63,7 @@ public class BoostFlutterView extends FrameLayout {
private final List<OnFirstFrameRenderedListener> mFirstFrameRenderedListeners = new LinkedList<>(); private final List<OnFirstFrameRenderedListener> mFirstFrameRenderedListeners = new LinkedList<>();
private boolean mNeedSnapshotWhenDetach = true; private boolean mNeedSnapshotWhenDetach = false;
private ImageView mSnapshot; private ImageView mSnapshot;
...@@ -74,6 +74,11 @@ public class BoostFlutterView extends FrameLayout { ...@@ -74,6 +74,11 @@ public class BoostFlutterView extends FrameLayout {
if(mRenderingProgressCover != null && mRenderingProgressCover.getParent() != null) { if(mRenderingProgressCover != null && mRenderingProgressCover.getParent() != null) {
((ViewGroup)mRenderingProgressCover.getParent()).removeView(mRenderingProgressCover); ((ViewGroup)mRenderingProgressCover.getParent()).removeView(mRenderingProgressCover);
} }
if(mNeedSnapshotWhenDetach && mSnapshot.getParent() != null) {
((ViewGroup)mSnapshot.getParent()).removeView(mSnapshot);
}
final Object[] listeners = mFirstFrameRenderedListeners.toArray(); final Object[] listeners = mFirstFrameRenderedListeners.toArray();
for (Object obj : listeners) { for (Object obj : listeners) {
((OnFirstFrameRenderedListener) obj).onFirstFrameRendered(BoostFlutterView.this); ((OnFirstFrameRenderedListener) obj).onFirstFrameRendered(BoostFlutterView.this);
...@@ -230,7 +235,15 @@ public class BoostFlutterView extends FrameLayout { ...@@ -230,7 +235,15 @@ public class BoostFlutterView extends FrameLayout {
Debuger.log("BoostFlutterView onDetach"); Debuger.log("BoostFlutterView onDetach");
if(mNeedSnapshotWhenDetach) { if(mNeedSnapshotWhenDetach) {
//mFlutterView.
if(mSnapshot.getParent() != null) {
((ViewGroup)mSnapshot.getParent()).removeView(mSnapshot);
}
Debuger.log("BoostFlutterView snapshot");
mSnapshot.setImageBitmap(mFlutterEngine.getRenderer().getBitmap());
BoostFlutterView.this.addView(mSnapshot);
} }
mFlutterView.removeOnFirstFrameRenderedListener(mOnFirstFrameRenderedListener); mFlutterView.removeOnFirstFrameRenderedListener(mOnFirstFrameRenderedListener);
......
...@@ -25,15 +25,14 @@ package com.taobao.idlefish.flutterboost; ...@@ -25,15 +25,14 @@ package com.taobao.idlefish.flutterboost;
import android.content.Intent; import android.content.Intent;
import com.taobao.idlefish.flutterboost.NavigationService.NavigationService; import com.taobao.idlefish.flutterboost.messageing.NavigationService;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import com.taobao.idlefish.flutterboost.interfaces.IContainerRecord; import com.taobao.idlefish.flutterboost.interfaces.IContainerRecord;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer; import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
public class ContainerRecord implements IContainerRecord { public class ContainerRecord implements IContainerRecord {
private final FlutterViewContainerManager mManager; private final FlutterViewContainerManager mManager;
private final IFlutterViewContainer mContainer; private final IFlutterViewContainer mContainer;
...@@ -143,7 +142,8 @@ public class ContainerRecord implements IContainerRecord { ...@@ -143,7 +142,8 @@ public class ContainerRecord implements IContainerRecord {
map.put("type", "backPressedCallback"); map.put("type", "backPressedCallback");
map.put("name", mContainer.getContainerName()); map.put("name", mContainer.getContainerName());
map.put("uniqueId", mUniqueId); map.put("uniqueId", mUniqueId);
NavigationService.getService().emitEvent(map);
FlutterBoostPlugin.getInstance().sendEvent("lifecycle",map);
mContainer.getBoostFlutterView().onBackPressed(); mContainer.getBoostFlutterView().onBackPressed();
} }
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.NavigationService;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import fleamarket.taobao.com.xservicekit.handler.MessageHandler;
import fleamarket.taobao.com.xservicekit.service.ServiceTemplate;
import fleamarket.taobao.com.xservicekit.service.ServiceGateway;
import io.flutter.plugin.common.MethodChannel;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
public class NavigationService {
private static final ServiceTemplate mService = new ServiceTemplate("NavigationService");
public static ServiceTemplate getService(){
return mService;
}
public static void register(){
ServiceGateway.sharedInstance().addService(mService);
}
public static void onNativePageResult(final MessageResult<Boolean> result ,String uniqueId,String key,Map resultData,Map params){
Map<String,Object> args = new HashMap<>();
args.put("uniqueId",uniqueId);
args.put("key",key);
args.put("resultData",resultData);
args.put("params",params);
mService.invoke("onNativePageResult", args, mService.methodChannelName(), new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean){
result.success((Boolean)o);
}else{
result.error("return type error code dart code","","");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null){
result.error(s,s1,o);
}
}
@Override
public void notImplemented() {
if (result != null){
result.notImplemented();
}
}
});
}
public static void didShowPageContainer(final MessageResult<Boolean> result ,String pageName,Map params,String uniqueId){
Map<String,Object> args = new HashMap<>();
args.put("pageName",pageName);
args.put("params",params);
args.put("uniqueId",uniqueId);
mService.invoke("didShowPageContainer", args, mService.methodChannelName(), new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean){
result.success((Boolean)o);
}else{
result.error("return type error code dart code","","");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null){
result.error(s,s1,o);
}
}
@Override
public void notImplemented() {
if (result != null){
result.notImplemented();
}
}
});
}
public static void willShowPageContainer(final MessageResult<Boolean> result ,String pageName,Map params,String uniqueId){
Map<String,Object> args = new HashMap<>();
args.put("pageName",pageName);
args.put("params",params);
args.put("uniqueId",uniqueId);
mService.invoke("willShowPageContainer", args, mService.methodChannelName(), new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean){
result.success((Boolean)o);
}else{
result.error("return type error code dart code","","");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null){
result.error(s,s1,o);
}
}
@Override
public void notImplemented() {
if (result != null){
result.notImplemented();
}
}
});
}
public static void willDisappearPageContainer(final MessageResult<Boolean> result ,String pageName,Map params,String uniqueId){
Map<String,Object> args = new HashMap<>();
args.put("pageName",pageName);
args.put("params",params);
args.put("uniqueId",uniqueId);
mService.invoke("willDisappearPageContainer", args, mService.methodChannelName(), new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean){
result.success((Boolean)o);
}else{
result.error("return type error code dart code","","");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null){
result.error(s,s1,o);
}
}
@Override
public void notImplemented() {
if (result != null){
result.notImplemented();
}
}
});
}
public static void didDisappearPageContainer(final MessageResult<Boolean> result ,String pageName,Map params,String uniqueId){
Map<String,Object> args = new HashMap<>();
args.put("pageName",pageName);
args.put("params",params);
args.put("uniqueId",uniqueId);
mService.invoke("didDisappearPageContainer", args, mService.methodChannelName(), new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean){
result.success((Boolean)o);
}else{
result.error("return type error code dart code","","");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null){
result.error(s,s1,o);
}
}
@Override
public void notImplemented() {
if (result != null){
result.notImplemented();
}
}
});
}
public static void didInitPageContainer(final MessageResult<Boolean> result ,String pageName,Map params,String uniqueId){
Map<String,Object> args = new HashMap<>();
args.put("pageName",pageName);
args.put("params",params);
args.put("uniqueId",uniqueId);
mService.invoke("didInitPageContainer", args, mService.methodChannelName(), new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean){
result.success((Boolean)o);
}else{
result.error("return type error code dart code","","");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null){
result.error(s,s1,o);
}
}
@Override
public void notImplemented() {
if (result != null){
result.notImplemented();
}
}
});
}
public static void willDeallocPageContainer(final MessageResult<Boolean> result ,String pageName,Map params,String uniqueId){
Map<String,Object> args = new HashMap<>();
args.put("pageName",pageName);
args.put("params",params);
args.put("uniqueId",uniqueId);
mService.invoke("willDeallocPageContainer", args, mService.methodChannelName(), new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean){
result.success((Boolean)o);
}else{
result.error("return type error code dart code","","");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null){
result.error(s,s1,o);
}
}
@Override
public void notImplemented() {
if (result != null){
result.notImplemented();
}
}
});
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.NavigationService;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import fleamarket.taobao.com.xservicekit.handler.MessageHandler;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
import fleamarket.taobao.com.xservicekit.service.ServiceGateway;
public class NavigationService_closePage implements MessageHandler<Boolean>{
private Object mContext = null;
private boolean onCall(MessageResult<Boolean> result,String uniqueId,String pageName,Map params,Boolean animated){
FlutterBoostPlugin.singleton().containerManager().closeContainer(uniqueId,null);
result.success(true);
return true;
}
//==================Do not edit code blow!==============
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) {
this.onCall(result,(String)args.get("uniqueId"),(String)args.get("pageName"),(Map)args.get("params"),(Boolean)args.get("animated"));
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("closePage");
return h;
}
@Override
public Object getContext() {
return mContext;
}
@Override
public void setContext(Object obj) {
mContext = obj;
}
@Override
public String service() {
return "NavigationService";
}
public static void register(){
ServiceGateway.sharedInstance().registerHandler(new NavigationService_closePage());
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.NavigationService;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import fleamarket.taobao.com.xservicekit.handler.MessageHandler;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
import fleamarket.taobao.com.xservicekit.service.ServiceGateway;
public class NavigationService_onFlutterPageResult implements MessageHandler<Boolean>{
private Object mContext = null;
private boolean onCall(MessageResult<Boolean> result,String uniqueId,String key,Map resultData,Map params){
// FlutterBoostPlugin.containerManager().setContainerResult(uniqueId,resultData);
// result.success(true);
return true;
}
//==================Do not edit code blow!==============
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) {
this.onCall(result,(String)args.get("uniqueId"),(String)args.get("key"),(Map)args.get("resultData"),(Map)args.get("params"));
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("onFlutterPageResult");
return h;
}
@Override
public Object getContext() {
return mContext;
}
@Override
public void setContext(Object obj) {
mContext = obj;
}
@Override
public String service() {
return "NavigationService";
}
public static void register(){
ServiceGateway.sharedInstance().registerHandler(new NavigationService_onFlutterPageResult());
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.NavigationService;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import fleamarket.taobao.com.xservicekit.handler.MessageHandler;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
import fleamarket.taobao.com.xservicekit.service.ServiceGateway;
public class NavigationService_onShownContainerChanged implements MessageHandler<Boolean>{
private Object mContext = null;
private boolean onCall(MessageResult<Boolean> result,String now,String old,Map params){
//Add your handler code here.
FlutterBoostPlugin.singleton().containerManager().onShownContainerChanged(old,now);
return true;
}
//==================Do not edit code blow!==============
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) {
this.onCall(result,(String)args.get("newName"),(String)args.get("oldName"),(Map)args.get("params"));
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("onShownContainerChanged");
return h;
}
@Override
public Object getContext() {
return mContext;
}
@Override
public void setContext(Object obj) {
mContext = obj;
}
@Override
public String service() {
return "NavigationService";
}
public static void register(){
ServiceGateway.sharedInstance().registerHandler(new NavigationService_onShownContainerChanged());
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.NavigationService;
import android.content.Context;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import fleamarket.taobao.com.xservicekit.handler.MessageHandler;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
import fleamarket.taobao.com.xservicekit.service.ServiceGateway;
public class NavigationService_openPage implements MessageHandler<Boolean>{
private Object mContext = null;
private boolean onCall(MessageResult<Boolean> result,String pageName,Map params,Boolean animated){
int requestCode = 0;
if(params != null && params.get("requestCode") != null) {
requestCode = (int) params.get("requestCode");
}
Context ctx = FlutterBoostPlugin.singleton().currentActivity();
if (ctx == null) {
ctx = FlutterBoostPlugin.singleton().platform().getApplication();
}
FlutterBoostPlugin.singleton().platform().startActivity(ctx, pageName ,params, requestCode);
if(result != null){
result.success(true);
}
return true;
}
//==================Do not edit code blow!==============
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) {
this.onCall(result,(String)args.get("pageName"),(Map)args.get("params"),(Boolean)args.get("animated"));
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("openPage");
return h;
}
@Override
public Object getContext() {
return mContext;
}
@Override
public void setContext(Object obj) {
mContext = obj;
}
@Override
public String service() {
return "NavigationService";
}
public static void register(){
ServiceGateway.sharedInstance().registerHandler(new NavigationService_openPage());
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.NavigationService;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.interfaces.IContainerRecord;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import fleamarket.taobao.com.xservicekit.handler.MessageHandler;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
import fleamarket.taobao.com.xservicekit.service.ServiceGateway;
public class NavigationService_pageOnStart implements MessageHandler<Map>{
private Object mContext = null;
private boolean onCall(MessageResult<Map> result,Map params){
Map<String,Object> pageInfo = new HashMap<>();
try {
IContainerRecord record = FlutterBoostPlugin.singleton()
.containerManager().getCurrentTopRecord();
if(record == null) {
record = FlutterBoostPlugin.singleton().containerManager().getLastGenerateRecord();
}
pageInfo.put("name",record.getContainer().getContainerName());
pageInfo.put("params",record.getContainer().getContainerParams());
pageInfo.put("uniqueId",record.uniqueId());
result.success(pageInfo);
}catch (Throwable t){
result.success(pageInfo);
}
return true;
}
//==================Do not edit code blow!==============
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Map> result) {
this.onCall(result,(Map)args.get("params"));
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("pageOnStart");
return h;
}
@Override
public Object getContext() {
return mContext;
}
@Override
public void setContext(Object obj) {
mContext = obj;
}
@Override
public String service() {
return "NavigationService";
}
public static void register(){
ServiceGateway.sharedInstance().registerHandler(new NavigationService_pageOnStart());
}
}
\ No newline at end of file
...@@ -69,7 +69,7 @@ abstract public class BoostFlutterFragment extends Fragment implements IFlutterV ...@@ -69,7 +69,7 @@ abstract public class BoostFlutterFragment extends Fragment implements IFlutterV
BoostFlutterView.Builder builder = new BoostFlutterView.Builder(getContextActivity()); BoostFlutterView.Builder builder = new BoostFlutterView.Builder(getContextActivity());
return builder.flutterEngine(engine) return builder.flutterEngine(engine)
.renderMode(FlutterView.RenderMode.texture) .renderMode(FlutterView.RenderMode.surface)
.transparencyMode(FlutterView.TransparencyMode.opaque) .transparencyMode(FlutterView.TransparencyMode.opaque)
.build(); .build();
} }
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import java.util.HashMap;
import java.util.Map;
import io.flutter.plugin.common.MethodChannel;
public class NavigationService {
public static MethodChannel methodChannel = null;
public static void onNativePageResult(final MessageResult<Boolean> result, String uniqueId, String key, Map resultData, Map params) {
Map<String, Object> args = new HashMap<>();
args.put("uniqueId", uniqueId);
args.put("key", key);
args.put("resultData", resultData);
args.put("params", params);
methodChannel.invokeMethod("onNativePageResult", args, new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean) {
result.success((Boolean) o);
} else {
result.error("return type error code dart code", "", "");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null) {
result.error(s, s1, o);
}
}
@Override
public void notImplemented() {
if (result != null) {
result.notImplemented();
}
}
});
}
public static void didShowPageContainer(final MessageResult<Boolean> result, String pageName, Map params, String uniqueId) {
Map<String, Object> args = new HashMap<>();
args.put("pageName", pageName);
args.put("params", params);
args.put("uniqueId", uniqueId);
methodChannel.invokeMethod("didShowPageContainer", args, new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean) {
result.success((Boolean) o);
} else {
result.error("return type error code dart code", "", "");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null) {
result.error(s, s1, o);
}
}
@Override
public void notImplemented() {
if (result != null) {
result.notImplemented();
}
}
});
}
public static void willShowPageContainer(final MessageResult<Boolean> result, String pageName, Map params, String uniqueId) {
Map<String, Object> args = new HashMap<>();
args.put("pageName", pageName);
args.put("params", params);
args.put("uniqueId", uniqueId);
methodChannel.invokeMethod("willShowPageContainer", args, new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean) {
result.success((Boolean) o);
} else {
result.error("return type error code dart code", "", "");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null) {
result.error(s, s1, o);
}
}
@Override
public void notImplemented() {
if (result != null) {
result.notImplemented();
}
}
});
}
public static void willDisappearPageContainer(final MessageResult<Boolean> result, String pageName, Map params, String uniqueId) {
Map<String, Object> args = new HashMap<>();
args.put("pageName", pageName);
args.put("params", params);
args.put("uniqueId", uniqueId);
methodChannel.invokeMethod("willDisappearPageContainer", args, new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean) {
result.success((Boolean) o);
} else {
result.error("return type error code dart code", "", "");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null) {
result.error(s, s1, o);
}
}
@Override
public void notImplemented() {
if (result != null) {
result.notImplemented();
}
}
});
}
public static void didDisappearPageContainer(final MessageResult<Boolean> result, String pageName, Map params, String uniqueId) {
Map<String, Object> args = new HashMap<>();
args.put("pageName", pageName);
args.put("params", params);
args.put("uniqueId", uniqueId);
methodChannel.invokeMethod("didDisappearPageContainer", args, new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean) {
result.success((Boolean) o);
} else {
result.error("return type error code dart code", "", "");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null) {
result.error(s, s1, o);
}
}
@Override
public void notImplemented() {
if (result != null) {
result.notImplemented();
}
}
});
}
public static void didInitPageContainer(final MessageResult<Boolean> result, String pageName, Map params, String uniqueId) {
Map<String, Object> args = new HashMap<>();
args.put("pageName", pageName);
args.put("params", params);
args.put("uniqueId", uniqueId);
methodChannel.invokeMethod("didInitPageContainer", args, new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean) {
result.success((Boolean) o);
} else {
result.error("return type error code dart code", "", "");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null) {
result.error(s, s1, o);
}
}
@Override
public void notImplemented() {
if (result != null) {
result.notImplemented();
}
}
});
}
public static void willDeallocPageContainer(final MessageResult<Boolean> result, String pageName, Map params, String uniqueId) {
Map<String, Object> args = new HashMap<>();
args.put("pageName", pageName);
args.put("params", params);
args.put("uniqueId", uniqueId);
methodChannel.invokeMethod("willDeallocPageContainer", args, new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean) {
result.success((Boolean) o);
} else {
result.error("return type error code dart code", "", "");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null) {
result.error(s, s1, o);
}
}
@Override
public void notImplemented() {
if (result != null) {
result.notImplemented();
}
}
});
}
}
\ No newline at end of file
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2019 Alibaba Group * Copyright (c) 2019 Alibaba Group
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
...@@ -21,78 +21,97 @@ ...@@ -21,78 +21,97 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
package com.taobao.idlefish.flutterboost.messageing.base;
#import "FLBResultMediator.h" import android.support.annotation.Nullable;
#import "Service_NavigationService.h"
@interface FLBResultMediator() import java.util.HashMap;
@property (nonatomic,strong) NSMutableDictionary *handlers; import java.util.LinkedList;
@end import java.util.List;
import java.util.Map;
@implementation FLBResultMediator import io.flutter.plugin.common.MethodChannel;
- (instancetype)init public class Broadcastor{
{
if (self = [super init]) { private MethodChannel channel = null;
_handlers = [NSMutableDictionary new]; private Map<String,List<EvenListener>> lists = new HashMap<>();
public Broadcastor(MethodChannel channel) {
this.channel = channel;
} }
return self;
}
- (void)onResultForKey:(NSString *)rid public void sendEvent(String name , Map arguments) {
resultData:(NSDictionary *)resultData
params:(nonnull NSDictionary *)params if (name == null) {
{ return;
if(!rid) return; }
NSString *key = rid; Map msg = new HashMap();
if(_handlers[key]){ msg.put("name",name);
FLBPageResultHandler handler = _handlers[key]; if(arguments != null){
handler(key,resultData); msg.put("arguments",arguments);
[_handlers removeObjectForKey: key]; }
}else{
//Cannot find handler here. Try to forward message to flutter. channel.invokeMethod("__event__", msg, new MethodChannel.Result() {
//Use forward to avoid circle. @Override
if(!params || !params[@"forward"]){ public void success(@Nullable Object o) {
NSMutableDictionary *tmp = params.mutableCopy;
if(!tmp){
tmp = NSMutableDictionary.new;
} }
tmp[@"forward"] = @(1); @Override
params = tmp; public void error(String s, @Nullable String s1, @Nullable Object o) {
[Service_NavigationService onNativePageResult:^(NSNumber *r) {}
uniqueId:rid
key:rid
resultData:resultData
params:params];
}else{
NSMutableDictionary *tmp = params.mutableCopy;
tmp[@"forward"] = @([params[@"forward"] intValue] + 1);
params = tmp;
if([params[@"forward"] intValue] <= 2){
[Service_NavigationService onNativePageResult:^(NSNumber *r) {}
uniqueId:rid
key:rid
resultData:resultData
params:params];
} }
@Override
public void notImplemented() {
}
});
}
public void dispatch(String name, Map arguments) {
if(name == null || arguments == null){
return ;
}
String eventName = (String)arguments.get("name");
Map eventArguments = (Map)arguments.get("arguments");
List<EvenListener> list = lists.get(eventName);
if(list == null){
return ;
} }
for(EvenListener l : list){
l.onEvent(eventName,eventArguments);
}
return;
} }
}
- (void)setResultHandler:(FLBPageResultHandler)handler public void addEventListener(String name , EvenListener listener){
forKey:(NSString *)vcid if(listener == null || name == null){
{ return ;
if(!handler || !vcid) return; }
_handlers[vcid] = handler;
}
- (void)removeHandlerForKey:(NSString *)vcid List<EvenListener> list = lists.get(name);
{ if (list == null){
if(!vcid) return; list = new LinkedList<>();
[_handlers removeObjectForKey:vcid]; lists.put(name,list);
} }
list.add(listener);
}
public void removeEventListener(String name ,EvenListener listener){
if(listener == null || name == null){
return ;
}
List<EvenListener> list = lists.get(name);
if(list != null){
list.remove(listener);
}
}
@end
}
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2019 Alibaba Group * Copyright (c) 2019 Alibaba Group
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
...@@ -21,13 +21,10 @@ ...@@ -21,13 +21,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
package com.taobao.idlefish.flutterboost.messageing.base;
import '../NavigationService/service/NavigationServiceRegister.dart'; import java.util.Map;
class ServiceLoader{ public interface EvenListener {
void onEvent(String eventName , Map arguments);
static load(){ }
NavigationServiceRegister.register();
}
}
\ No newline at end of file
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2019 Alibaba Group * Copyright (c) 2019 Alibaba Group
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
...@@ -22,11 +22,11 @@ ...@@ -22,11 +22,11 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
package com.taobao.idlefish.flutterboost.loader; package com.taobao.idlefish.flutterboost.messageing.base;
import java.util.Map;
public class ServiceLoader {
public static void load(){ public interface Message {
com.taobao.idlefish.flutterboost.NavigationService.NavigationServiceRegister.register(); String name();
} Map arguments();
} }
\ No newline at end of file
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2019 Alibaba Group * Copyright (c) 2019 Alibaba Group
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
...@@ -21,18 +21,10 @@ ...@@ -21,18 +21,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
package com.taobao.idlefish.flutterboost.messageing.base;
package com.taobao.idlefish.flutterboost.NavigationService; public interface MessageDispatcher<T>{
boolean dispatch(Message msg,MessageResult<T> result);
void addHandler(MessageHandler<T> handler);
public class NavigationServiceRegister { void removeHandler(MessageHandler<T> handler);
public static void register(){ }
NavigationService.register();
NavigationService_onShownContainerChanged.register();
NavigationService_onFlutterPageResult.register();
NavigationService_pageOnStart.register();
NavigationService_openPage.register();
NavigationService_closePage.register();
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.base;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MessageDispatcherImp implements MessageDispatcher {
private Map<String,MessageHandler> handlers = new HashMap<>();
@Override
public boolean dispatch(Message msg, MessageResult result) {
if(msg == null){
return false;
}
MessageHandler h = handlers.get(msg.name());
if(h != null){
return h.onMethodCall(msg.name(),msg.arguments(),result);
}
return false;
}
@Override
public void addHandler(MessageHandler handler) {
if(handler == null){
return;
}
List<String> names = handler.handleMessageNames();
for(String name : names){
handlers.put(name,handler);
}
}
@Override
public void removeHandler(MessageHandler handler) {
if(handler == null){
return;
}
List<String> names = handler.handleMessageNames();
for(String name : names){
if(handler == handlers.get(name)){
handlers.remove(name);
}
}
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.base;
import java.util.List;
import java.util.Map;
public interface MessageHandler<T> {
boolean onMethodCall(String name, Map args, MessageResult<T> result);
List<String> handleMessageNames();
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.base;
import java.util.Map;
public class MessageImp implements Message{
private String name;
private Map args;
public MessageImp(String name,Map args){
this.name = name;
this.args = args;
}
@Override
public String name() {
return name;
}
@Override
public Map arguments() {
return args;
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.base;
public interface MessageResult<T> {
void success(T var1);
void error(String var1, String var2, Object var3);
void notImplemented();
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.handlers;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.FlutterViewContainerManager;
import com.taobao.idlefish.flutterboost.messageing.base.MessageHandler;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ClosePageHandler implements MessageHandler<Boolean> {
//==================Do not edit code blow!==============
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) {
//TODO:接入新的close消息
String uniqueId = (String)args.get("uniqueId");
Map resultData = (Map)args.get("result");
Map exts = (Map)args.get("exts");
FlutterBoostPlugin.containerManager().closeContainer(uniqueId, null);
result.success(true);
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("closePage");
return h;
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.handlers;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.messageing.base.MessageHandler;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import com.taobao.idlefish.flutterboost.interfaces.IContainerManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class OnFlutterPageResultHandler implements MessageHandler<Boolean> {
private boolean onCall(MessageResult<Boolean> result, String uniqueId, String key, Map resultData, Map params) {
result.success(true);
return true;
}
//==================Do not edit code blow!==============
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) {
this.onCall(result, (String) args.get("uniqueId"), (String) args.get("key"), (Map) args.get("resultData"), (Map) args.get("params"));
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("onFlutterPageResult");
return h;
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.handlers;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.messageing.base.MessageHandler;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class OnShownContainerChangedHandler implements MessageHandler<Boolean> {
private boolean onCall(MessageResult<Boolean> result, String now, String old, Map params) {
//Add your handler code here.
FlutterBoostPlugin.containerManager().onShownContainerChanged(old, now);
return true;
}
//==================Do not edit code blow!==============
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) {
this.onCall(result, (String) args.get("newName"), (String) args.get("oldName"), (Map) args.get("params"));
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("onShownContainerChanged");
return h;
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.handlers;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.messageing.base.MessageHandler;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class OpenPageHandler implements MessageHandler<Map> {
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Map> result) {
//TODO:接入新的open方法,同时兼容老方法
Map params = (Map)args.get("urlParams");
Map exts = (Map)args.get("exts");
String url = (String)args.get("url");
int requestCode = 0;
if (params != null && params.get("requestCode") != null) {
requestCode = (int) params.get("requestCode");
}
FlutterBoostPlugin.openPage(null, url, params, 0);
//TODO: to call future.
if (result != null) {
result.success(new HashMap());
}
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("openPage");
return h;
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.handlers;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.FlutterViewContainerManager;
import com.taobao.idlefish.flutterboost.interfaces.IContainerRecord;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer;
import com.taobao.idlefish.flutterboost.messageing.base.MessageHandler;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PageOnStartHandler implements MessageHandler<Map> {
private boolean onCall(MessageResult<Map> result, Map params) {
Map<String, Object> pageInfo = new HashMap<>();
try {
IContainerRecord record = FlutterBoostPlugin
.containerManager().getCurrentTopRecord();
if (record == null) {
record = FlutterBoostPlugin.containerManager().getLastGenerateRecord();
}
pageInfo.put("name", record.getContainer().getContainerName());
pageInfo.put("params", record.getContainer().getContainerParams());
pageInfo.put("uniqueId", record.uniqueId());
result.success(pageInfo);
} catch (Throwable t) {
result.success(pageInfo);
}
return true;
}
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Map> result) {
this.onCall(result, (Map) args.get("params"));
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("pageOnStart");
return h;
}
}
\ No newline at end of file
...@@ -2,7 +2,6 @@ PODS: ...@@ -2,7 +2,6 @@ PODS:
- Flutter (1.0.0) - Flutter (1.0.0)
- flutter_boost (0.0.1): - flutter_boost (0.0.1):
- Flutter - Flutter
- xservice_kit
- xservice_kit (0.0.1): - xservice_kit (0.0.1):
- Flutter - Flutter
...@@ -21,7 +20,7 @@ EXTERNAL SOURCES: ...@@ -21,7 +20,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296 Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296
flutter_boost: 6a083f2f1b67f9b08724d6c4b280a099d1b40797 flutter_boost: e6949ea7bf22ad0766867b631996c2a7afa1a710
xservice_kit: a86c64372b3e41e7d8e9b1a0b9139866680f525c xservice_kit: a86c64372b3e41e7d8e9b1a0b9139866680f525c
PODFILE CHECKSUM: 2a757a7bdc03b37a2814666652fdff1cf694243f PODFILE CHECKSUM: 2a757a7bdc03b37a2814666652fdff1cf694243f
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
...@@ -45,7 +44,6 @@ ...@@ -45,7 +44,6 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
...@@ -105,7 +103,6 @@ ...@@ -105,7 +103,6 @@
9740EEB11CF90186004384FC /* Flutter */ = { 9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
3B80C3931E831B6300D905FE /* App.framework */, 3B80C3931E831B6300D905FE /* App.framework */,
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
9740EEBA1CF902C7004384FC /* Flutter.framework */, 9740EEBA1CF902C7004384FC /* Flutter.framework */,
...@@ -232,7 +229,6 @@ ...@@ -232,7 +229,6 @@
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
......
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <flutter_boost/FLBPlatform.h> #import <flutter_boost/FlutterBoost.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DemoRouter : NSObject<FLBPlatform> @interface DemoRouter : NSObject<FLB2Platform>
@property (nonatomic,strong) UINavigationController *navigationController; @property (nonatomic,strong) UINavigationController *navigationController;
......
...@@ -21,11 +21,64 @@ ...@@ -21,11 +21,64 @@
return instance; return instance;
} }
// Boost 2 switch
- (BOOL)userBoost2
{
return YES;
}
#pragma mark - Boost 2
- (void)open:(NSString *)name
urlParams:(NSDictionary *)params
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion
{
BOOL animated = [exts[@"animated"] boolValue];
animated = YES;
if([params[@"present"] boolValue]){
FLB2FlutterViewContainer *vc = FLB2FlutterViewContainer.new;
[vc setName:name params:params];
[self.navigationController presentViewController:vc animated:animated completion:^{
if(completion) completion(YES);
}];
}else{
FLB2FlutterViewContainer *vc = FLB2FlutterViewContainer.new;
[vc setName:name params:params];
[self.navigationController pushViewController:vc animated:animated];
if(completion) completion(YES);
}
}
- (void)close:(NSString *)uid
result:(NSDictionary *)result
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion
{
BOOL animated = [exts[@"animated"] boolValue];
animated = YES;
FLBFlutterViewContainer *vc = (id)self.navigationController.presentedViewController;
if([vc isKindOfClass:FLBFlutterViewContainer.class] && [vc.uniqueIDString isEqual: uid]){
[vc dismissViewControllerAnimated:animated completion:^{}];
}else{
[self.navigationController popViewControllerAnimated:animated];
}
}
#pragma mark - Boost 1
- (void)openPage:(NSString *)name - (void)openPage:(NSString *)name
params:(NSDictionary *)params params:(NSDictionary *)params
animated:(BOOL)animated animated:(BOOL)animated
completion:(void (^)(BOOL))completion completion:(void (^)(BOOL))completion
{ {
if([self userBoost2]){
NSMutableDictionary *exts = NSMutableDictionary.new;
exts[@"url"] = name;
exts[@"params"] = params;
exts[@"animated"] = @(animated);
[self open:name urlParams:params exts:exts completion:completion];
return;
}
if([params[@"present"] boolValue]){ if([params[@"present"] boolValue]){
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new; FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
[vc setName:name params:params]; [vc setName:name params:params];
...@@ -40,14 +93,19 @@ ...@@ -40,14 +93,19 @@
} }
} }
- (BOOL)accessibilityEnable
{
return YES;
}
- (void)closePage:(NSString *)uid animated:(BOOL)animated params:(NSDictionary *)params completion:(void (^)(BOOL))completion - (void)closePage:(NSString *)uid animated:(BOOL)animated params:(NSDictionary *)params completion:(void (^)(BOOL))completion
{ {
if([self userBoost2]){
NSMutableDictionary *exts = NSMutableDictionary.new;
exts[@"params"] = params;
exts[@"animated"] = @(animated);
[self close:uid result:@{} exts:exts completion:completion];
return;
}
FLBFlutterViewContainer *vc = (id)self.navigationController.presentedViewController; FLBFlutterViewContainer *vc = (id)self.navigationController.presentedViewController;
if([vc isKindOfClass:FLBFlutterViewContainer.class] && [vc.uniqueIDString isEqual: uid]){ if([vc isKindOfClass:FLBFlutterViewContainer.class] && [vc.uniqueIDString isEqual: uid]){
[vc dismissViewControllerAnimated:animated completion:^{}]; [vc dismissViewControllerAnimated:animated completion:^{}];
......
...@@ -26,9 +26,7 @@ ...@@ -26,9 +26,7 @@
- (IBAction)pushFlutterPage:(id)sender { - (IBAction)pushFlutterPage:(id)sender {
[DemoRouter.sharedRouter openPage:@"first" params:@{} animated:YES completion:^(BOOL f){ [DemoRouter.sharedRouter openPage:@"first" params:@{} animated:YES completion:^(BOOL f){
[FlutterBoostPlugin.sharedInstance onResultForKey:@"result_id_100" resultData:@{} params:@{}];
}]; }];
} }
......
...@@ -13,8 +13,10 @@ class FirstRouteWidget extends StatelessWidget { ...@@ -13,8 +13,10 @@ class FirstRouteWidget extends StatelessWidget {
child: Text('Open second route'), child: Text('Open second route'),
onPressed: () { onPressed: () {
FlutterBoost.singleton.openPage("second", {}, animated: true, resultHandler:(String key , Map<dynamic,dynamic> result){ print("open second page!");
print("did recieve second route result $key $result"); FlutterBoost.singleton.open("second").then((Map value){
print("did recieve second route result");
print("did recieve second route result $value");
}); });
}, },
...@@ -39,12 +41,11 @@ class SecondRouteWidget extends StatelessWidget { ...@@ -39,12 +41,11 @@ class SecondRouteWidget extends StatelessWidget {
BoostContainerSettings settings = BoostContainer.of(context).settings; BoostContainerSettings settings = BoostContainer.of(context).settings;
if(settings.params.containsKey("result_id")){ if(settings.params.containsKey("result_id")){
String rid = settings.params["result_id"]; String rid = settings.params["result_id"];
FlutterBoost.singleton.onPageResult(rid, {"data":"works"},{});
} }
FlutterBoost.singleton.closePageForContext(context); FlutterBoost.singleton.close(settings.uniqueId,result: {"result":"data from second"});
}, },
child: Text('Go back!'), child: Text('Go back with result!'),
), ),
), ),
); );
......
...@@ -128,7 +128,44 @@ ...@@ -128,7 +128,44 @@
- (id<FLB2FlutterProvider>)flutterProvider - (id<FLB2FlutterProvider>)flutterProvider
{ {
return _viewProvider; return (id)_viewProvider;
}
- (void)close:(NSString *)uid
result:(NSDictionary *)result
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion
{
[self.platform closePage:uid
animated:[exts[@"animated"] boolValue]
params:exts[@"params"]
completion:completion];
}
- (void)open:(NSString *)url
urlParams:(NSDictionary *)urlParams
exts:(NSDictionary *)exts
reult:(void (^)(NSDictionary *))resultCallback
completion:(void (^)(BOOL))completion
{
[self.platform openPage:url
params:urlParams
animated:[exts[@"animated"] boolValue]
completion:completion];
}
- (void)didInitPageContainer:(NSString *)url
params:(NSDictionary *)urlParams
uniqueId:(NSString *)uniqueId
{
}
- (void)willDeallocPageContainer:(NSString *)url
params:(NSDictionary *)params
uniqueId:(NSString *)uniqueId
{
} }
@end @end
...@@ -391,15 +391,5 @@ static NSUInteger kInstanceCounter = 0; ...@@ -391,15 +391,5 @@ static NSUInteger kInstanceCounter = 0;
self.interactiveGestureActive = NO; self.interactiveGestureActive = NO;
} }
#pragma mark - FLBViewControllerResultHandler
- (void)onRecievedResult:(NSDictionary *)resultData forKey:(NSString *)key
{
[Service_NavigationService onNativePageResult:^(NSNumber *finished) {}
uniqueId:self.uniqueIDString
key:key
resultData:resultData
params:@{}];
}
@end @end
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
@property (nonatomic,strong) id<FLB2FlutterProvider> viewProvider; @property (nonatomic,strong) id<FLB2FlutterProvider> viewProvider;
@property (nonatomic,assign) BOOL isRunning; @property (nonatomic,assign) BOOL isRunning;
@property (nonatomic,strong) NSMutableDictionary *pageResultCallbacks;
@property (nonatomic,strong) NSMutableDictionary *callbackCache;
@end @end
...@@ -73,6 +77,8 @@ ...@@ -73,6 +77,8 @@
{ {
if (self = [super init]) { if (self = [super init]) {
_manager = [FLBFlutterContainerManager new]; _manager = [FLBFlutterContainerManager new];
_pageResultCallbacks = NSMutableDictionary.new;
_callbackCache = NSMutableDictionary.new;
} }
return self; return self;
} }
...@@ -129,4 +135,66 @@ ...@@ -129,4 +135,66 @@
return self.flutterProvider.engine.viewController; return self.flutterProvider.engine.viewController;
} }
- (void)close:(NSString *)uniqueId
result:(NSDictionary *)result
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion
{
[self.platform close:uniqueId
result:result
exts:exts
completion:completion];
if(_pageResultCallbacks[uniqueId]){
void (^cb)(NSDictionary *) = _pageResultCallbacks[uniqueId];
cb(result);
[_pageResultCallbacks removeObjectForKey:uniqueId];
}
}
- (void)open:(NSString *)url
urlParams:(NSDictionary *)urlParams
exts:(NSDictionary *)exts
reult:(void (^)(NSDictionary *))resultCallback
completion:(void (^)(BOOL))completion
{
NSString *cid = urlParams[@"__calback_id__"];
if(!cid){
static int64_t sCallbackID = 1;
cid = @(sCallbackID).stringValue;
sCallbackID += 2;
}
_callbackCache[cid] = resultCallback;
[self.platform open:url
urlParams:urlParams
exts:exts
completion:completion];
}
- (void)didInitPageContainer:(NSString *)url
params:(NSDictionary *)urlParams
uniqueId:(NSString *)uniqueId
{
NSString *cid = urlParams[@"__calback_id__"];
if(cid && _callbackCache[cid]){
_pageResultCallbacks[uniqueId] = _callbackCache[cid];
[_callbackCache removeObjectForKey:cid];
}
}
- (void)willDeallocPageContainer:(NSString *)url
params:(NSDictionary *)params
uniqueId:(NSString *)uniqueId
{
if(_pageResultCallbacks[uniqueId]){
void (^cb)(NSDictionary *) = _pageResultCallbacks[uniqueId];
cb(@{});
[_pageResultCallbacks removeObjectForKey:uniqueId];
}
}
@end @end
...@@ -33,15 +33,15 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -33,15 +33,15 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)userBoost2; - (BOOL)userBoost2;
@required @required
- (void)openPage:(NSString *)name - (void)open:(NSString *)url
params:(NSDictionary *)params urlParams:(NSDictionary *)urlParams
animated:(BOOL)animated exts:(NSDictionary *)exts
completion:(void (^)(BOOL finished))completion; completion:(void (^)(BOOL finished))completion;
- (void)closePage:(NSString *)uid - (void)close:(NSString *)uid
animated:(BOOL)animated result:(NSDictionary *)result
params:(NSDictionary *)params exts:(NSDictionary *)exts
completion:(void (^)(BOOL finished))completion; completion:(void (^)(BOOL finished))completion;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -55,6 +55,29 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -55,6 +55,29 @@ NS_ASSUME_NONNULL_BEGIN
- (void)resume; - (void)resume;
- (void)inactive; - (void)inactive;
- (BOOL)isRunning; - (BOOL)isRunning;
#pragma mark - handle messages
- (void)close:(NSString *)uid
result:(NSDictionary *)result
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion;
- (void)open:(NSString *)url
urlParams:(NSDictionary *)urlParams
exts:(NSDictionary *)exts
reult:(void (^)(NSDictionary *))resultCallback
completion:(void (^)(BOOL))completion;
- (void)didInitPageContainer:(NSString *)url
params:(NSDictionary *)urlParams
uniqueId:(NSString *)uniqueId;
- (void)willDeallocPageContainer:(NSString *)url
params:(NSDictionary *)params
uniqueId:(NSString *)uniqueId;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef FLBTypes_h
#define FLBTypes_h
typedef void (^FLBEventListener) (NSString *name ,
NSDictionary *arguments);
typedef void (^FLBVoidCallback)(void);
#endif /* FLBTypes_h */
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#import <Flutter/Flutter.h> #import <Flutter/Flutter.h>
#import "FLB2Platform.h" #import "FLB2Platform.h"
#import "FLBTypes.h"
@interface FlutterBoostPlugin : NSObject<FlutterPlugin> @interface FlutterBoostPlugin : NSObject<FlutterPlugin>
...@@ -38,18 +39,11 @@ ...@@ -38,18 +39,11 @@
- (BOOL)isRunning; - (BOOL)isRunning;
- (FlutterViewController *)currentViewController; - (FlutterViewController *)currentViewController;
#pragma mark - handing vc result. #pragma mark - broadcast event to/from flutter
- (void)openPage:(NSString *)name - (void)sendEvent:(NSString *)eventName
params:(NSDictionary *)params arguments:(NSDictionary *)arguments;
animated:(BOOL)animated
completion:(void (^)(BOOL finished))completion
resultHandler:(void (^)(NSString *resultId,NSDictionary *rData))resultHandler;
- (void)onResultForKey:(NSString *)vcId - (FLBVoidCallback)addEventListener:(FLBEventListener)listner
resultData:(NSDictionary *)resultData forName:(NSString *)name;
params:(NSDictionary *)params;
- (void)setResultHandler:(void (^)(NSString *, NSDictionary *))handler
forKey:(NSString *)result_id;
- (void)removeHandlerForKey:(NSString *)vcid;
@end @end
...@@ -23,13 +23,65 @@ ...@@ -23,13 +23,65 @@
*/ */
#import "FlutterBoostPlugin.h" #import "FlutterBoostPlugin.h"
#import "FLBResultMediator.h"
#import "FlutterBoostPlugin_private.h" #import "FlutterBoostPlugin_private.h"
#import "FLBFactory.h" #import "FLBFactory.h"
#import "FLB2Factory.h" #import "FLB2Factory.h"
#import "FLBMessageDispather.h"
#import "FLBMessageImp.h"
#import "NavigationService_closePage.h"
#import "NavigationService_openPage.h"
#import "NavigationService_pageOnStart.h"
#import "NavigationService_onShownContainerChanged.h"
#import "NavigationService_onFlutterPageResult.h"
@interface FlutterBoostPlugin()
@property (nonatomic,strong) FLBMessageDispather *dispatcher;
@end
@implementation FlutterBoostPlugin @implementation FlutterBoostPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"flutter_boost"
binaryMessenger:[registrar messenger]];
FlutterBoostPlugin* instance = [self.class sharedInstance];
[instance registerHandlers];
instance.methodChannel = channel;
instance.broadcastor = [[FLBBroadcastor alloc] initWithMethodChannel:channel];
[registrar addMethodCallDelegate:instance channel:channel];
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"getPlatformVersion" isEqualToString:call.method]) {
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
} else if([@"__event__" isEqual: call.method]){
[_broadcastor handleMethodCall:call result:result];
}else{
FLBMessageImp *msg = FLBMessageImp.new;
msg.name = call.method;
msg.params = call.arguments;
if(![self.dispatcher dispatch:msg result:result]){
result(FlutterMethodNotImplemented);
}
}
}
- (void)registerHandlers
{
NSArray *handlers = @[
NavigationService_openPage.class,
NavigationService_closePage.class,
NavigationService_pageOnStart.class,
NavigationService_onShownContainerChanged.class,
NavigationService_onFlutterPageResult.class
];
for(Class cls in handlers){
[self.dispatcher registerHandler:cls.new];
}
}
+ (instancetype)sharedInstance + (instancetype)sharedInstance
{ {
static id _instance = nil; static id _instance = nil;
...@@ -44,7 +96,7 @@ ...@@ -44,7 +96,7 @@
- (instancetype)init - (instancetype)init
{ {
if (self = [super init]) { if (self = [super init]) {
_resultMediator = [FLBResultMediator new]; _dispatcher = FLBMessageDispather.new;
} }
return self; return self;
...@@ -55,33 +107,12 @@ ...@@ -55,33 +107,12 @@
return _application; return _application;
} }
- (FLBResultMediator *)resultMediator
{
return _resultMediator;
}
- (id<FLBAbstractFactory>)factory - (id<FLBAbstractFactory>)factory
{ {
return _factory; return _factory;
} }
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"flutter_boost"
binaryMessenger:[registrar messenger]];
FlutterBoostPlugin* instance = [self.class sharedInstance];
[registrar addMethodCallDelegate:instance channel:channel];
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"getPlatformVersion" isEqualToString:call.method]) {
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
} else {
result(FlutterMethodNotImplemented);
}
}
- (void)startFlutterWithPlatform:(id<FLB2Platform>)platform - (void)startFlutterWithPlatform:(id<FLB2Platform>)platform
onStart:(void (^)(id<FlutterBinaryMessenger, onStart:(void (^)(id<FlutterBinaryMessenger,
FlutterTextureRegistry, FlutterTextureRegistry,
...@@ -112,31 +143,20 @@ ...@@ -112,31 +143,20 @@
return [self.application flutterViewController]; return [self.application flutterViewController];
} }
- (void)openPage:(NSString *)name
params:(NSDictionary *)params animated:(BOOL)animated
completion:(void (^)(BOOL))completion
resultHandler:(void (^)(NSString *, NSDictionary *))resultHandler
{
static int kRid = 0;
NSString *resultId = [NSString stringWithFormat:@"result_id_%d",kRid++];
[_resultMediator setResultHandler:^(NSString * _Nonnull resultId, NSDictionary * _Nonnull resultData) {
if(resultHandler) resultHandler(resultId,resultData);
} forKey:resultId];
}
- (void)onResultForKey:(NSString *)vcId resultData:(NSDictionary *)resultData params:(NSDictionary *)params
{
[_resultMediator onResultForKey:vcId resultData:resultData params:params];
}
- (void)setResultHandler:(void (^)(NSString *, NSDictionary *))handler forKey:(NSString *)vcid #pragma mark - broadcast event to/from flutter
- (void)sendEvent:(NSString *)eventName
arguments:(NSDictionary *)arguments
{ {
[_resultMediator setResultHandler:handler forKey:vcid]; [_broadcastor sendEvent:eventName
arguments:arguments];
} }
- (void)removeHandlerForKey:(NSString *)vcid - (FLBVoidCallback)addEventListener:(FLBEventListener)listner
forName:(NSString *)name
{ {
[_resultMediator removeHandlerForKey:vcid]; return [_broadcastor addEventListener:listner
forName:name];
} }
@end @end
...@@ -24,22 +24,21 @@ ...@@ -24,22 +24,21 @@
#import <Flutter/Flutter.h> #import <Flutter/Flutter.h>
#import "FLBFlutterApplicationInterface.h" #import "FLBFlutterApplicationInterface.h"
#import "FLBResultMediator.h"
#import "FLBAbstractFactory.h" #import "FLBAbstractFactory.h"
#import "FLBBroadcastor.h"
@interface FlutterBoostPlugin(){ @interface FlutterBoostPlugin(){
id<FLBFlutterApplicationInterface> _application; id<FLBFlutterApplicationInterface> _application;
FLBResultMediator *_resultMediator;
id<FLBAbstractFactory> _factory; id<FLBAbstractFactory> _factory;
} }
- (id<FLBFlutterApplicationInterface>)application; - (id<FLBFlutterApplicationInterface>)application;
- (FLBResultMediator *)resultMediator;
- (id<FLBAbstractFactory>)factory; - (id<FLBAbstractFactory>)factory;
@property (nonatomic,strong) FlutterMethodChannel *methodChannel;
@property (nonatomic,strong) FLBBroadcastor *broadcastor;
@property (nonatomic,copy) NSString *fPageId; @property (nonatomic,copy) NSString *fPageId;
@property (nonatomic,copy) NSString *fPagename; @property (nonatomic,copy) NSString *fPagename;
@property (nonatomic,strong) NSDictionary *fParams; @property (nonatomic,strong) NSDictionary *fParams;
@end @end
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
// Generated by AIOCodeGen do not edit! // Generated by AIOCodeGen do not edit!
#import "FlutterServiceCallHandler.h" #import "FLBMessageHandlerImp.h"
@interface NavigationService_closePage : FlutterServiceCallHandler
@end @interface NavigationService_closePage : FLBMessageHandlerImp
\ No newline at end of file @end
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
//Generated by AIOCodeGen.
#import "ServiceGateway.h" #import "ServiceGateway.h"
#import "NavigationService_closePage.h" #import "NavigationService_closePage.h"
...@@ -31,36 +30,30 @@ ...@@ -31,36 +30,30 @@
#define FLUTTER_APP [FlutterBoostPlugin sharedInstance].application #define FLUTTER_APP [FlutterBoostPlugin sharedInstance].application
@implementation NavigationService_closePage @implementation NavigationService_closePage
- (void)onCall:(void (^)(BOOL))result
uniqueId:(NSString *)uniqueId
pageName:(NSString *)pageName
params:(NSDictionary *)params
animated:(NSNumber *)animated
{
//Add your handler code here!
[FLUTTER_APP.platform closePage:uniqueId
animated:animated.boolValue
params:params
completion:^(BOOL finished) {
if(result) result(finished);
}];
}
#pragma mark - Do not edit these method. #pragma mark - Do not edit these method.
- (void)__flutter_p_handler_closePage:(NSDictionary *)args result:(void (^)(BOOL))result { - (BOOL)call:(id<FLBMessage>)msg result:(void (^)(BOOL))resultBlock
[self onCall:result uniqueId:args[@"uniqueId"] pageName:args[@"pageName"] params:args[@"params"] animated:args[@"animated"]]; {
} NSDictionary *args = msg.params;
+ (void)load{ NSDictionary *exts = args[@"exts"];
[[ServiceGateway sharedInstance] registerHandler:[NavigationService_closePage new]]; NSString *uid = args[@"uniqueId"];
NSDictionary *resultData = args[@"result"];
[FLUTTER_APP close:uid
result:resultData
exts:exts
completion:resultBlock];
return YES;
} }
- (NSString *)returnType - (NSString *)returnType
{ {
return @"BOOL"; return @"BOOL";
} }
- (NSString *)service
{ - (NSArray *)handledMessageNames
return @"NavigationService"; {
} return @[@"closePage"];
}
@end @end
...@@ -23,6 +23,6 @@ ...@@ -23,6 +23,6 @@
*/ */
// Generated by AIOCodeGen do not edit! // Generated by AIOCodeGen do not edit!
#import "FlutterServiceCallHandler.h" #import "FLBMessageHandlerImp.h"
@interface NavigationService_onFlutterPageResult : FlutterServiceCallHandler @interface NavigationService_onFlutterPageResult : FLBMessageHandlerImp
@end @end
\ No newline at end of file
...@@ -32,26 +32,25 @@ ...@@ -32,26 +32,25 @@
- (void)onCall:(void (^)(BOOL))result uniqueId:(NSString *)uniqueId key:(NSString *)key resultData:(NSDictionary *)resultData params:(NSDictionary *)params - (void)onCall:(void (^)(BOOL))result uniqueId:(NSString *)uniqueId key:(NSString *)key resultData:(NSDictionary *)resultData params:(NSDictionary *)params
{ {
//Add your handler code here!
[FlutterBoostPlugin.sharedInstance onResultForKey:key
resultData:resultData
params:params];
} }
#pragma mark - Do not edit these method. #pragma mark - Do not edit these method.
- (void)__flutter_p_handler_onFlutterPageResult:(NSDictionary *)args result:(void (^)(BOOL))result { - (BOOL)call:(id<FLBMessage>)msg result:(void (^)(BOOL))result
{
NSDictionary *args = msg.params;
[self onCall:result uniqueId:args[@"uniqueId"] key:args[@"key"] resultData:args[@"resultData"] params:args[@"params"]]; [self onCall:result uniqueId:args[@"uniqueId"] key:args[@"key"] resultData:args[@"resultData"] params:args[@"params"]];
return YES;
} }
+ (void)load{
[[ServiceGateway sharedInstance] registerHandler:[NavigationService_onFlutterPageResult new]]; - (NSArray *)handledMessageNames
} {
return @[@"onFlutterPageResult"];
}
- (NSString *)returnType - (NSString *)returnType
{ {
return @"BOOL"; return @"BOOL";
} }
- (NSString *)service
{
return @"NavigationService";
}
@end @end
...@@ -23,6 +23,6 @@ ...@@ -23,6 +23,6 @@
*/ */
// Generated by AIOCodeGen do not edit! // Generated by AIOCodeGen do not edit!
#import "FlutterServiceCallHandler.h" #import "FLBMessageHandlerImp.h"
@interface NavigationService_onShownContainerChanged : FlutterServiceCallHandler @interface NavigationService_onShownContainerChanged : FLBMessageHandlerImp
@end @end
\ No newline at end of file
...@@ -38,19 +38,21 @@ ...@@ -38,19 +38,21 @@
} }
#pragma mark - Do not edit these method. #pragma mark - Do not edit these method.
- (void)__flutter_p_handler_onShownContainerChanged:(NSDictionary *)args result:(void (^)(BOOL))result { - (BOOL)call:(id<FLBMessage>)msg result:(void (^)(BOOL))result
{
NSDictionary *args = msg.params;
[self onCall:result newName:args[@"newName"] oldName:args[@"oldName"] params:args[@"params"]]; [self onCall:result newName:args[@"newName"] oldName:args[@"oldName"] params:args[@"params"]];
return YES;
} }
+ (void)load{
[[ServiceGateway sharedInstance] registerHandler:[NavigationService_onShownContainerChanged new]];
}
- (NSString *)returnType - (NSString *)returnType
{ {
return @"BOOL"; return @"BOOL";
} }
- (NSString *)service - (NSArray *)handledMessageNames
{ {
return @"NavigationService"; return @[@"onShownContainerChanged"];
} }
@end @end
...@@ -23,6 +23,6 @@ ...@@ -23,6 +23,6 @@
*/ */
// Generated by AIOCodeGen do not edit! // Generated by AIOCodeGen do not edit!
#import "FlutterServiceCallHandler.h" #import "FLBMessageHandlerImp.h"
@interface NavigationService_openPage : FlutterServiceCallHandler @interface NavigationService_openPage : FLBMessageHandlerImp
@end @end
\ No newline at end of file
...@@ -32,31 +32,29 @@ ...@@ -32,31 +32,29 @@
#define FLUTTER_APP [FlutterBoostPlugin sharedInstance].application #define FLUTTER_APP [FlutterBoostPlugin sharedInstance].application
@implementation NavigationService_openPage @implementation NavigationService_openPage
- (void)onCall:(void (^)(BOOL))result pageName:(NSString *)pageName params:(NSDictionary *)params animated:(NSNumber *)animated
{
[FLUTTER_APP.platform openPage:pageName
params:params
animated:animated.boolValue
completion:^(BOOL finished) {
if(result)result(YES);
}];
}
#pragma mark - Do not edit these method. #pragma mark - Do not edit these method.
- (void)__flutter_p_handler_openPage:(NSDictionary *)args result:(void (^)(BOOL))result { - (BOOL)call:(id<FLBMessage>)msg result:(void (^)(NSDictionary *))result{
[self onCall:result pageName:args[@"pageName"] params:args[@"params"] animated:args[@"animated"]]; NSDictionary *args = msg.params;
} NSString *url = args[@"url"];
+ (void)load{ NSDictionary *urlParams = args[@"urlParams"];
[[ServiceGateway sharedInstance] registerHandler:[NavigationService_openPage new]]; NSDictionary *exts = args[@"exts"];
[FLUTTER_APP open:url
urlParams:urlParams
exts:exts
reult:result
completion:^(BOOL) {}];
return YES;
} }
- (NSString *)returnType - (NSString *)returnType
{ {
return @"BOOL"; return @"NSDictionary *";
}
- (NSString *)service
{
return @"NavigationService";
} }
- (NSArray *)handledMessageNames
{
return @[@"openPage"];
}
@end @end
...@@ -23,6 +23,6 @@ ...@@ -23,6 +23,6 @@
*/ */
// Generated by AIOCodeGen do not edit! // Generated by AIOCodeGen do not edit!
#import "FlutterServiceCallHandler.h" #import "FLBMessageHandlerImp.h"
@interface NavigationService_pageOnStart : FlutterServiceCallHandler @interface NavigationService_pageOnStart : FLBMessageHandlerImp
@end @end
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
//Generated by AIOCodeGen. //Generated by AIOCodeGen.
#import "ServiceGateway.h" #import "ServiceGateway.h"
#import "NavigationService_pageOnStart.h" #import "NavigationService_pageOnStart.h"
#import "FlutterBoostPlugin_private.h" #import "FlutterBoostPlugin_private.h"
@implementation NavigationService_pageOnStart @implementation NavigationService_pageOnStart
...@@ -40,19 +40,22 @@ ...@@ -40,19 +40,22 @@
} }
#pragma mark - Do not edit these method. #pragma mark - Do not edit these method.
- (void)__flutter_p_handler_pageOnStart:(NSDictionary *)args result:(void (^)(NSDictionary *))result {
[self onCall:result params:args[@"params"]]; - (BOOL)call:(id<FLBMessage>)msg result:(void (^)(NSDictionary *))result
} {
+ (void)load{ NSDictionary *args = msg.params;
[[ServiceGateway sharedInstance] registerHandler:[NavigationService_pageOnStart new]]; [self onCall:result params:args[@"params"]];
} return YES;
}
- (NSString *)returnType - (NSString *)returnType
{ {
return @"NSDictionary *"; return @"NSDictionary *";
} }
- (NSString *)service
{ - (NSArray *)handledMessageNames
return @"NavigationService"; {
} return @[@"pageOnStart"];
}
@end @end
...@@ -22,11 +22,10 @@ ...@@ -22,11 +22,10 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
//Generated by AIOCodeGen do not edit! #import <Foundation/Foundation.h>
#import "FlutterServiceTemplate.h"
@interface Service_NavigationService : NSObject @interface Service_NavigationService : NSObject
+ (FlutterServiceTemplate *)service;
+ (void)onNativePageResult:(void (^)(NSNumber *))result uniqueId:(NSString *)uniqueId key:(NSString *)key resultData:(NSDictionary *)resultData params:(NSDictionary *)params; + (void)onNativePageResult:(void (^)(NSNumber *))result uniqueId:(NSString *)uniqueId key:(NSString *)key resultData:(NSDictionary *)resultData params:(NSDictionary *)params;
+ (void)didShowPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId; + (void)didShowPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId;
+ (void)willShowPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId; + (void)willShowPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId;
...@@ -34,4 +33,4 @@ ...@@ -34,4 +33,4 @@
+ (void)didDisappearPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId; + (void)didDisappearPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId;
+ (void)didInitPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId; + (void)didInitPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId;
+ (void)willDeallocPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId; + (void)willDeallocPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId;
@end @end
\ No newline at end of file
...@@ -22,29 +22,18 @@ ...@@ -22,29 +22,18 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
//Generated by AIOCodeGen. Do not edit!
#import "Service_NavigationService.h"
#import "Service_NavigationService.h" #import <Flutter/Flutter.h>
#import "ServiceGateway.h" #import "FlutterBoostPlugin_private.h"
#import "FlutterServiceTemplate.h"
@implementation Service_NavigationService @implementation Service_NavigationService
+ (FlutterServiceTemplate *)service + (FlutterMethodChannel *)methodChannel
{ {
static id _instance = nil; return FlutterBoostPlugin.sharedInstance.methodChannel;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[FlutterServiceTemplate alloc] initWithName:@"NavigationService"];
});
return _instance;
}
+ (void)load{
[[ServiceGateway sharedInstance] addService:[self service]];
} }
+ (void)onNativePageResult:(void (^)(NSNumber *))result uniqueId:(NSString *)uniqueId key:(NSString *)key resultData:(NSDictionary *)resultData params:(NSDictionary *)params + (void)onNativePageResult:(void (^)(NSNumber *))result uniqueId:(NSString *)uniqueId key:(NSString *)key resultData:(NSDictionary *)resultData params:(NSDictionary *)params
{ {
NSMutableDictionary *tmp = [NSMutableDictionary dictionary]; NSMutableDictionary *tmp = [NSMutableDictionary dictionary];
...@@ -52,7 +41,7 @@ ...@@ -52,7 +41,7 @@
if(key) tmp[@"key"] = key; if(key) tmp[@"key"] = key;
if(resultData) tmp[@"resultData"] = resultData; if(resultData) tmp[@"resultData"] = resultData;
if(params) tmp[@"params"] = params; if(params) tmp[@"params"] = params;
[self.service invoke:@"onNativePageResult" args:tmp result:^(id tTesult) { [self.methodChannel invokeMethod:@"onNativePageResult" arguments:tmp result:^(id tTesult) {
if (result) { if (result) {
result(tTesult); result(tTesult);
} }
...@@ -65,7 +54,7 @@ ...@@ -65,7 +54,7 @@
if(pageName) tmp[@"pageName"] = pageName; if(pageName) tmp[@"pageName"] = pageName;
if(params) tmp[@"params"] = params; if(params) tmp[@"params"] = params;
if(uniqueId) tmp[@"uniqueId"] = uniqueId; if(uniqueId) tmp[@"uniqueId"] = uniqueId;
[self.service invoke:@"didShowPageContainer" args:tmp result:^(id tTesult) { [self.methodChannel invokeMethod:@"didShowPageContainer" arguments:tmp result:^(id tTesult) {
if (result) { if (result) {
result(tTesult); result(tTesult);
} }
...@@ -78,7 +67,7 @@ ...@@ -78,7 +67,7 @@
if(pageName) tmp[@"pageName"] = pageName; if(pageName) tmp[@"pageName"] = pageName;
if(params) tmp[@"params"] = params; if(params) tmp[@"params"] = params;
if(uniqueId) tmp[@"uniqueId"] = uniqueId; if(uniqueId) tmp[@"uniqueId"] = uniqueId;
[self.service invoke:@"willShowPageContainer" args:tmp result:^(id tTesult) { [self.methodChannel invokeMethod:@"willShowPageContainer" arguments:tmp result:^(id tTesult) {
if (result) { if (result) {
result(tTesult); result(tTesult);
} }
...@@ -91,7 +80,7 @@ ...@@ -91,7 +80,7 @@
if(pageName) tmp[@"pageName"] = pageName; if(pageName) tmp[@"pageName"] = pageName;
if(params) tmp[@"params"] = params; if(params) tmp[@"params"] = params;
if(uniqueId) tmp[@"uniqueId"] = uniqueId; if(uniqueId) tmp[@"uniqueId"] = uniqueId;
[self.service invoke:@"willDisappearPageContainer" args:tmp result:^(id tTesult) { [self.methodChannel invokeMethod:@"willDisappearPageContainer" arguments:tmp result:^(id tTesult) {
if (result) { if (result) {
result(tTesult); result(tTesult);
} }
...@@ -104,7 +93,7 @@ ...@@ -104,7 +93,7 @@
if(pageName) tmp[@"pageName"] = pageName; if(pageName) tmp[@"pageName"] = pageName;
if(params) tmp[@"params"] = params; if(params) tmp[@"params"] = params;
if(uniqueId) tmp[@"uniqueId"] = uniqueId; if(uniqueId) tmp[@"uniqueId"] = uniqueId;
[self.service invoke:@"didDisappearPageContainer" args:tmp result:^(id tTesult) { [self.methodChannel invokeMethod:@"didDisappearPageContainer" arguments:tmp result:^(id tTesult) {
if (result) { if (result) {
result(tTesult); result(tTesult);
} }
...@@ -117,11 +106,15 @@ ...@@ -117,11 +106,15 @@
if(pageName) tmp[@"pageName"] = pageName; if(pageName) tmp[@"pageName"] = pageName;
if(params) tmp[@"params"] = params; if(params) tmp[@"params"] = params;
if(uniqueId) tmp[@"uniqueId"] = uniqueId; if(uniqueId) tmp[@"uniqueId"] = uniqueId;
[self.service invoke:@"didInitPageContainer" args:tmp result:^(id tTesult) { [self.methodChannel invokeMethod:@"didInitPageContainer" arguments:tmp result:^(id tTesult) {
if (result) { if (result) {
result(tTesult); result(tTesult);
} }
}]; }];
[FlutterBoostPlugin.sharedInstance.application didInitPageContainer:pageName
params:params
uniqueId:uniqueId];
} }
+ (void)willDeallocPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId + (void)willDeallocPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId
...@@ -130,12 +123,16 @@ ...@@ -130,12 +123,16 @@
if(pageName) tmp[@"pageName"] = pageName; if(pageName) tmp[@"pageName"] = pageName;
if(params) tmp[@"params"] = params; if(params) tmp[@"params"] = params;
if(uniqueId) tmp[@"uniqueId"] = uniqueId; if(uniqueId) tmp[@"uniqueId"] = uniqueId;
[self.service invoke:@"willDeallocPageContainer" args:tmp result:^(id tTesult) { [self.methodChannel invokeMethod:@"willDeallocPageContainer" arguments:tmp result:^(id tTesult) {
if (result) { if (result) {
result(tTesult); result(tTesult);
} }
}]; }];
[FlutterBoostPlugin.sharedInstance.application willDeallocPageContainer:pageName
params:params
uniqueId:uniqueId];
} }
@end @end
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
#import "FLBTypes.h"
NS_ASSUME_NONNULL_BEGIN
@interface FLBBroadcastor : NSObject
- (instancetype)initWithMethodChannel:(FlutterMethodChannel *)channel;
- (void)sendEvent:(NSString *)eventName
arguments:(NSDictionary *)arguments;
- (FLBVoidCallback)addEventListener:(FLBEventListener)listner
forName:(NSString *)name;
- (void)handleMethodCall:(FlutterMethodCall *)call
result:(FlutterResult)result;
@end
NS_ASSUME_NONNULL_END
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2019 Alibaba Group * Copyright (c) 2019 Alibaba Group
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
...@@ -21,61 +21,69 @@ ...@@ -21,61 +21,69 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
import 'package:flutter_boost/support/logger.dart';
import 'package:flutter_boost/AIOService/NavigationService/service/NavigationService.dart';
typedef void PageResultHandler(String key , Map<String,dynamic> result);
typedef VoidCallback = void Function();
class PageResultMediator{ #import "FLBBroadcastor.h"
static int _resultId = 0; @interface FLBBroadcastor()
@property (nonatomic,strong) FlutterMethodChannel *channel;
@property (nonatomic,strong) NSMutableDictionary *lists;
String createResultId(){ @end
_resultId++;
return "result_id_$_resultId";
}
bool isResultId(String rid){ @implementation FLBBroadcastor
if(rid == null) return false;
return rid.contains("result_id");
}
Map<String,PageResultHandler> _handlers = Map(); - (instancetype)initWithMethodChannel:(FlutterMethodChannel *)channel
void onPageResult(String key , Map<String,dynamic> resultData, Map params){ {
if (self = [super init]) {
if(key == null) return; _channel = channel;
_lists = NSMutableDictionary.new;
Logger.log("did receive page result $resultData for page key $key"); }
return self;
}
if(_handlers.containsKey(key)){ - (void)sendEvent:(NSString *)eventName
_handlers[key](key,resultData); arguments:(NSDictionary *)arguments
_handlers.remove(key); {
}else{ if(!eventName) return;
//Cannot find handler consider forward to native. NSMutableDictionary *msg = NSMutableDictionary.new;
//Use forward to avoid circle. msg[@"name"] = eventName;
if(params == null || !params.containsKey("forward")){ msg[@"arguments"] = arguments;
if(params == null){ [_channel invokeMethod:@"__event__"
params = new Map(); arguments:msg
} result:^(id r){}];
params["forward"] = 1; }
NavigationService.onFlutterPageResult(key, key , resultData, params);
}else{
params["forward"] = params["forward"]+1;
if(params["forward"] <= 2){
NavigationService.onFlutterPageResult(key, key , resultData, params);
}
}
- (FLBVoidCallback)addEventListener:(FLBEventListener)listner
forName:(NSString *)name
{
if(!name || !listner) return ^{};
NSMutableArray *list = _lists[name];
if(!list){
list = NSMutableArray.new;
_lists[name] = list;
} }
} [list addObject:listner];
return ^{
VoidCallback setPageResultHandler(String key, PageResultHandler handler){ [list removeObject:listner];
if(key == null || handler == null) return (){};
_handlers[key] = handler;
return (){
_handlers.remove(key);
}; };
} }
- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
{
if([call.method isEqual:@"__event__"]){
NSString *name = call.arguments[@"name"];
NSDictionary *arguments = call.arguments[@"arguments"];
if(name){
NSMutableArray *list = _lists[name];
if(list){
for(FLBEventListener l in list){
l(name,arguments);
}
}
}
}
} }
@end
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
#import "FLBMessageing.h"
@interface FLBMessageDispather : NSObject<FLBMessageDispatcher>
@end
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "FLBMessageDispather.h"
@interface FLBMessageDispather()
@property (nonatomic,strong) NSMutableDictionary *handlerMap;
@end
@implementation FLBMessageDispather
- (instancetype)init
{
if (self = [super init]) {
_handlerMap = NSMutableDictionary.new;
}
return self;
}
- (BOOL)dispatch:(id<FLBMessage>)msg result:(void (^)(id date))result
{
if (msg) {
id<FLBMessageHandler> handler = _handlerMap[msg.name];
[handler handle:msg result:result];
return handler != nil;
}else{
return NO;
}
}
- (void)registerHandler:(id<FLBMessageHandler>)handler
{
if(!handler) return;
NSArray *methods = handler.handledMessageNames;
for(NSString *name in methods){
if(_handlerMap[name]){
NSAssert(NO, @"Conflicted method call name results in undefined error!");
}else{
_handlerMap[name] = handler;
}
}
}
- (void)removeHandler:(id<FLBMessageHandler>)handler
{
NSArray *methods = handler.handledMessageNames;
[_handlerMap removeObjectsForKeys:methods];
}
- (void)removeAll
{
[_handlerMap removeAllObjects];
}
@end
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
#import "FLBMessageing.h"
@interface FLBMessageHandlerImp : NSObject<FLBMessageHandler>
@end
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "FLBMessageHandlerImp.h"
#import "FLBMessageImp.h"
typedef void (^SendResult)(NSObject *result);
@interface FLBMessageHandlerImp()
@property (nonatomic,strong) NSMutableDictionary *callHandlers;
@property (nonatomic,strong) NSMutableArray *methodNames;
@end
@implementation FLBMessageHandlerImp
- (instancetype)init{
if (self = [super init]) {
_callHandlers = [NSMutableDictionary new];
_methodNames = NSMutableArray.new;
[self bindCallMethod];
}
return self;
}
#pragma mark - method handling logic.
//Farward this msg to old entry.
- (BOOL)handle:(id<FLBMessage>)msg result:(void (^)(id data))result
{
return [self handleMethodCall:msg.name args:msg.params result:result];
}
- (NSArray *)handledMessageNames
{
return _methodNames;
}
- (bool)handleMethodCall:(NSString*)call
args:(NSDictionary *)args
result:(void (^)(id data))result
{
void (^handler)(NSDictionary *,SendResult) = [self findHandler:call];
if (handler) {
handler(args,result);
return YES;
}
return NO;
}
- (id)findHandler:(NSString *)call
{
return _callHandlers[call];
}
- (void)bindCallMethod
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
SEL method = @selector(call:result:);
for(NSString *name in self.handledMessageNames){
if (_callHandlers[name]) {
continue;
}
__weak typeof(self) weakSelf = self;
_callHandlers[name] = ^(NSDictionary *args,SendResult result){
id resultBlock = [weakSelf getHandlerBlockForType:weakSelf.returnType result:result];
if (resultBlock && result) {
FLBMessageImp *msg = FLBMessageImp.new;
msg.name = name;
msg.params = args;
[weakSelf performSelector:method withObject:msg withObject:resultBlock];
}else{
#if DEBUG
[NSException raise:@"invalid call" format:@"missing handler and result!"];
#endif
}
};
}
#pragma clang diagnostic pop
}
- (id)getHandlerBlockForType:(NSString *)type result:(SendResult)result
{
if ([type isEqual:@"int64_t"]) {
return ^(int64_t value){
result(@(value));
};
}
if ([type isEqual:@"double"]) {
return ^(double value){
result(@(value));
};
}
if ([type isEqual:@"BOOL"]) {
return ^(BOOL value){
result(@(value));
};
}
if ([type hasPrefix:@"NSString"]) {
return ^(NSString *value){
if ([value isKindOfClass:NSNumber.class]) {
#if DEBUG
[NSException raise:@"invalid type" format:@"require NSString!"];
#endif
value = ((NSNumber *)value).stringValue;
}
result(value);
};
}
if ([type hasPrefix:@"NSArray"]) {
return ^(NSArray *value){
result(value);
};
}
if ([type hasPrefix:@"NSDictionary"]) {
return ^(NSDictionary *value){
result(value);
};
}
if ([type isEqual:@"id"]) {
return result;
}
/*
@"int":@"int64_t",
@"double":@"double",
@"bool":@"BOOL",
@"String":@"NSString *",
*/
return nil;
}
- (NSString *)returnType
{
return @"id";
}
- (NSString *)service
{
return @"root";
}
@end
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2019 Alibaba Group * Copyright (c) 2019 Alibaba Group
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
...@@ -21,18 +21,15 @@ ...@@ -21,18 +21,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "FLBMessageing.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
typedef void (^FLBPageResultHandler)(NSString *, NSDictionary *); @interface FLBMessageImp : NSObject<FLBMessage>
@interface FLBResultMediator : NSObject
- (void)onResultForKey:(NSString *)resultId resultData:(NSDictionary *)resultData params:(NSDictionary *)params; @property (nonatomic,copy) NSString *name;
- (void)setResultHandler:(FLBPageResultHandler)handler forKey:(NSString *)vcid; @property (nonatomic,strong) NSDictionary *params;
- (void)removeHandlerForKey:(NSString *)vcid;
@end @end
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "FLBMessageImp.h"
@implementation FLBMessageImp
- (NSString *)name
{
return _name;
}
- (NSDictionary *)params
{
return _params;
}
@end
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
@protocol FLBMessage <NSObject>
@required
- (NSString *)name;
- (NSDictionary *)params;
@end
@protocol FLBMessageHandler <NSObject>
@required
- (BOOL)handle:(id<FLBMessage>)msg result:(void (^)(id result))result;
- (NSArray *)handledMessageNames;
- (NSString *)service;
@end
@protocol FLBMessageDispatcher <NSObject>
@required
- (BOOL)dispatch:(id<FLBMessage>)msg result:(void (^)(id result))result;
- (void)registerHandler:(id<FLBMessageHandler>) handler;
- (void)removeHandler:(id<FLBMessageHandler>) handler;
- (void)removeAll;
@end
...@@ -21,12 +21,11 @@ A new Flutter plugin make flutter better to use! ...@@ -21,12 +21,11 @@ A new Flutter plugin make flutter better to use!
'Classes/Boost/FLB2Platform.h', 'Classes/Boost/FLB2Platform.h',
'Classes/Boost/FLBFlutterContainer.h', 'Classes/Boost/FLBFlutterContainer.h',
'Classes/Boost/FLBFlutterAppDelegate.h', 'Classes/Boost/FLBFlutterAppDelegate.h',
'Classes/Boost/FLBTypes.h',
'Classes/1.0/FLBFlutterViewContainer.h', 'Classes/1.0/FLBFlutterViewContainer.h',
'Classes/1.5/FLB2FlutterViewContainer.h' 'Classes/1.5/FLB2FlutterViewContainer.h'
s.dependency 'Flutter' s.dependency 'Flutter'
s.dependency 'xservice_kit'
s.libraries = 'c++' s.libraries = 'c++'
s.ios.deployment_target = '8.0' s.ios.deployment_target = '8.0'
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import 'NavigationService.dart';
import '../handlers/NavigationService_onNativePageResult.dart';
import '../handlers/NavigationService_didShowPageContainer.dart';
import '../handlers/NavigationService_willShowPageContainer.dart';
import '../handlers/NavigationService_willDisappearPageContainer.dart';
import '../handlers/NavigationService_didDisappearPageContainer.dart';
import '../handlers/NavigationService_didInitPageContainer.dart';
import '../handlers/NavigationService_willDeallocPageContainer.dart';
class NavigationServiceRegister{
static register(){
NavigationService.regsiter();
NavigationService_onNativePageResult.regsiter();
NavigationService_didShowPageContainer.regsiter();
NavigationService_willShowPageContainer.regsiter();
NavigationService_willDisappearPageContainer.regsiter();
NavigationService_didDisappearPageContainer.regsiter();
NavigationService_didInitPageContainer.regsiter();
NavigationService_willDeallocPageContainer.regsiter();
}
}
\ No newline at end of file
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_boost/AIOService/NavigationService/service/NavigationService.dart';
import 'package:flutter_boost/container/boost_container.dart'; import 'package:flutter_boost/container/boost_container.dart';
import 'package:flutter_boost/flutter_boost.dart'; import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter_boost/messaging/native_page_container_event_handler.dart'; import 'package:flutter_boost/messaging/native_page_container_event_handler.dart';
...@@ -37,7 +36,9 @@ class ContainerCoordinator implements NativePageContainerEventHandler { ...@@ -37,7 +36,9 @@ class ContainerCoordinator implements NativePageContainerEventHandler {
PageBuilder _defaultPageBuilder; PageBuilder _defaultPageBuilder;
ContainerCoordinator() { ContainerCoordinator() {
NavigationService.listenEvent(onChannelEvent); FlutterBoost.singleton.addEventListener("lifecycle", (String name , Map arguments){
onChannelEvent(arguments);
});
} }
BoostContainerSettings _createContainerSettings( BoostContainerSettings _createContainerSettings(
...@@ -88,7 +89,7 @@ class ContainerCoordinator implements NativePageContainerEventHandler { ...@@ -88,7 +89,7 @@ class ContainerCoordinator implements NativePageContainerEventHandler {
void onChannelEvent(dynamic event) { void onChannelEvent(dynamic event) {
if (event is Map) { if (event is Map) {
Map map = event as Map; Map map = event;
final String type = map['type']; final String type = map['type'];
switch (type) { switch (type) {
...@@ -177,7 +178,7 @@ class ContainerCoordinator implements NativePageContainerEventHandler { ...@@ -177,7 +178,7 @@ class ContainerCoordinator implements NativePageContainerEventHandler {
FlutterBoost.containerManager?.remove(pageId); FlutterBoost.containerManager?.remove(pageId);
Logger.log( Logger.log(
'native containner dealloc, \nmanager dump:\n${FlutterBoost.containerManager?.dump()}'); 'native containner dealloc, \n manager dump:\n${FlutterBoost.containerManager?.dump()}');
return true; return true;
} }
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
*/ */
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:flutter_boost/AIOService/NavigationService/service/NavigationService.dart'; import 'package:flutter_boost/messaging/service/navigation_service.dart';
import 'package:flutter_boost/container/boost_container.dart'; import 'package:flutter_boost/container/boost_container.dart';
import 'package:flutter_boost/container/container_coordinator.dart'; import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:flutter_boost/flutter_boost.dart'; import 'package:flutter_boost/flutter_boost.dart';
......
...@@ -24,19 +24,26 @@ ...@@ -24,19 +24,26 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter_boost/messaging/service/navigation_service.dart';
import 'package:flutter_boost/AIOService/NavigationService/service/NavigationService.dart';
import 'package:flutter_boost/container/boost_container.dart'; import 'package:flutter_boost/container/boost_container.dart';
import 'package:flutter_boost/container/container_manager.dart'; import 'package:flutter_boost/container/container_manager.dart';
import 'package:flutter_boost/messaging/page_result_mediator.dart';
import 'package:flutter_boost/router/router.dart'; import 'package:flutter_boost/router/router.dart';
import 'AIOService/loader/ServiceLoader.dart';
import 'container/container_coordinator.dart'; import 'container/container_coordinator.dart';
import 'messaging/base/message_dispatcher.dart';
import 'messaging/handlers/did_disappear_page_container_handler.dart';
import 'messaging/handlers/did_show_page_container_handler.dart';
import 'messaging/handlers/did_init_page_container_handler.dart';
import 'messaging/handlers/on_native_page_result_handler.dart';
import 'messaging/handlers/will_dealloc_page_container_handler.dart';
import 'messaging/handlers/will_show_page_container_handler.dart';
import 'messaging/handlers/will_disappear_page_container_handler.dart';
import 'messaging/base/broadcastor.dart';
import 'observers_holders.dart'; import 'observers_holders.dart';
export 'container/boost_container.dart'; export 'container/boost_container.dart';
export 'container/container_manager.dart'; export 'container/container_manager.dart';
import 'package:flutter/services.dart';
typedef Widget PageBuilder(String pageName, Map params, String uniqueId); typedef Widget PageBuilder(String pageName, Map params, String uniqueId);
...@@ -47,18 +54,18 @@ typedef void PostPushRoute( ...@@ -47,18 +54,18 @@ typedef void PostPushRoute(
String pageName, String uniqueId, Map params, Route route, Future result); String pageName, 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>();
final ObserversHolder _observersHolder = ObserversHolder(); final ObserversHolder _observersHolder = ObserversHolder();
final PageResultMediator _resultMediator = PageResultMediator();
final Router _router = Router(); final Router _router = Router();
final MethodChannel _methodChannel = MethodChannel('flutter_boost');
final MessageDispatcher _dispatcher = MessageDispatcher();
FlutterBoost() { int _callbackID = 0;
_router.resultMediator = _resultMediator;
ServiceLoader.load(); Broadcastor _broadcastor;
}
static FlutterBoost get singleton => _instance; static FlutterBoost get singleton => _instance;
...@@ -67,8 +74,8 @@ class FlutterBoost { ...@@ -67,8 +74,8 @@ class FlutterBoost {
static TransitionBuilder init( static TransitionBuilder init(
{TransitionBuilder builder, {TransitionBuilder builder,
PrePushRoute prePush, PrePushRoute prePush,
PostPushRoute postPush}) { PostPushRoute postPush}) {
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?');
...@@ -90,32 +97,105 @@ class FlutterBoost { ...@@ -90,32 +97,105 @@ class FlutterBoost {
ObserversHolder get observersHolder => _observersHolder; ObserversHolder get observersHolder => _observersHolder;
FlutterBoost() {
_broadcastor = Broadcastor(_methodChannel);
//Config message handlers
NavigationService.methodChannel = _methodChannel;
_dispatcher.registerHandler(DidDisappearPageContainerHandler());
_dispatcher.registerHandler(DidInitPageContainerHandler());
_dispatcher.registerHandler(DidShowPageContainerHandler());
_dispatcher.registerHandler(OnNativePageResultHandler());
_dispatcher.registerHandler(WillDeallocPageContainerHandler());
_dispatcher.registerHandler(WillShowPageContainerHandler());
_dispatcher.registerHandler(WillDisappearPageContainerHandler());
_methodChannel.setMethodCallHandler((MethodCall call){
if(call.method == "__event__"){
//Handler broadcast event.
return _broadcastor.handleCall(call);
}else{
return _dispatcher.dispatch(call);
}
});
}
///Register a default page builder. ///Register a default page builder.
void registerDefaultPageBuilder(PageBuilder builder) { void registerDefaultPageBuilder(PageBuilder builder) {
ContainerCoordinator.singleton.registerDefaultPageBuilder(builder); ContainerCoordinator.singleton.registerDefaultPageBuilder(builder);
} }
///Register page builder for a key.
void registerPageBuilder(String pageName, PageBuilder builder) {
ContainerCoordinator.singleton.registerPageBuilder(pageName, builder);
}
///Register a map builders ///Register a map builders
void registerPageBuilders(Map<String, PageBuilder> builders) { void registerPageBuilders(Map<String, PageBuilder> builders) {
ContainerCoordinator.singleton.registerPageBuilders(builders); ContainerCoordinator.singleton.registerPageBuilders(builders);
} }
Future<bool> openPage(String url, Map params, Future<Map<dynamic,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts}){
{bool animated, PageResultHandler resultHandler}) { if(urlParams == null) {
return _router.openPage(url, params, urlParams = Map();
animated: animated, resultHandler: resultHandler); }
if(exts == null){
exts = Map();
}
urlParams["__calback_id__"] = _callbackID;
_callbackID += 2;
return _router.open(url,urlParams: urlParams,exts: exts);
}
Future<bool> close(String id,{Map<String,dynamic> result,Map<String,dynamic> exts}){
if(result == null) {
result = Map();
}
if(exts == null){
exts = Map();
}
return _router.close(id,result: result,exts: exts);
}
//Listen broadcast event from native.
Function addEventListener(String name , EventListener listener){
return _broadcastor.addEventListener(name, listener);
}
//Send broadcast event to native.
void sendEvent(String name , Map arguments){
_broadcastor.sendEvent(name, arguments);
}
Future<Map<String,dynamic>> openPage(String name, Map params,{bool animated}) {
Map<String,dynamic> exts = Map();
if(animated != null){
exts["animated"] = animated;
}else{
exts["animated"] = true;
}
return open(name,urlParams: params , exts: exts);
} }
Future<bool> closePage(String url, String pageId, Map params, Future<bool> closePage(String url, String id, Map params,
{bool animated}) { {bool animated}) {
return _router.closePage(url, pageId, params, animated: animated);
Map<String,dynamic> exts = Map();
if(animated != null){
exts["animated"] = animated;
}else{
exts["animated"] = true;
}
if(url != null){
exts["url"] = url;
}
if(params != null){
exts["params"] = params;
}
close(id, result: {} , exts: exts);
} }
//Close currentPage page. //Close currentPage page.
Future<bool> closeCurPage(Map params) { Future<bool> closeCurPage(Map params) {
return _router.closeCurPage(params); return _router.closeCurPage(params);
...@@ -142,21 +222,6 @@ class FlutterBoost { ...@@ -142,21 +222,6 @@ class FlutterBoost {
} }
bool onPageResult(String key, Map resultData, Map params) {
if(_resultMediator.isResultId(key)){
_resultMediator.onPageResult(key, resultData,params);
}else{
containerManager?.containerStateOf(key)?.performOnResult(resultData);
}
return true;
}
VoidCallback setPageResultHandler(String key, PageResultHandler handler) {
return _resultMediator.setPageResultHandler(key, handler);
}
///register for Container changed callbacks ///register for Container changed callbacks
VoidCallback addContainerObserver(BoostContainerObserver observer) => VoidCallback addContainerObserver(BoostContainerObserver observer) =>
_observersHolder.addObserver<BoostContainerObserver>(observer); _observersHolder.addObserver<BoostContainerObserver>(observer);
...@@ -169,4 +234,6 @@ class FlutterBoost { ...@@ -169,4 +234,6 @@ 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);
} }
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import 'package:flutter/services.dart';
typedef Future<dynamic> EventListener(String name , Map arguments);
class Broadcastor{
MethodChannel _channel;
Map<String,List<EventListener>> _lists = Map();
Broadcastor(MethodChannel channel){
_channel = channel;
}
void sendEvent(String name , Map arguments){
if(name == null) {
return;
}
if(arguments == null){
arguments = Map();
}
Map msg = Map();
msg["name"] = name;
msg["arguments"] = arguments;
_channel.invokeMethod("__event__",msg);
}
Function addEventListener(String name , EventListener listener){
if(name == null || listener == null){
return (){};
}
List<EventListener> list = _lists[name];
if(list == null){
list = List();
_lists[name] = list;
}
list.add(listener);
return (){
list.remove(listener);
};
}
Future<dynamic> handleCall(MethodCall call){
if(call.method != "__event__"){
return Future<dynamic>((){});
}
String name = call.arguments["name"];
Map arg = call.arguments["arguments"];
List<EventListener> list = _lists[name];
if(list != null){
for(EventListener l in list){
l(name,arg);
}
}
return Future<dynamic>((){});
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import 'dart:async';
import 'package:flutter/services.dart';
import 'message_handler.dart';
class MessageDispatcher{
Map<String,MessageHandler> _handlers = Map();
Future<dynamic> dispatch(MethodCall call){
if(_handlers.containsKey(call.method)){
return _handlers[call.method].onMethodCall(call);
}{
return null;
}
}
void registerHandler(MessageHandler handler){
_handlers[handler.name()] = handler;
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import 'dart:async';
import 'package:flutter/services.dart';
abstract class MessageHandler{
String name();
Future<dynamic> onMethodCall(MethodCall call);
}
\ No newline at end of file
...@@ -25,24 +25,15 @@ import 'dart:async'; ...@@ -25,24 +25,15 @@ import 'dart:async';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_boost/container/container_coordinator.dart'; import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:xservice_kit/ServiceCallHandler.dart'; import 'package:flutter_boost/messaging/base/message_handler.dart';
import 'package:xservice_kit/ServiceGateway.dart';
class NavigationService_didDisappearPageContainer extends ServiceCallHandler { class DidDisappearPageContainerHandler implements MessageHandler {
static void regsiter() {
ServiceGateway.sharedInstance()
.registerHandler(new NavigationService_didDisappearPageContainer());
}
@override @override
String name() { String name() {
return "didDisappearPageContainer"; return "didDisappearPageContainer";
} }
@override
String service() {
return "NavigationService";
}
@override @override
Future<bool> onMethodCall(MethodCall call) { Future<bool> onMethodCall(MethodCall call) {
......
...@@ -24,14 +24,14 @@ ...@@ -24,14 +24,14 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:xservice_kit/ServiceCallHandler.dart';
import 'package:xservice_kit/ServiceGateway.dart';
import 'package:flutter_boost/container/container_coordinator.dart'; import 'package:flutter_boost/container/container_coordinator.dart';
class NavigationService_didInitPageContainer extends ServiceCallHandler { import 'package:flutter_boost/messaging/base/message_handler.dart';
class DidInitPageContainerHandler implements MessageHandler {
static void regsiter() { static void regsiter() {
ServiceGateway.sharedInstance() // ServiceGateway.sharedInstance()
.registerHandler(new NavigationService_didInitPageContainer()); // .registerHandler(new NavigationService_didInitPageContainer());
} }
@override @override
...@@ -39,10 +39,6 @@ class NavigationService_didInitPageContainer extends ServiceCallHandler { ...@@ -39,10 +39,6 @@ class NavigationService_didInitPageContainer extends ServiceCallHandler {
return "didInitPageContainer"; return "didInitPageContainer";
} }
@override
String service() {
return "NavigationService";
}
@override @override
Future<bool> onMethodCall(MethodCall call) { Future<bool> onMethodCall(MethodCall call) {
......
...@@ -25,25 +25,15 @@ import 'dart:async'; ...@@ -25,25 +25,15 @@ import 'dart:async';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_boost/container/container_coordinator.dart'; import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:xservice_kit/ServiceCallHandler.dart'; import 'package:flutter_boost/messaging/base/message_handler.dart';
import 'package:xservice_kit/ServiceGateway.dart';
class NavigationService_didShowPageContainer extends ServiceCallHandler { class DidShowPageContainerHandler implements MessageHandler {
static void regsiter() {
ServiceGateway.sharedInstance()
.registerHandler(new NavigationService_didShowPageContainer());
}
@override @override
String name() { String name() {
return "didShowPageContainer"; return "didShowPageContainer";
} }
@override
String service() {
return "NavigationService";
}
@override @override
Future<bool> onMethodCall(MethodCall call) { Future<bool> onMethodCall(MethodCall call) {
return onCall(call.arguments["pageName"], call.arguments["params"], return onCall(call.arguments["pageName"], call.arguments["params"],
......
...@@ -24,26 +24,16 @@ ...@@ -24,26 +24,16 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:xservice_kit/ServiceCallHandler.dart';
import 'package:xservice_kit/ServiceGateway.dart';
import 'package:flutter_boost/flutter_boost.dart';
class NavigationService_onNativePageResult extends ServiceCallHandler { import 'package:flutter_boost/messaging/base/message_handler.dart';
static void regsiter() { class OnNativePageResultHandler implements MessageHandler {
ServiceGateway.sharedInstance().registerHandler(new NavigationService_onNativePageResult());
}
@override @override
String name() { String name() {
return "onNativePageResult"; return "onNativePageResult";
} }
@override
String service() {
return "NavigationService";
}
@override @override
Future<bool> onMethodCall(MethodCall call) { Future<bool> onMethodCall(MethodCall call) {
return onCall(call.arguments["uniqueId"],call.arguments["key"],call.arguments["resultData"],call.arguments["params"]); return onCall(call.arguments["uniqueId"],call.arguments["key"],call.arguments["resultData"],call.arguments["params"]);
...@@ -51,6 +41,5 @@ class NavigationService_onNativePageResult extends ServiceCallHandler { ...@@ -51,6 +41,5 @@ class NavigationService_onNativePageResult extends ServiceCallHandler {
//==============================================Do not edit code above! //==============================================Do not edit code above!
Future<bool> onCall(String uniqueId,String key,Map resultData,Map params) async{ Future<bool> onCall(String uniqueId,String key,Map resultData,Map params) async{
return FlutterBoost.singleton.onPageResult(key, resultData, params);
} }
} }
...@@ -25,25 +25,14 @@ import 'dart:async'; ...@@ -25,25 +25,14 @@ import 'dart:async';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_boost/container/container_coordinator.dart'; import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:xservice_kit/ServiceCallHandler.dart'; import 'package:flutter_boost/messaging/base/message_handler.dart';
import 'package:xservice_kit/ServiceGateway.dart';
class NavigationService_willDeallocPageContainer extends ServiceCallHandler {
static void regsiter() {
ServiceGateway.sharedInstance()
.registerHandler(new NavigationService_willDeallocPageContainer());
}
class WillDeallocPageContainerHandler implements MessageHandler {
@override @override
String name() { String name() {
return "willDeallocPageContainer"; return "willDeallocPageContainer";
} }
@override
String service() {
return "NavigationService";
}
@override @override
Future<bool> onMethodCall(MethodCall call) { Future<bool> onMethodCall(MethodCall call) {
return onCall(call.arguments["pageName"], call.arguments["params"], return onCall(call.arguments["pageName"], call.arguments["params"],
......
...@@ -25,25 +25,15 @@ import 'dart:async'; ...@@ -25,25 +25,15 @@ import 'dart:async';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_boost/container/container_coordinator.dart'; import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:xservice_kit/ServiceCallHandler.dart'; import 'package:flutter_boost/messaging/base/message_handler.dart';
import 'package:xservice_kit/ServiceGateway.dart';
class NavigationService_willDisappearPageContainer extends ServiceCallHandler { class WillDisappearPageContainerHandler implements MessageHandler {
static void regsiter() {
ServiceGateway.sharedInstance()
.registerHandler(new NavigationService_willDisappearPageContainer());
}
@override @override
String name() { String name() {
return "willDisappearPageContainer"; return "willDisappearPageContainer";
} }
@override
String service() {
return "NavigationService";
}
@override @override
Future<bool> onMethodCall(MethodCall call) { Future<bool> onMethodCall(MethodCall call) {
return onCall(call.arguments["pageName"], call.arguments["params"], return onCall(call.arguments["pageName"], call.arguments["params"],
......
...@@ -25,25 +25,15 @@ import 'dart:async'; ...@@ -25,25 +25,15 @@ import 'dart:async';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_boost/container/container_coordinator.dart'; import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:xservice_kit/ServiceCallHandler.dart'; import 'package:flutter_boost/messaging/base/message_handler.dart';
import 'package:xservice_kit/ServiceGateway.dart';
class NavigationService_willShowPageContainer extends ServiceCallHandler { class WillShowPageContainerHandler implements MessageHandler {
static void regsiter() {
ServiceGateway.sharedInstance()
.registerHandler(new NavigationService_willShowPageContainer());
}
@override @override
String name() { String name() {
return "willShowPageContainer"; return "willShowPageContainer";
} }
@override
String service() {
return "NavigationService";
}
@override @override
Future<bool> onMethodCall(MethodCall call) { Future<bool> onMethodCall(MethodCall call) {
return onCall(call.arguments["pageName"], call.arguments["params"], return onCall(call.arguments["pageName"], call.arguments["params"],
......
...@@ -21,23 +21,27 @@ ...@@ -21,23 +21,27 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
import 'package:flutter_boost/AIOService/NavigationService/service/NavigationService.dart'; import 'package:flutter_boost/messaging/service/navigation_service.dart';
import 'dart:async'; import 'dart:async';
abstract class MessageProxy{ abstract class MessageProxy{
Future<bool> openPage(String pageName,Map params,bool animated); Future<Map<dynamic,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts});
Future<bool> closePage(String uniqueId,String pageName,Map params,bool animated); Future<bool> close(String id,{Map<String,dynamic> result,Map<String,dynamic> exts});
} }
class MessageProxyImp implements MessageProxy{ class MessageProxyImp implements MessageProxy{
@override @override
Future<bool> openPage(String pageName, Map params, bool animated) { Future<Map<dynamic,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts}){
return NavigationService.openPage(pageName, params, animated); return NavigationService.openPage(url, urlParams, exts);
} }
@override @override
Future<bool> closePage(String uniqueId, String pageName, Map params, bool animated) { Future<bool> close(String id,{Map<String,dynamic> result,Map<String,dynamic> exts}){
return NavigationService.closePage(uniqueId, pageName, params, animated); return NavigationService.closePage(id,result: result,exts: exts);
} }
} }
...@@ -22,34 +22,21 @@ ...@@ -22,34 +22,21 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
import 'dart:async'; import 'dart:async';
import 'package:xservice_kit/foundation_ext/foundation_ext.dart'; import 'package:flutter/services.dart';
import 'package:xservice_kit/ServiceTemplate.dart';
import 'package:xservice_kit/ServiceGateway.dart';
class NavigationService {
class NavigationService {
static MethodChannel methodChannel;
static final ServiceTemplate _service =
new ServiceTemplate("NavigationService");
static void regsiter() {
ServiceGateway.sharedInstance().registerService(_service);
}
//List event from event channel.
static int listenEvent(void onData(dynamic event)) {
return _service.listenEvent(onData);
}
//Cancel event for subscription with ID.
static void cancelEventForSubscription(int subID) {
_service.cancelEventForSubscription(subID);
}
static Future<bool> onShownContainerChanged(String newName,String oldName,Map params) { static Future<bool> onShownContainerChanged(String newName,String oldName,Map params) {
Map<String,dynamic> properties = new Map<String,dynamic>(); Map<String,dynamic> properties = new Map<String,dynamic>();
properties["newName"]=newName; properties["newName"]=newName;
properties["oldName"]=oldName; properties["oldName"]=oldName;
properties["params"]=params; properties["params"]=params;
return _service.methodChannel().invokeMethod('onShownContainerChanged',properties).then<bool>((value){ return methodChannel.invokeMethod('onShownContainerChanged',properties).then<bool>((value){
return BOOL(value); return (value);
}); });
} }
static Future<bool> onFlutterPageResult(String uniqueId,String key,Map resultData,Map params) { static Future<bool> onFlutterPageResult(String uniqueId,String key,Map resultData,Map params) {
...@@ -58,39 +45,45 @@ ...@@ -58,39 +45,45 @@
properties["key"]=key; properties["key"]=key;
properties["resultData"]=resultData; properties["resultData"]=resultData;
properties["params"]=params; properties["params"]=params;
return _service.methodChannel().invokeMethod('onFlutterPageResult',properties).then<bool>((value){ return methodChannel.invokeMethod('onFlutterPageResult',properties).then<bool>((value){
return BOOL(value); return (value);
}); });
} }
static Future<Map> pageOnStart(Map params) async { static Future<Map> pageOnStart(Map params) async {
Map<String,dynamic> properties = new Map<String,dynamic>(); Map<String,dynamic> properties = new Map<String,dynamic>();
properties["params"]=params; properties["params"]=params;
try { try {
return await _service.methodChannel().invokeMethod('pageOnStart',properties).then<Map>((value){ return await methodChannel.invokeMethod('pageOnStart',properties).then<Map>((value){
return value as Map; return value as Map;
}); });
} catch (e) { } catch (e) {
print('Page on start exception'); print('Page on start exception');
return Future<Map>.value({}); return Future<Map>((){});
} }
} }
static Future<bool> openPage(String pageName,Map params,bool animated) {
static Future<Map<dynamic,dynamic>> openPage(String url,Map urlParams, Map exts) {
Map<String,dynamic> properties = new Map<String,dynamic>(); Map<String,dynamic> properties = new Map<String,dynamic>();
properties["pageName"]=pageName; properties["url"]=url;
properties["params"]=params; properties["urlParams"]=urlParams;
properties["animated"]=animated; properties["exts"]=exts;
return _service.methodChannel().invokeMethod('openPage',properties).then<bool>((value){ return methodChannel.invokeMethod('openPage',properties).then<Map<dynamic,dynamic>>((value){
return BOOL(value); return (value);
}); });
} }
static Future<bool> closePage(String uniqueId,String pageName,Map params,bool animated) {
static Future<bool> closePage(String uniqueId,{Map<String,dynamic> result,Map<String,dynamic> exts}) {
Map<String,dynamic> properties = new Map<String,dynamic>(); Map<String,dynamic> properties = new Map<String,dynamic>();
properties["uniqueId"]=uniqueId; properties["uniqueId"]=uniqueId;
properties["pageName"]=pageName; if(result != null){
properties["params"]=params; properties["result"]=result;
properties["animated"]=animated; }
return _service.methodChannel().invokeMethod('closePage',properties).then<bool>((value){ if(exts != null) {
return BOOL(value); properties["exts"] = exts;
}
return methodChannel.invokeMethod('closePage',properties).then<bool>((value){
return value;
}); });
} }
} }
\ No newline at end of file
...@@ -26,13 +26,10 @@ import 'dart:async'; ...@@ -26,13 +26,10 @@ import 'dart:async';
import 'package:flutter_boost/container/boost_container.dart'; import 'package:flutter_boost/container/boost_container.dart';
import 'package:flutter_boost/flutter_boost.dart'; import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter_boost/messaging/message_proxy.dart'; import 'package:flutter_boost/messaging/message_proxy.dart';
import 'package:flutter_boost/messaging/page_result_mediator.dart';
import 'package:flutter_boost/support/logger.dart'; import 'package:flutter_boost/support/logger.dart';
class Router { class Router {
MessageProxy _msgProxy = MessageProxyImp(); MessageProxy _msgProxy = MessageProxyImp();
PageResultMediator resultMediator = null;
void setMessageProxy(MessageProxy prx) { void setMessageProxy(MessageProxy prx) {
if (prx != null) { if (prx != null) {
...@@ -41,28 +38,15 @@ class Router { ...@@ -41,28 +38,15 @@ class Router {
} }
Future<bool> openPage(String url, Map params, Future<Map<dynamic,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts}){
{bool animated = true, PageResultHandler resultHandler}) { return _msgProxy.open(url,urlParams: urlParams,exts: exts);
if (resultHandler != null) {
String rid = resultMediator.createResultId();
params["result_id"] = rid;
FlutterBoost.singleton.setPageResultHandler(rid,
(String key, Map<dynamic, dynamic> result) {
Logger.log("Recieved result $result for from page key $key");
if (resultHandler != null) {
resultHandler(key, result);
}
});
}
return _msgProxy.openPage(url, params, animated);
} }
Future<bool> closePage(String name, String pageId, Map params, Future<bool> close(String id,{Map<String,dynamic> result,Map<String,dynamic> exts}){
{bool animated = true}) { return _msgProxy.close(id,result:result,exts: exts);
return _msgProxy.closePage(pageId, name, params, animated);
} }
//Close currentPage page. //Close currentPage page.
Future<bool> closeCurPage(Map params) { Future<bool> closeCurPage(Map params) {
BoostContainerSettings settings; BoostContainerSettings settings;
...@@ -87,7 +71,9 @@ class Router { ...@@ -87,7 +71,9 @@ class Router {
animated = params["animated"] as bool; animated = params["animated"] as bool;
} }
return _msgProxy.closePage( Map<String,dynamic> exts = Map();
settings.uniqueId, settings.name, settings.params, animated); exts["animated"] = animated;
return _msgProxy.close(settings.uniqueId,result: {} ,exts: exts);
} }
} }
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