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

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

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