Commit fae46f29 authored by Jidong Chen's avatar Jidong Chen

ios open close opt

parent b393b000
......@@ -20,7 +20,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296
flutter_boost: a018687cd20f74f410a6ab17bd33187f5f31f8fd
flutter_boost: e6949ea7bf22ad0766867b631996c2a7afa1a710
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 */,
......@@ -232,7 +229,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;
......
......@@ -8,11 +8,11 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <flutter_boost/FLBPlatform.h>
#import <flutter_boost/FlutterBoost.h>
NS_ASSUME_NONNULL_BEGIN
@interface DemoRouter : NSObject<FLBPlatform>
@interface DemoRouter : NSObject<FLB2Platform>
@property (nonatomic,strong) UINavigationController *navigationController;
......
......@@ -21,11 +21,64 @@
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
params:(NSDictionary *)params
animated:(BOOL)animated
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]){
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
[vc setName:name params:params];
......@@ -40,14 +93,19 @@
}
}
- (BOOL)accessibilityEnable
{
return YES;
}
- (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;
if([vc isKindOfClass:FLBFlutterViewContainer.class] && [vc.uniqueIDString isEqual: uid]){
[vc dismissViewControllerAnimated:animated completion:^{}];
......
......@@ -27,8 +27,6 @@
- (IBAction)pushFlutterPage:(id)sender {
[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 {
child: Text('Open second route'),
onPressed: () {
FlutterBoost.singleton.openPage("second", {}, animated: true, resultHandler:(String key , Map<dynamic,dynamic> result){
print("did recieve second route result $key $result");
print("open second page!");
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 {
BoostContainerSettings settings = BoostContainer.of(context).settings;
if(settings.params.containsKey("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!'),
),
),
);
......
......@@ -154,4 +154,18 @@
completion:completion];
}
- (void)didInitPageContainer:(NSString *)url
params:(NSDictionary *)urlParams
uniqueId:(NSString *)uniqueId
{
}
- (void)willDeallocPageContainer:(NSString *)url
params:(NSDictionary *)params
uniqueId:(NSString *)uniqueId
{
}
@end
......@@ -391,15 +391,5 @@ static NSUInteger kInstanceCounter = 0;
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
......@@ -32,6 +32,10 @@
@property (nonatomic,strong) id<FLB2FlutterProvider> viewProvider;
@property (nonatomic,assign) BOOL isRunning;
@property (nonatomic,strong) NSMutableDictionary *pageResultCallbacks;
@property (nonatomic,strong) NSMutableDictionary *callbackCache;
@end
......@@ -73,6 +77,8 @@
{
if (self = [super init]) {
_manager = [FLBFlutterContainerManager new];
_pageResultCallbacks = NSMutableDictionary.new;
_callbackCache = NSMutableDictionary.new;
}
return self;
}
......@@ -129,19 +135,66 @@
return self.flutterProvider.engine.viewController;
}
- (void)close:(NSString *)uid
- (void)close:(NSString *)uniqueId
result:(NSDictionary *)result
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion{
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{
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
......@@ -35,7 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
@required
- (void)open:(NSString *)url
urlParams:(NSDictionary *)urlParams
exts:(BOOL)animated
exts:(NSDictionary *)exts
completion:(void (^)(BOOL finished))completion;
- (void)close:(NSString *)uid
......
......@@ -56,7 +56,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)inactive;
- (BOOL)isRunning;
#pragma mark - handle close/open messages
#pragma mark - handle messages
- (void)close:(NSString *)uid
result:(NSDictionary *)result
......@@ -69,6 +69,15 @@ NS_ASSUME_NONNULL_BEGIN
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
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,7 +24,7 @@
#import <Flutter/Flutter.h>
#import "FLB2Platform.h"
#import "FLBBroadcastor.h"
#import "FLBTypes.h"
@interface FlutterBoostPlugin : NSObject<FlutterPlugin>
......
......@@ -25,6 +25,7 @@
#import "FLBFlutterApplicationInterface.h"
#import "FLBAbstractFactory.h"
#import "FLBBroadcastor.h"
@interface FlutterBoostPlugin(){
id<FLBFlutterApplicationInterface> _application;
......@@ -39,4 +40,5 @@
@property (nonatomic,copy) NSString *fPageId;
@property (nonatomic,copy) NSString *fPagename;
@property (nonatomic,strong) NSDictionary *fParams;
@end
......@@ -111,6 +111,10 @@
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
......@@ -124,6 +128,10 @@
result(tTesult);
}
}];
[FlutterBoostPlugin.sharedInstance.application willDeallocPageContainer:pageName
params:params
uniqueId:uniqueId];
}
......
......@@ -25,13 +25,10 @@
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
#import "FLBTypes.h"
NS_ASSUME_NONNULL_BEGIN
typedef void (^FLBEventListener) (NSString *name ,
NSDictionary *arguments);
typedef void (^FLBVoidCallback)(void);
@interface FLBBroadcastor : NSObject
- (instancetype)initWithMethodChannel:(FlutterMethodChannel *)channel;
......
......@@ -21,7 +21,7 @@ A new Flutter plugin make flutter better to use!
'Classes/Boost/FLB2Platform.h',
'Classes/Boost/FLBFlutterContainer.h',
'Classes/Boost/FLBFlutterAppDelegate.h',
'Classes/Boost/FLBBroadcastor.h',
'Classes/Boost/FLBTypes.h',
'Classes/1.0/FLBFlutterViewContainer.h',
'Classes/1.5/FLB2FlutterViewContainer.h'
......
......@@ -27,7 +27,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_boost/messaging/service/navigation_service.dart';
import 'package:flutter_boost/container/boost_container.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 'container/container_coordinator.dart';
......@@ -64,6 +63,8 @@ class FlutterBoost {
final MethodChannel _methodChannel = MethodChannel('flutter_boost');
final MessageDispatcher _dispatcher = MessageDispatcher();
int _callbackID = 0;
Broadcastor _broadcastor;
static FlutterBoost get singleton => _instance;
......@@ -131,11 +132,25 @@ class FlutterBoost {
ContainerCoordinator.singleton.registerPageBuilders(builders);
}
Future<Map<String,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts}){
Future<Map<dynamic,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts}){
if(urlParams == null) {
urlParams = Map();
}
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);
}
......@@ -149,10 +164,12 @@ class FlutterBoost {
_broadcastor.sendEvent(name, arguments);
}
Future<bool> openPage(String name, Map params,{bool animated}) {
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);
}
......@@ -163,9 +180,11 @@ class FlutterBoost {
Map<String,dynamic> exts = Map();
if(animated != null){
exts["animated"] = animated;
}else{
exts["animated"] = true;
}
if(name != null){
if(url != null){
exts["url"] = url;
}
......
......@@ -25,20 +25,20 @@ import 'package:flutter_boost/messaging/service/navigation_service.dart';
import 'dart:async';
abstract class MessageProxy{
Future<Map<String,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts});
void close(String id,{Map<String,dynamic> result,Map<String,dynamic> exts});
Future<Map<dynamic,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts});
Future<bool> close(String id,{Map<String,dynamic> result,Map<String,dynamic> exts});
}
class MessageProxyImp implements MessageProxy{
@override
Future<Map<String,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts}){
Future<Map<dynamic,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts}){
return NavigationService.openPage(url, urlParams, exts);
}
@override
void close(String id,{Map<String,dynamic> result,Map<String,dynamic> exts}){
return NavigationService.closePage(uniqueId,result: result,exts: exts);
Future<bool> close(String id,{Map<String,dynamic> result,Map<String,dynamic> exts}){
return NavigationService.closePage(id,result: result,exts: exts);
}
......
......@@ -62,12 +62,12 @@ class NavigationService {
}
}
static Future<Map<String,dynamic>> openPage(String url,Map urlParams, Map exts) {
static Future<Map<dynamic,dynamic>> openPage(String url,Map urlParams, Map exts) {
Map<String,dynamic> properties = new Map<String,dynamic>();
properties["url"]=url;
properties["urlParams"]=params;
properties["urlParams"]=urlParams;
properties["exts"]=exts;
return methodChannel.invokeMethod('openPage',properties).then<Map<String,dynamic>>((value){
return methodChannel.invokeMethod('openPage',properties).then<Map<dynamic,dynamic>>((value){
return (value);
});
}
......
......@@ -26,7 +26,6 @@ import 'dart:async';
import 'package:flutter_boost/container/boost_container.dart';
import 'package:flutter_boost/flutter_boost.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';
class Router {
......@@ -39,7 +38,7 @@ class Router {
}
Future<Map<String,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts}){
Future<Map<dynamic,dynamic>> open(String url,{Map<String,dynamic> urlParams,Map<String,dynamic> exts}){
return _msgProxy.open(url,urlParams: urlParams,exts: exts);
}
......@@ -75,6 +74,6 @@ class Router {
Map<String,dynamic> exts = Map();
exts["animated"] = animated;
return _msgProxy.close(id,result: {} ,exts: exts);
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