Commit 50e7acc7 authored by Jidong Chen's avatar Jidong Chen

refactory to support co-existing of flutter_boost and flutter_boost2

parent cffd24e3
/*
* 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 "FLBFlutterApplicationInterface.h"
NS_ASSUME_NONNULL_BEGIN
@interface FLBFlutterApplication : NSObject<FLBFlutterApplicationInterface>
@property (nonatomic,strong) id<FLB2Platform> platform;
@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.
*/
#import "FLBFlutterApplication.h"
#import "FlutterBoost.h"
#import "FLBFlutterContainerManager.h"
#import "FLBViewProviderFactory.h"
@interface FLBFlutterApplication()
@property (nonatomic,strong) FLBFlutterContainerManager *manager;
@property (nonatomic,strong) id<FLBFlutterViewProvider> viewProvider;
@property (nonatomic,assign) BOOL isRendering;
@property (nonatomic,assign) BOOL isRunning;
@end
@implementation FLBFlutterApplication
- (BOOL)isRunning
{
return _isRunning;
}
- (void)startFlutterWithPlatform:(id<FLB2Platform>)platform onStart:(void (^)(id<FlutterBinaryMessenger,FlutterTextureRegistry,FlutterPluginRegistry> _Nonnull))callback
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
self.platform = platform;
self.viewProvider = [[FLBViewProviderFactory new] createViewProviderWithPlatform:platform];
[self.viewProvider resume];
self.isRendering = YES;
self.isRunning = YES;
if(callback) callback(self.viewProvider.viewController);
});
}
- (instancetype)init
{
if (self = [super init]) {
_manager = [FLBFlutterContainerManager new];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (UIView *)flutterView
{
return [self flutterViewController].view;
}
- (FlutterViewController *)flutterViewController
{
return self.viewProvider.viewController;
}
- (BOOL)contains:(id<FLBFlutterContainer>)vc
{
return [_manager contains:vc];
}
- (void)addUniqueViewController:(id<FLBFlutterContainer>)vc
{
return [_manager addUnique:vc];
}
- (void)removeViewController:(id<FLBFlutterContainer>)vc
{
return [_manager remove:vc];
}
- (BOOL)isTop:(NSString *)pageId
{
return [_manager.peak isEqual:pageId];
}
- (void)pause
{
if(!_isRendering) return;
[self.viewProvider pause];
_isRendering = NO;
}
- (void)resume
{
if(_isRendering) return;
[self.viewProvider resume];
_isRendering = YES;
}
- (void)inactive
{
[self.viewProvider inactive];
}
- (id<FLB2FlutterProvider>)flutterProvider
{
return (id)_viewProvider;
}
- (void)close:(NSString *)uid
result:(NSDictionary *)result
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion
{
BOOL animated = YES;
if([exts[@"animated"] boolValue]){
animated = [exts[@"animated"] boolValue];
}
[self.platform closePage:uid
animated:animated
params:exts[@"params"]
completion:completion];
}
- (void)open:(NSString *)url
urlParams:(NSDictionary *)urlParams
exts:(NSDictionary *)exts
reult:(void (^)(NSDictionary *))resultCallback
completion:(void (^)(BOOL))completion
{
BOOL animated = YES;
if([exts[@"animated"] boolValue]){
animated = [exts[@"animated"] boolValue];
}
[self.platform openPage:url
params:urlParams
animated:animated
completion:completion];
}
- (void)didInitPageContainer:(NSString *)url
params:(NSDictionary *)urlParams
uniqueId:(NSString *)uniqueId
{
}
- (void)willDeallocPageContainer:(NSString *)url
params:(NSDictionary *)params
uniqueId:(NSString *)uniqueId
{
}
@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 "FLBFlutterViewProvider.h"
#import "FLBPlatform.h"
NS_ASSUME_NONNULL_BEGIN
@interface FLBFlutterEngineOld : NSObject<FLBFlutterViewProvider>
- (instancetype)initWithPlatform:(id<FLBPlatform>)platform;
@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.
*/
#import "FLBFlutterEngineOld.h"
#import "FLBFlutterViewControllerAdaptor.h"
#import <objc/runtime.h>
@interface FLBFlutterEngineOld()
@property (nonatomic,strong) FLBFlutterViewControllerAdaptor *viewController;
@end
@implementation FLBFlutterEngineOld
- (instancetype)initWithPlatform:(id<FLBPlatform>)platform
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if (self = [super init]) {
Class class = [FLBFlutterViewControllerAdaptor class];
SEL originalSelector = @selector(onAccessibilityStatusChanged:);
SEL swizzledSelector = @selector(fixed_onAccessibilityStatusChanged:);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
method_exchangeImplementations(originalMethod, swizzledMethod);
_viewController = [FLBFlutterViewControllerAdaptor new];
[_viewController view];
Class clazz = NSClassFromString(@"GeneratedPluginRegistrant");
if (clazz) {
if ([clazz respondsToSelector:NSSelectorFromString(@"registerWithRegistry:")]) {
[clazz performSelector:NSSelectorFromString(@"registerWithRegistry:")
withObject:_viewController];
}
}
}
return self;
#pragma clang diagnostic pop
}
- (FlutterViewController *)viewController
{
return _viewController;
}
- (void)pause
{
[self.viewController boost_viewWillDisappear:NO];
[self.viewController boost_viewDidDisappear:NO];
}
- (void)resume
{
[self.viewController boost_viewWillAppear:NO];
[self.viewController boost_viewDidAppear:NO];
}
- (void)inactive
{
NSString *channel = @"flutter/lifecycle";
NSString *message = @"AppLifecycleState.inactive";
NSData *data = [[FlutterStringCodec sharedInstance] encode:message];
[self.viewController sendOnChannel:channel message:data];
}
- (void)resumeFlutterOnly
{
NSString *channel = @"flutter/lifecycle";
NSString *message = @"AppLifecycleState.resumed";
NSData *data = [[FlutterStringCodec sharedInstance] encode:message];
[self.viewController sendOnChannel:channel message:data];
}
@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>
@class FlutterViewController;
NS_ASSUME_NONNULL_BEGIN
#define RELEASE_1_0 0
@protocol FLBFlutterViewProvider <NSObject>
@required
- (FlutterViewController *)viewController;
- (void)pause;
- (void)resume;
- (void)inactive;
@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.
*/
#import <UIKit/UIKit.h>
#import "FLBFlutterContainer.h"
NS_ASSUME_NONNULL_BEGIN
@interface FLBFlutterViewContainer : UIViewController<FLBFlutterContainer>
@end
NS_ASSUME_NONNULL_END
This diff is collapsed.
/*
* 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 <Flutter/Flutter.h>
NS_ASSUME_NONNULL_BEGIN
@interface FLBFlutterViewControllerAdaptor : FlutterViewController
- (void)boost_viewWillAppear:(BOOL)animated;
- (void)boost_viewDidAppear:(BOOL)animated;
- (void)boost_viewWillDisappear:(BOOL)animated;
- (void)boost_viewDidDisappear:(BOOL)animated;
@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.
*/
#import "FLBFlutterViewControllerAdaptor.h"
#import <objc/runtime.h>
@interface FLBFlutterViewControllerAdaptor ()
@end
@implementation FLBFlutterViewControllerAdaptor
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
// Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated
{
//Left blank intentionally.
}
- (void)viewDidAppear:(BOOL)animated
{
//Left blank intentionally.
}
- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
//Avoid super call intentionally.
}
- (void)viewDidDisappear:(BOOL)animated
{
//Avoid super call intentionally.
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
}
- (void)boost_viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)boost_viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)boost_viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)boost_viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (UIEdgeInsets)paddingEdgeInsets{
UIEdgeInsets edgeInsets = UIEdgeInsetsZero;
if (@available(iOS 11, *)) {
edgeInsets = UIEdgeInsetsMake(0, self.view.safeAreaInsets.left, self.view.safeAreaInsets.bottom, self.view.safeAreaInsets.right);
} else {
edgeInsets = UIEdgeInsetsZero;
}
return edgeInsets;
}
- (void)installSplashScreenViewIfNecessary {
//Override this to avoid unnecessary splash Screen.
}
@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>
@class FlutterViewController;
NS_ASSUME_NONNULL_BEGIN
#define RELEASE_1_0 0
@protocol FLBFlutterViewProvider <NSObject>
@required
- (FlutterViewController *)viewController;
- (void)pause;
- (void)resume;
- (void)inactive;
@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.
*/
#import <Foundation/Foundation.h>
#import "FLBFlutterViewProvider.h"
#import "FLBPlatform.h"
NS_ASSUME_NONNULL_BEGIN
@interface FLBViewProviderFactory : NSObject
- (id<FLBFlutterViewProvider>)createViewProvider;
- (id<FLBFlutterViewProvider>)createViewProviderWithPlatform:(id<FLBPlatform>)platform;
@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.
*/
#import "FLBViewProviderFactory.h"
#import "FLBFlutterEngineOld.h"
#import "FLBPlatform.h"
@implementation FLBViewProviderFactory
- (id<FLBFlutterViewProvider>)createViewProviderWithPlatform:(id<FLBPlatform>)platform
{
return [[FLBFlutterEngineOld alloc] initWithPlatform:platform];
}
- (id<FLBFlutterViewProvider>)createViewProvider
{
return [FLBFlutterEngineOld new];
}
@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.
*/
NS_ASSUME_NONNULL_BEGIN
@interface FlutterBoostConfig : NSObject
#pragma mark - Store first open page
//There are some cases first page messages could be lost.
//So we store the first page info for later usage.
+ (instancetype)sharedInstance;
@property (nonatomic,copy) NSString *fPagename;
@property (nonatomic,copy) NSString *fPageId;
@property (nonatomic,strong) NSDictionary *fParams;
- (BOOL)firstView;
@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.
*/
#import "FlutterBoostConfig.h"
@interface FlutterBoostConfig()
@property (nonatomic,assign) BOOL firstView;
@end
@implementation FlutterBoostConfig
+ (instancetype)sharedInstance
{
static FlutterBoostConfig *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [self new];
instance.firstView = YES;
});
return instance;
}
- (void)setFPageId:(NSString *)fPageId
{
_fPageId = fPageId;
_firstView = NO;
}
- (BOOL)firstView
{
return _firstView;
}
@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>
@class FLBStackCache;
@protocol FLBStackCacheObject<NSObject>
@required
@property (nonatomic,copy) NSString *key;
- (BOOL)writeToFileWithKey:(NSString *)key
queue:(dispatch_queue_t)queue
cache:(FLBStackCache *)cache
completion:(void (^)(NSError *err,NSString *path))completion;
+ (BOOL)loadFromFileWithKey:(NSString *)key
queue:(dispatch_queue_t)queue
cache:(FLBStackCache *)cache
completion:(void (^)(NSError *err ,id<FLBStackCacheObject>))completion;
- (BOOL)removeCachedFileWithKey:(NSString *)key
queue:(dispatch_queue_t)queue
cache:(FLBStackCache *)cache
completion:(void (^)(NSError *, NSString *))completion;
@end
@interface FLBStackCache : NSObject
+ (instancetype)sharedInstance;
/**
* Num of objects allowed in memory.
* Default value is set to 2.
*/
@property (nonatomic,assign) NSUInteger inMemoryCount;
#pragma mark - basic operations.
- (void)pushObject:(id<FLBStackCacheObject>)obj key:(NSString *)key;
- (id<FLBStackCacheObject>)remove:(NSString *)key;
- (void)invalidate:(NSString *)key;
- (BOOL)empty;
- (void)clear;
- (id<FLBStackCacheObject>)objectForKey:(NSString *)key;
#pragma mark - Disk thing.
- (NSString *)cacheDir;
@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 "FLBStackCache.h"
@interface FLBStackCache()
@property (nonatomic,strong) NSMutableArray *keyStack;
@property (nonatomic,strong) NSMutableDictionary *typesMap;
@property (nonatomic,strong) NSMutableDictionary *inMemoryObjectsMap;
@property (nonatomic,strong) NSMutableDictionary *loadinMap;
@property (nonatomic,strong) dispatch_queue_t queueIO;
@end
@implementation FLBStackCache
+ (instancetype)sharedInstance
{
static id sInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sInstance = [self.class new];
});
return sInstance;
}
- (BOOL)empty
{
return _keyStack.count<=0;
}
- (void)clear
{
[self.keyStack removeAllObjects];
[self.inMemoryObjectsMap removeAllObjects];
[self.typesMap removeAllObjects];
NSError *err = nil;
[[NSFileManager defaultManager] removeItemAtPath:self.cacheDir error:&err];
if (err) {
NSLog(@"fail to remove cache dir %@",err);
}
}
- (instancetype)init
{
if (self = [super init]) {
_keyStack = [NSMutableArray new];
_inMemoryObjectsMap = [NSMutableDictionary new];
_loadinMap = [NSMutableDictionary new];
_typesMap = [NSMutableDictionary new];
_queueIO = dispatch_queue_create("Stack cache working queue", NULL);
}
_inMemoryCount = 2;
return self;
}
- (void)pushObject:(id<FLBStackCacheObject>)obj
key:(NSString *)key
{
if (!obj || key.length <= 0) {
return;
}
if(![_keyStack containsObject:key]){
[_keyStack addObject:key];
}else{
//return;
}
obj.key = key;
_typesMap[key] = obj.class;
_inMemoryObjectsMap[key] = obj;
for(NSUInteger i = _keyStack.count - _inMemoryObjectsMap.count ;
i < _keyStack.count && _inMemoryObjectsMap.count > _inMemoryCount;
i++){
NSString *keyToSave = _keyStack[i];
if(_inMemoryObjectsMap[keyToSave]){
id<FLBStackCacheObject> ob = _inMemoryObjectsMap[keyToSave];
[_inMemoryObjectsMap removeObjectForKey:keyToSave];
[ob writeToFileWithKey:keyToSave
queue:_queueIO
cache:self
completion:^(NSError *err, NSString *path) {
if (err) {
NSLog(@"Caching object to file failed!");
}
}];
}
}
}
- (id<FLBStackCacheObject>)objectForKey:(NSString *)key
{
return _inMemoryObjectsMap[key];
}
- (id<FLBStackCacheObject>)remove:(NSString *)key
{
if([self empty]) return nil;
if(![_keyStack containsObject:key]) return nil;
id ob = _inMemoryObjectsMap[key];
[_keyStack removeObject:key];
[_inMemoryObjectsMap removeObjectForKey:key];
[_typesMap removeObjectForKey:key];
[self preloadIfNeeded];
return ob;
}
- (void)invalidate:(NSString *)key
{
if(!key || [self empty]) return;
if(![_keyStack containsObject:key]) return;
id<FLBStackCacheObject> ob = _inMemoryObjectsMap[key];
[ob removeCachedFileWithKey:key
queue:_queueIO
cache:self
completion:^(NSError *err, NSString *k) {
}];
[_inMemoryObjectsMap removeObjectForKey:key];
[self preloadIfNeeded];
}
- (void)preloadIfNeeded
{
for(NSString *key in self.keyStack.reverseObjectEnumerator){
Class typeClass = _typesMap[key];
id cache = _inMemoryObjectsMap[key];
if(typeClass && !cache && [typeClass conformsToProtocol: @protocol(FLBStackCacheObject)]){
_loadinMap[key] = @(YES);
[typeClass loadFromFileWithKey:key
queue:_queueIO
cache:self
completion:^(NSError *err ,id<FLBStackCacheObject> ob){
[self.loadinMap removeObjectForKey:key];
if (ob && !err) {
if(self.typesMap[key]){
self.inMemoryObjectsMap[key] = ob;
}
}else{
NSLog(@"preload object from file failed!");
}
}];
}
if(_inMemoryObjectsMap.count + _loadinMap.count >= _inMemoryCount){
break;
}
}
}
- (NSString *)cacheDir
{
static NSString *cachePath = nil;
if (!cachePath) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cacheDirectory = [paths objectAtIndex:0];
cachePath = [cacheDirectory stringByAppendingPathComponent:@"FlutterScreenshots"];
}
BOOL dir = NO;
if(![[NSFileManager defaultManager] fileExistsAtPath:cachePath isDirectory:&dir]){
NSError *eror = nil;
[[NSFileManager defaultManager] createDirectoryAtPath:cachePath
withIntermediateDirectories:YES
attributes:nil
error:&eror];
if (eror) {
NSLog(@"%@",eror);
}
}
return cachePath;
}
@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 "FLBStackCache.h"
@interface FLBStackCacheObjectImg : NSObject<FLBStackCacheObject>
@property (nonatomic,copy) NSString *key;
- (instancetype)initWithImage:(UIImage *)image;
- (UIImage *)image;
@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 "FLBStackCacheObjectImg.h"
@interface FLBStackCacheObjectImg()
@property (nonatomic,strong) UIImage *image;
@end
@implementation FLBStackCacheObjectImg
- (instancetype)initWithImage:(UIImage *)image
{
if (self = [super init]) {
_image = image;
}
return self;
}
+ (BOOL)loadFromFileWithKey:(NSString *)key
queue:(dispatch_queue_t)queue
cache:(FLBStackCache *)cache
completion:(void (^)(NSError *, id<FLBStackCacheObject>))completion
{
dispatch_async(queue, ^{
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[self filePathByKey:key dirPath:cache.cacheDir]];
if (completion) {
if (image) {
FLBStackCacheObjectImg *ob = [[FLBStackCacheObjectImg alloc] initWithImage:image];
ob.key = key;
completion(nil,ob);
}else{
completion([NSError new],nil);
}
}
});
return YES;
}
+ (NSString *)filePathByKey:(NSString *)key dirPath:(NSString *)cacheDir
{
key = [key stringByReplacingOccurrencesOfString:@"/" withString:@""];
key = [key stringByReplacingOccurrencesOfString:@":" withString:@""];
NSString *path = [cacheDir stringByAppendingPathComponent:key];
return path;
}
- (BOOL)writeToFileWithKey:(NSString *)key
queue:(dispatch_queue_t)queue
cache:(FLBStackCache *)cache
completion:(void (^)(NSError *, NSString *))completion
{
if(!_image){
return NO;
}
dispatch_async(queue, ^{
NSData *imgData = UIImagePNGRepresentation(self.image);
NSString *filePath = [FLBStackCacheObjectImg filePathByKey:key dirPath:cache.cacheDir];
[imgData writeToFile:filePath atomically:YES];
if (completion) {
completion(nil,key);
}
});
return YES;
}
- (BOOL)removeCachedFileWithKey:(NSString *)key
queue:(dispatch_queue_t)queue
cache:(FLBStackCache *)cache
completion:(void (^)(NSError *, NSString *))completion
{
if(!key){
return NO;
}
dispatch_async(queue, ^{
NSString *filePath = [FLBStackCacheObjectImg filePathByKey:key dirPath:cache.cacheDir];
NSError *err = nil;
[NSFileManager.defaultManager removeItemAtPath:filePath error:&err];
if (completion) {
completion(err,key);
}
});
return YES;
}
@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>
#define kFLBMemoryInspectorChangedNotification @"__FlutterMemoryInspectorChangedNotification__"
#define kFLBMemoryInspectorKeyCondition @"condition"
typedef NS_ENUM(NSUInteger,FLBMemoryCondition) {
FLBMemoryConditionUnknown,
FLBMemoryConditionNormal,
FLBMemoryConditionLowMemory,
FLBMemoryConditionExtremelyLow,
FLBMemoryConditionAboutToDie
};
@interface FLBMemoryInspector : NSObject
+ (instancetype)sharedInstance;
- (FLBMemoryCondition)currentCondition;
- (int64_t)currentFootPrint;
- (int64_t)deviceMemory;
- (BOOL)smallMemoryDevice;
@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 "FLBMemoryInspector.h"
#include <mach/mach.h>
#include <stdlib.h>
#include <sys/sysctl.h>
#define MB(_v_) (_v_*1024*1024)
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
@interface FLBMemoryInspector()
@property(nonatomic,assign) FLBMemoryCondition condition;
@end
@implementation FLBMemoryInspector
+ (instancetype)sharedInstance
{
static id sInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sInstance = [[self.class alloc] init];
});
return sInstance;
}
static bool isHighterThanIos9(){
bool ret = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0.0");
return ret;
}
static int64_t memoryFootprint()
{
task_vm_info_data_t vmInfo;
mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
kern_return_t result = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count);
if (result != KERN_SUCCESS)
return -1;
return vmInfo.phys_footprint;
}
static int64_t _memoryWarningLimit()
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine =(char *) malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
if ([platform isEqualToString:@"iPhone5,1"]) return MB(600);
if ([platform isEqualToString:@"iPhone5,2"]) return MB(600);
if ([platform isEqualToString:@"iPhone5,3"]) return MB(600);
if ([platform isEqualToString:@"iPhone5,4"]) return MB(600);
if ([platform isEqualToString:@"iPhone6,1"]) return MB(600);
if ([platform isEqualToString:@"iPhone6,2"]) return MB(600);
if ([platform isEqualToString:@"iPhone7,1"]) return MB(600);
if ([platform isEqualToString:@"iPhone7,2"]) return MB(600);
if ([platform isEqualToString:@"iPhone8,1"]) return MB(1280);
if ([platform isEqualToString:@"iPhone8,2"]) return MB(1280);
if ([platform isEqualToString:@"iPhone8,4"]) return MB(1280);
if ([platform isEqualToString:@"iPhone9,1"]) return MB(1280);
if ([platform isEqualToString:@"iPhone9,2"]) return MB(1950);
if ([platform isEqualToString:@"iPhone9,3"]) return MB(1280);
if ([platform isEqualToString:@"iPhone9,4"]) return MB(1950);
if ([platform isEqualToString:@"iPhone10,1"]) return MB(1280);
if ([platform isEqualToString:@"iPhone10,2"]) return MB(1950);
if ([platform isEqualToString:@"iPhone10,3"]) return MB(1950);
if ([platform isEqualToString:@"iPhone10,4"]) return MB(1280);
if ([platform isEqualToString:@"iPhone10,5"]) return MB(1950);
if ([platform isEqualToString:@"iPhone10,6"]) return MB(1950);
return 0;
}
static int64_t getLimit(){
const static size_t l = _memoryWarningLimit();
return l;
}
- (int64_t)deviceMemory
{
int64_t size = [NSProcessInfo processInfo].physicalMemory;
return size;
}
- (BOOL)smallMemoryDevice
{
if([self deviceMemory] <= MB(1024)){
return YES;
}else{
return NO;
}
}
- (FLBMemoryCondition)currentCondition
{
FLBMemoryCondition newCondition = FLBMemoryConditionUnknown;
if(!isHighterThanIos9() || getLimit() <= 0){
newCondition = FLBMemoryConditionUnknown;
}else if(memoryFootprint() < getLimit() * 0.40){
newCondition = FLBMemoryConditionNormal;
}else if(memoryFootprint() < getLimit() * 0.60){
newCondition = FLBMemoryConditionLowMemory;
}else if(memoryFootprint() < getLimit() * 0.80){
newCondition = FLBMemoryConditionExtremelyLow;
}else{
newCondition = FLBMemoryConditionAboutToDie;
}
if (newCondition != self.condition) {
[[NSNotificationCenter defaultCenter] postNotificationName:kFLBMemoryInspectorChangedNotification
object:@{kFLBMemoryInspectorKeyCondition:@(newCondition)}];
}
self.condition = newCondition;
return newCondition;
}
- (int64_t)currentFootPrint
{
return memoryFootprint();
}
@end
......@@ -25,7 +25,6 @@
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
#import "FLB2Platform.h"
#import "FlutterBoost.h"
#import "FLB2FlutterProvider.h"
#import "FLBFlutterApplicationInterface.h"
......
......@@ -23,17 +23,14 @@
*/
#import "FLB2FlutterApplication.h"
#import "FlutterBoost.h"
#import "FLBFlutterContainerManager.h"
#import "FlutterBoost2.h"
#import "FLB2FlutterContainerManager.h"
#import "FLB2FlutterEngine.h"
@interface FLB2FlutterApplication()
@property (nonatomic,strong) FLBFlutterContainerManager *manager;
@property (nonatomic,strong) FLB2FlutterContainerManager *manager;
@property (nonatomic,strong) id<FLB2FlutterProvider> viewProvider;
@property (nonatomic,assign) BOOL isRunning;
@property (nonatomic,strong) NSMutableDictionary *pageResultCallbacks;
@property (nonatomic,strong) NSMutableDictionary *callbackCache;
@end
......@@ -76,7 +73,7 @@
- (instancetype)init
{
if (self = [super init]) {
_manager = [FLBFlutterContainerManager new];
_manager = [FLB2FlutterContainerManager new];
_pageResultCallbacks = NSMutableDictionary.new;
_callbackCache = NSMutableDictionary.new;
}
......
......@@ -25,10 +25,10 @@
#import "FLB2FlutterViewContainer.h"
#import "FLB2FlutterApplication.h"
#import "BoostMessageChannel.h"
#import "FLBFlutterContainerManager.h"
#import "FlutterBoostPlugin_private.h"
#import "FLB2FlutterContainerManager.h"
#import "FlutterBoostPlugin2_private.h"
#define FLUTTER_APP [FlutterBoostPlugin sharedInstance].application
#define FLUTTER_APP [FlutterBoostPlugin2 sharedInstance].application
#define FLUTTER_VIEW FLUTTER_APP.flutterViewController.view
#define FLUTTER_VC FLUTTER_APP.flutterViewController
......@@ -174,10 +174,10 @@ static NSUInteger kInstanceCounter = 0;
params:_params
uniqueId:self.uniqueIDString];
//Save some first time page info.
if(![FlutterBoostPlugin sharedInstance].fPagename){
[FlutterBoostPlugin sharedInstance].fPagename = _name;
[FlutterBoostPlugin sharedInstance].fPageId = self.uniqueIDString;
[FlutterBoostPlugin sharedInstance].fParams = _params;
if(![FlutterBoostPlugin2 sharedInstance].fPagename){
[FlutterBoostPlugin2 sharedInstance].fPagename = _name;
[FlutterBoostPlugin2 sharedInstance].fPageId = self.uniqueIDString;
[FlutterBoostPlugin2 sharedInstance].fParams = _params;
}
[super viewWillAppear:animated];
......
......@@ -21,14 +21,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
#import "FLBAbstractFactory.h"
#import <Flutter/Flutter.h>
NS_ASSUME_NONNULL_BEGIN
@interface FLBFactory : NSObject<FLBAbstractFactory>
@interface BoostChannel : NSObject<FlutterPlugin>
@end
......
......@@ -21,22 +21,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "BoostChannel.h"
#import "FlutterBoost2.h"
#import "FLBFactory.h"
#import "FLBFlutterViewContainer.h"
#import "FLBFlutterApplication.h"
@implementation FLBFactory
- (id<FLBFlutterApplicationInterface>)createApplication:(id<FLB2Platform>)platform
{
return FLBFlutterApplication.new;
@implementation BoostChannel
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
[FlutterBoostPlugin2 registerWithRegistrar:registrar];
}
- (id<FLBFlutterContainer>)createFlutterContainer
{
return FLBFlutterViewContainer.new;
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
[FlutterBoostPlugin2.sharedInstance handleMethodCall:call result:result];
}
@end
......@@ -25,7 +25,7 @@
#import <Flutter/Flutter.h>
NS_ASSUME_NONNULL_BEGIN
@interface FLBFlutterAppDelegate : FlutterAppDelegate
@interface FLB2FlutterAppDelegate : FlutterAppDelegate
// Returns the key window's rootViewController, if it's a FlutterViewController.
// Otherwise, returns nil.
- (FlutterViewController*)rootFlutterViewController;
......
......@@ -22,13 +22,13 @@
* THE SOFTWARE.
*/
#import "FLBFlutterAppDelegate.h"
#import "FlutterBoostPlugin_private.h"
#import "FLB2FlutterAppDelegate.h"
#import "FlutterBoostPlugin2_private.h"
@implementation FLBFlutterAppDelegate
@implementation FLB2FlutterAppDelegate
// Returns the key window's rootViewController, if it's a FlutterViewController.
// Otherwise, returns nil.
- (FlutterViewController*)rootFlutterViewController {
return FlutterBoostPlugin.sharedInstance.application.flutterViewController;
return FlutterBoostPlugin2.sharedInstance.application.flutterViewController;
}
@end
......@@ -26,7 +26,7 @@
#import "FLBFlutterContainer.h"
NS_ASSUME_NONNULL_BEGIN
@interface FLBFlutterContainerManager : NSObject
@interface FLB2FlutterContainerManager : NSObject
- (NSString *)peak;
- (void)addUnique:(id<FLBFlutterContainer>)vc;
......
......@@ -22,14 +22,14 @@
* THE SOFTWARE.
*/
#import "FLBFlutterContainerManager.h"
#import "FLB2FlutterContainerManager.h"
@interface FLBFlutterContainerManager()
@interface FLB2FlutterContainerManager()
@property (nonatomic,strong) NSMutableArray *idStk;
@property (nonatomic,strong) NSMutableDictionary *existedID;
@end
@implementation FLBFlutterContainerManager
@implementation FLB2FlutterContainerManager
- (instancetype)init
{
......
......@@ -23,17 +23,19 @@
*/
#import <Foundation/Foundation.h>
#import "FLBFlutterViewProvider.h"
@class FlutterViewController;
@class FlutterEngine;
NS_ASSUME_NONNULL_BEGIN
@protocol FLB2FlutterProvider <FLBFlutterViewProvider>
@protocol FLB2FlutterProvider <NSObject>
@required
- (FlutterEngine *)engine;
- (void)atacheToViewController:(FlutterViewController *)vc;
- (void)detach;
- (void)prepareEngineIfNeeded;
- (void)pause;
- (void)resume;
- (void)inactive;
@end
NS_ASSUME_NONNULL_END
......@@ -23,13 +23,9 @@
*/
#import <Foundation/Foundation.h>
#import "FLBPlatform.h"
NS_ASSUME_NONNULL_BEGIN
@protocol FLB2Platform <FLBPlatform>
@optional
- (BOOL)useBoost2;
@protocol FLB2Platform <NSObject>
@required
- (void)open:(NSString *)url
urlParams:(NSDictionary *)urlParams
......
......@@ -24,7 +24,7 @@
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
#import "FLB2Platform.h"
#import "FlutterBoost.h"
#import "FlutterBoost2.h"
#import "FLB2FlutterProvider.h"
#import "FLBFlutterContainer.h"
......
......@@ -21,8 +21,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
......
/*
* 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>
NS_ASSUME_NONNULL_BEGIN
@protocol FLBPlatform <NSObject>
@required
- (void)openPage:(NSString *)name
params:(NSDictionary *)params
animated:(BOOL)animated
completion:(void (^)(BOOL finished))completion;
- (void)closePage:(NSString *)uid
animated:(BOOL)animated
params:(NSDictionary *)params
completion:(void (^)(BOOL finished))completion;
@end
NS_ASSUME_NONNULL_END
......@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
#ifndef FLBTypes_h
#define FLBTypes_h
......
......@@ -25,11 +25,9 @@
#ifndef FlutterBoost_h
#define FlutterBoost_h
#import "FlutterBoostPlugin.h"
#import "FLBFlutterAppDelegate.h"
#import "FLBFlutterViewContainer.h"
#import "FLBPlatform.h"
#import "FlutterBoostPlugin2.h"
#import "FLB2FlutterAppDelegate.h"
#import "FLB2FlutterViewContainer.h"
#import "FLB2Platform.h"
#import "FLBTypes.h"
#endif /* FlutterBoost_h */
......@@ -26,7 +26,7 @@
#import "FLB2Platform.h"
#import "FLBTypes.h"
@interface FlutterBoostPlugin : NSObject<FlutterPlugin>
@interface FlutterBoostPlugin2 : NSObject<FlutterPlugin>
#pragma mark - Initializer
+ (instancetype)sharedInstance;
......
......@@ -22,25 +22,23 @@
* THE SOFTWARE.
*/
#import "FlutterBoostPlugin.h"
#import "FlutterBoostPlugin_private.h"
#import "FLBFactory.h"
#import "FlutterBoostPlugin2.h"
#import "FlutterBoostPlugin2_private.h"
#import "FLB2Factory.h"
#import "BoostMessageChannel.h"
#import "FlutterBoostPlugin_private.h"
#define NSNull2Nil(_x_) if([_x_ isKindOfClass: NSNull.class]) _x_ = nil;
@interface FlutterBoostPlugin()
@interface FlutterBoostPlugin2()
@end
@implementation FlutterBoostPlugin
@implementation FlutterBoostPlugin2
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"flutter_boost"
binaryMessenger:[registrar messenger]];
FlutterBoostPlugin* instance = [self.class sharedInstance];
FlutterBoostPlugin2* instance = [self.class sharedInstance];
instance.methodChannel = channel;
[registrar addMethodCallDelegate:instance channel:channel];
}
......@@ -58,7 +56,7 @@
NSNull2Nil(exts);
NSNull2Nil(resultData);
NSNull2Nil(uid);
[[FlutterBoostPlugin sharedInstance].application close:uid
[[FlutterBoostPlugin2 sharedInstance].application close:uid
result:resultData
exts:exts
completion:^(BOOL r){
......@@ -78,16 +76,16 @@
NSNull2Nil(url);
NSNull2Nil(urlParams);
NSNull2Nil(exts);
[[FlutterBoostPlugin sharedInstance].application open:url
[[FlutterBoostPlugin2 sharedInstance].application open:url
urlParams:urlParams
exts:exts
reult:result
completion:^(BOOL r) {}];
}else if([@"pageOnStart" isEqualToString:call.method]){
NSMutableDictionary *pageInfo = [NSMutableDictionary new];
pageInfo[@"name"] =[FlutterBoostPlugin sharedInstance].fPagename;
pageInfo[@"params"] = [FlutterBoostPlugin sharedInstance].fParams;
pageInfo[@"uniqueId"] = [FlutterBoostPlugin sharedInstance].fPageId;
pageInfo[@"name"] =[FlutterBoostPlugin2 sharedInstance].fPagename;
pageInfo[@"params"] = [FlutterBoostPlugin2 sharedInstance].fParams;
pageInfo[@"uniqueId"] = [FlutterBoostPlugin2 sharedInstance].fPageId;
if(result) result(pageInfo);
}else{
result(FlutterMethodNotImplemented);
......@@ -125,11 +123,7 @@
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if([platform respondsToSelector:@selector(useBoost2)] && platform.useBoost2){
self->_factory = FLB2Factory.new;
}else{
self->_factory = FLBFactory.new;
}
self->_application = [self->_factory createApplication:platform];
[self->_application startFlutterWithPlatform:platform
onStart:callback];
......
......@@ -25,8 +25,8 @@
#import "FLBFlutterApplicationInterface.h"
#import "FLBAbstractFactory.h"
@interface FlutterBoostPlugin(){
#import "FlutterBoostPlugin2.h"
@interface FlutterBoostPlugin2(){
id<FLBFlutterApplicationInterface> _application;
id<FLBAbstractFactory> _factory;
}
......
......@@ -22,7 +22,7 @@
* THE SOFTWARE.
*/
#import "BoostMessageChannel.h"
#import "FlutterBoostPlugin_private.h"
#import "FlutterBoostPlugin2_private.h"
@implementation BoostMessageChannel
......@@ -37,7 +37,7 @@
+ (FlutterMethodChannel *)methodChannel
{
return FlutterBoostPlugin.sharedInstance.methodChannel;
return FlutterBoostPlugin2.sharedInstance.methodChannel;
}
+ (void)sendEvent:(NSString *)eventName
......@@ -162,7 +162,7 @@
}
}];
[FlutterBoostPlugin.sharedInstance.application didInitPageContainer:pageName
[FlutterBoostPlugin2.sharedInstance.application didInitPageContainer:pageName
params:params
uniqueId:uniqueId];
}
......@@ -179,7 +179,7 @@
}
}];
[FlutterBoostPlugin.sharedInstance.application willDeallocPageContainer:pageName
[FlutterBoostPlugin2.sharedInstance.application willDeallocPageContainer:pageName
params:params
uniqueId:uniqueId];
}
......
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'flutter_boost2'
s.version = '0.0.1'
s.summary = 'A new Flutter plugin make flutter better to use!'
s.description = <<-DESC
A new Flutter plugin make flutter better to use!
DESC
s.homepage = 'http://example.com'
s.license = { :file => '../LICENSE.md' }
s.author = { 'Alibaba Xianyu' => 'email@example.com' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*.{h,m,mm}'
s.public_header_files =
'Classes/Boost/FlutterBoostPlugin2.h',
'Classes/Boost/FLB2Platform.h',
'Classes/Boost/FLBFlutterContainer.h',
'Classes/Boost/FLB2FlutterAppDelegate.h',
'Classes/Boost/FLBTypes.h',
'Classes/Boost/FlutterBoost2.h',
'Classes/Boost/BoostChannel.h',
'Classes/1.5/FLB2FlutterViewContainer.h'
s.dependency 'Flutter'
s.libraries = 'c++'
s.ios.deployment_target = '8.0'
end
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