Commit 478803b2 authored by 余玠's avatar 余玠

避免多次调用surfaceUpdate或者反复创建surface

parent 570f4acb
......@@ -81,7 +81,6 @@
- (void)resume
{
[[_engine lifecycleChannel] sendMessage:@"AppLifecycleState.resumed"];
[(FLBFlutterViewContainer *)_engine.viewController surfaceUpdated:YES];
}
- (void)inactive
......@@ -110,6 +109,7 @@
- (void)atacheToViewController:(FlutterViewController *)vc
{
if(_engine.viewController != vc){
[(FLBFlutterViewContainer *)_engine.viewController surfaceUpdated:NO];
_engine.viewController = vc;
}
}
......@@ -123,11 +123,9 @@
- (void)prepareEngineIfNeeded
{
// if ([_dummy respondsToSelector:@selector(setEnableForRunnersBatch:)]) {
// [_dummy setEnableForRunnersBatch:YES];
// }
[self detach];
[_dummy surfaceUpdated:YES];
[(FLBFlutterViewContainer *)_engine.viewController surfaceUpdated:NO];
NSLog(@"[XDEBUG]---surface changed--reset-");
// [self detach];
}
@end
......
......@@ -27,6 +27,8 @@
#import "BoostMessageChannel.h"
#import "FLBFlutterContainerManager.h"
#import "FlutterBoostPlugin_private.h"
#import <objc/message.h>
#import <objc/runtime.h>
#define FLUTTER_APP [FlutterBoostPlugin sharedInstance].application
#define FLUTTER_VIEW FLUTTER_APP.flutterViewController.view
......@@ -137,7 +139,6 @@ static NSUInteger kInstanceCounter = 0;
- (void)attatchFlutterEngine
{
[FLUTTER_APP.flutterProvider prepareEngineIfNeeded];
[FLUTTER_APP.flutterProvider atacheToViewController:self];
}
......@@ -161,16 +162,6 @@ static NSUInteger kInstanceCounter = 0;
- (void)viewWillAppear:(BOOL)animated
{
if([FLUTTER_APP contains:self]){
[self surfaceUpdated:NO];
[self detatchFlutterEngine];
}else{
[self attatchFlutterEngine];
[self surfaceUpdated:YES];
}
[FLUTTER_APP resume];
//For new page we should attach flutter view in view will appear
//for better performance.
......@@ -185,7 +176,13 @@ static NSUInteger kInstanceCounter = 0;
[FlutterBoostPlugin sharedInstance].fParams = _params;
}
[super viewWillAppear:animated];
//instead of calling [super viewWillAppear:animated];, call super's super
struct objc_super target = {
.super_class = class_getSuperclass([FlutterViewController class]),
.receiver = self,
};
NSMethodSignature * (*callSuper)(struct objc_super *, SEL, BOOL animated) = (__typeof__(callSuper))objc_msgSendSuper;
callSuper(&target, @selector(viewWillAppear:), animated);
}
- (void)viewDidAppear:(BOOL)animated
......@@ -194,13 +191,15 @@ static NSUInteger kInstanceCounter = 0;
//Ensure flutter view is attached.
[self attatchFlutterEngine];
[FLUTTER_APP resume];
[BoostMessageChannel didShowPageContainer:^(NSNumber *result) {}
pageName:_name
params:_params
uniqueId:self.uniqueIDString];
//NOTES:务必在show之后再update,否则有闪烁
[self surfaceUpdated:YES];
[super viewDidAppear:animated];
}
......@@ -217,14 +216,17 @@ static NSUInteger kInstanceCounter = 0;
- (void)viewDidDisappear:(BOOL)animated
{
[FLUTTER_APP resume];
[BoostMessageChannel didDisappearPageContainer:^(NSNumber *result) {}
pageName:_name
params:_params
uniqueId:self.uniqueIDString];
[super viewDidDisappear:animated];
[FLUTTER_APP resume];
// instead of calling [super viewDidDisappear:animated];, call super's super
struct objc_super target = {
.super_class = class_getSuperclass([FlutterViewController class]),
.receiver = self,
};
NSMethodSignature * (*callSuper)(struct objc_super *, SEL, BOOL animated) = (__typeof__(callSuper))objc_msgSendSuper;
callSuper(&target, @selector(viewDidDisappear:), animated);
}
- (void)installSplashScreenViewIfNecessary {
......
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