Commit 62f44a98 authored by xuanwu's avatar xuanwu

feat:增加了flutter与iOS原生侧滑冲突的一种解决方案:

	  https://juejin.im/post/5cf8e4b96fb9a07ed440f1d8
parent f4427cf1
......@@ -33,6 +33,7 @@
NavigationService_pageOnStart.register();
NavigationService_openPage.register();
NavigationService_closePage.register();
NavigationService_flutterCanPop.register();
}
}
\ No newline at end of file
package com.taobao.idlefish.flutterboost.NavigationService;
import android.util.Log;
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_flutterCanPop implements MessageHandler<Boolean>{
private Object mContext = null;
private boolean onCall(MessageResult<Boolean> result,Boolean canPop){
return true;
}
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) {
return this.onCall(result,(Boolean) args.get("canPop"));
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("flutterCanPop");
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_flutterCanPop());
}
}
\ No newline at end of file
/Users/jidong/Documents/opensource/flutter_boost
\ No newline at end of file
/Users/zhongchengguo/Desktop/flutter_boost
\ No newline at end of file
/Users/jidong/.pub-cache/hosted/pub.dartlang.org/xservice_kit-0.0.27
\ No newline at end of file
/Users/zhongchengguo/.pub-cache/hosted/pub.flutter-io.cn/xservice_kit-0.0.29
\ No newline at end of file
......@@ -8,20 +8,20 @@ PODS:
DEPENDENCIES:
- Flutter (from `.symlinks/flutter/ios`)
- flutter_boost (from `/Users/jidong/Documents/opensource/flutter_boost/ios`)
- xservice_kit (from `/Users/jidong/.pub-cache/hosted/pub.dartlang.org/xservice_kit-0.0.27/ios`)
- flutter_boost (from `/Users/zhongchengguo/Desktop/flutter_boost/ios`)
- xservice_kit (from `/Users/zhongchengguo/.pub-cache/hosted/pub.flutter-io.cn/xservice_kit-0.0.29/ios`)
EXTERNAL SOURCES:
Flutter:
:path: ".symlinks/flutter/ios"
flutter_boost:
:path: "/Users/jidong/Documents/opensource/flutter_boost/ios"
:path: "/Users/zhongchengguo/Desktop/flutter_boost/ios"
xservice_kit:
:path: "/Users/jidong/.pub-cache/hosted/pub.dartlang.org/xservice_kit-0.0.27/ios"
:path: "/Users/zhongchengguo/.pub-cache/hosted/pub.flutter-io.cn/xservice_kit-0.0.29/ios"
SPEC CHECKSUMS:
Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296
flutter_boost: 24249d12d924d858cf445a84949484bc08bca000
flutter_boost: 6a083f2f1b67f9b08724d6c4b280a099d1b40797
xservice_kit: a86c64372b3e41e7d8e9b1a0b9139866680f525c
PODFILE CHECKSUM: 2a757a7bdc03b37a2814666652fdff1cf694243f
......
......@@ -8,7 +8,6 @@
/* Begin PBXBuildFile section */
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 */; };
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, ); }; };
......@@ -45,7 +44,6 @@
/* Begin PBXFileReference section */
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>"; };
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>"; };
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>"; };
......@@ -105,7 +103,6 @@
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
3B80C3931E831B6300D905FE /* App.framework */,
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
9740EEBA1CF902C7004384FC /* Flutter.framework */,
......@@ -231,7 +228,6 @@
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
......
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "0"
version = "2.0">
</Bucket>
......@@ -52,4 +52,9 @@
[self.navigationController popViewControllerAnimated:animated];
}
}
- (void)flutterCanPop:(BOOL)canpop {
self.navigationController.interactivePopGestureRecognizer.enabled = !canpop;
}
@end
......@@ -33,11 +33,17 @@ class _MyAppState extends State<MyApp> {
FlutterBoost.handleOnStartPage();
}
Map<String, WidgetBuilder> routes = {
"second": (BuildContext context) =>
SecondRouteWidget(),
};
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Boost example',
builder: FlutterBoost.init(postPush: _onRoutePushed),
routes: routes,
home: Container());
}
......
......@@ -12,7 +12,8 @@ class FirstRouteWidget extends StatelessWidget {
child: RaisedButton(
child: Text('Open second route'),
onPressed: () {
FlutterBoost.singleton.openPage("second", {}, animated: true);
Navigator.pushNamed(context, "second");
// FlutterBoost.singleton.openPage("second", {}, animated: true);
},
),
),
......@@ -31,7 +32,8 @@ class SecondRouteWidget extends StatelessWidget {
child: RaisedButton(
onPressed: () {
// Navigate back to first route when tapped.
FlutterBoost.singleton.closePageForContext(context);
Navigator.pop(context);
// FlutterBoost.singleton.closePageForContext(context);
},
child: Text('Go back!'),
),
......
......@@ -32,6 +32,9 @@ NS_ASSUME_NONNULL_BEGIN
//Whether to enable accessibility support. Default value is Yes.
- (BOOL)accessibilityEnable;
// flutter模块是否还可以pop
- (void)flutterCanPop:(BOOL)canpop;
@required
- (void)openPage:(NSString *)name
params:(NSDictionary *)params
......
......@@ -283,6 +283,8 @@ static NSUInteger kInstanceCounter = 0;
//Invalidate obsolete screenshot.
[FLBStackCache.sharedInstance invalidate:self.uniqueIDString];
[Service_NavigationService canPopPageName:_name params:_params
uniqueId:[self uniqueIDString]];
}
#pragma mark - Life circle methods
......
//
// NavigationService_canPop.h
// flutter_boost
//
// Created by ZhongCheng Guo on 2019/6/5.
//
#import "FlutterServiceCallHandler.h"
NS_ASSUME_NONNULL_BEGIN
@interface NavigationService_flutterCanPop : FlutterServiceCallHandler
@end
NS_ASSUME_NONNULL_END
//
// NavigationService_canPop.m
// flutter_boost
//
// Created by ZhongCheng Guo on 2019/6/5.
//
#import "NavigationService_flutterCanPop.h"
#import "ServiceGateway.h"
#import "FLBFlutterApplication.h"
#import "FlutterBoostConfig.h"
@implementation NavigationService_flutterCanPop
- (void)onCall:(void (^)(BOOL))result
canPop:(BOOL)canPop
{
//Add your handler code here!
if ([[FLBFlutterApplication sharedApplication].platform respondsToSelector:@selector(flutterCanPop:)]) {
[[FLBFlutterApplication sharedApplication].platform flutterCanPop:canPop];
}
}
#pragma mark - Do not edit these method.
- (void)__flutter_p_handler_flutterCanPop:(NSDictionary *)args result:(void (^)(BOOL))result {
[self onCall:result canPop:[args[@"canPop"] boolValue]];
}
+ (void)load{
[[ServiceGateway sharedInstance] registerHandler:[NavigationService_flutterCanPop new]];
}
- (NSString *)service
{
return @"NavigationService";
}
@end
......@@ -34,4 +34,6 @@
+ (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)willDeallocPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId;
// 获取flutter的canPop
+ (void)canPopPageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId;
@end
......@@ -137,5 +137,13 @@
}];
}
+ (void)canPopPageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId{
NSMutableDictionary *tmp = [NSMutableDictionary dictionary];
if(pageName) tmp[@"pageName"] = pageName;
if(params) tmp[@"params"] = params;
if(uniqueId) tmp[@"uniqueId"] = uniqueId;
[self.service invoke:@"canPop" args:tmp result:^(id tTesult) {
}];
}
@end
import 'dart:async';
import 'package:flutter/material.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';
import 'package:flutter_boost/AIOService/NavigationService/service/NavigationService.dart';
class NavigationService_canPop extends ServiceCallHandler {
static void regsiter() {
ServiceGateway.sharedInstance()
.registerHandler(new NavigationService_canPop());
}
@override
String name() {
return "canPop";
}
@override
String service() {
return "NavigationService";
}
@override
Future<bool> onMethodCall(MethodCall call) {
return onCall(call.arguments["pageName"], call.arguments["params"],
call.arguments["uniqueId"]);
}
//==============================================Do not edit code above!
Future<bool> onCall(String pageName, Map params, String uniqueId) async {
NavigatorState navigator = FlutterBoost.containerManager.onstageContainer;
bool canPop = navigator.canPop();
NavigationService.flutterCanPop(canPop);
return true;
}
}
\ No newline at end of file
......@@ -93,4 +93,10 @@
return BOOL(value);
});
}
/// 通知原生模块flutter是否可以pop
static void flutterCanPop(bool canPop) {
Map<String,dynamic> properties = new Map<String,dynamic>();
properties["canPop"]=canPop;
_service.methodChannel().invokeMethod('flutterCanPop',properties);
}
}
\ No newline at end of file
......@@ -30,6 +30,7 @@
import '../handlers/NavigationService_didDisappearPageContainer.dart';
import '../handlers/NavigationService_didInitPageContainer.dart';
import '../handlers/NavigationService_willDeallocPageContainer.dart';
import '../handlers/NavigationService_canPop.dart';
class NavigationServiceRegister{
......@@ -43,6 +44,7 @@
NavigationService_didDisappearPageContainer.regsiter();
NavigationService_didInitPageContainer.regsiter();
NavigationService_willDeallocPageContainer.regsiter();
NavigationService_canPop.regsiter();
}
}
\ No newline at end of file
......@@ -28,6 +28,7 @@ import 'package:flutter_boost/container/boost_container.dart';
import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter_boost/support/logger.dart';
import 'package:flutter_boost/container/navigator_observer.dart';
enum ContainerOperation { Push, Onstage, Pop, Remove }
......@@ -100,6 +101,8 @@ class ContainerManagerState extends State<BoostContainerManager> {
assert(widget.initNavigator != null);
_onstage = BoostContainer.copy(widget.initNavigator);
FlutterBoost.containerManager.navigatorObserver.addBoostNavigatorObserver(NavigatorCanPopObserver());
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {});
});
......
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