Commit 87532b11 authored by 余玠's avatar 余玠

support external initialized flutter engine

parent be169943
......@@ -35,6 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
- (id<FLBFlutterProvider>)flutterProvider;
- (void)startFlutterWithPlatform:(id<FLBPlatform>)platform
withEngine:(FlutterEngine* _Nullable)engine
onStart:(void (^)(FlutterEngine *engine))callback;
- (FlutterViewController *)flutterViewController;
......
......@@ -26,6 +26,7 @@
#import "FLBPlatform.h"
#import "FLBTypes.h"
NS_ASSUME_NONNULL_BEGIN
@interface FlutterBoostPlugin : NSObject<FlutterPlugin>
#pragma mark - Initializer
+ (instancetype)sharedInstance;
......@@ -38,6 +39,16 @@
*/
- (void)startFlutterWithPlatform:(id<FLBPlatform>)platform
onStart:(void (^)(FlutterEngine *engine))callback;
/**
* 初始化FlutterBoost混合栈环境。应在程序使用混合栈之前调用。如在AppDelegate中
*
* @param platform 平台层实现FLBPlatform的对象
* @param engine 外部实例化engine后传入
* @param callback 启动之后回调
*/
- (void)startFlutterWithPlatform:(id<FLBPlatform>)platform
engine:(FlutterEngine* _Nullable)engine
onStart:(void (^)(FlutterEngine *engine))callback;
#pragma mark - Some properties.
- (BOOL)isRunning;
......@@ -109,3 +120,4 @@
onPageFinished:(void (^)(NSDictionary *))resultCallback
completion:(void (^)(BOOL))completion;
@end
NS_ASSUME_NONNULL_END
......@@ -113,6 +113,13 @@
- (void)startFlutterWithPlatform:(id<FLBPlatform>)platform
onStart:(void (^)(FlutterEngine *engine))callback;
{
[self startFlutterWithPlatform:platform engine:nil onStart:callback];
}
- (void)startFlutterWithPlatform:(id<FLBPlatform>)platform
engine:(FlutterEngine* _Nullable)engine
onStart:(void (^)(FlutterEngine *engine))callback;
{
static dispatch_once_t onceToken;
__weak __typeof__(self) weakSelf = self;
......@@ -121,6 +128,7 @@
self.factory = FLBFactory.new;
self.application = [self->_factory createApplication:platform];
[self.application startFlutterWithPlatform:platform
withEngine:engine
onStart:callback];
});
}
......
......@@ -50,12 +50,13 @@
}
- (void)startFlutterWithPlatform:(id<FLBPlatform>)platform
withEngine:(FlutterEngine* _Nullable)engine
onStart:(void (^)(FlutterEngine *engine))callback
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
self.platform = platform;
self.viewProvider = [[FLBFlutterEngine alloc] initWithPlatform:platform];
self.viewProvider = [[FLBFlutterEngine alloc] initWithPlatform:platform engine:engine];
self.isRunning = YES;
if(callback) callback(self.viewProvider.engine);
});
......
......@@ -28,6 +28,6 @@
NS_ASSUME_NONNULL_BEGIN
@interface FLBFlutterEngine : NSObject<FLBFlutterProvider>
- (instancetype)initWithPlatform:(id<FLBPlatform>_Nullable)platform;
- (instancetype)initWithPlatform:(id<FLBPlatform> _Nullable)platform engine:(FlutterEngine* _Nullable)engine;
@end
NS_ASSUME_NONNULL_END
......@@ -35,13 +35,17 @@
@implementation FLBFlutterEngine
- (instancetype)initWithPlatform:(id<FLBPlatform> _Nullable)platform
- (instancetype)initWithPlatform:(id<FLBPlatform> _Nullable)platform engine:(FlutterEngine * _Nullable)engine
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if (self = [super init]) {
_engine = [[FlutterEngine alloc] initWithName:@"io.flutter" project:nil];
if(!engine){
_engine = [[FlutterEngine alloc] initWithName:@"io.flutter" project:nil];
}else{
_engine = engine;
}
if(platform &&
[platform respondsToSelector: @selector(entryForDart)] &&
platform.entryForDart){
......@@ -69,7 +73,7 @@
- (instancetype)init
{
return [self initWithPlatform:nil];
return [self initWithPlatform:nil engine:nil];
}
- (void)pause
......
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