Commit 67f132b9 authored by Jidong Chen's avatar Jidong Chen

Fix cache problems.

parent fc3b7e84
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
@property (nonatomic,strong,readwrite) NSDictionary *params; @property (nonatomic,strong,readwrite) NSDictionary *params;
@property (nonatomic,strong) UIImageView *screenShotView; @property (nonatomic,strong) UIImageView *screenShotView;
@property (nonatomic,assign) long long identifier; @property (nonatomic,assign) long long identifier;
@property (nonatomic,assign) BOOL interactiveGestureActive;
@end @end
@implementation FLBFlutterViewContainer @implementation FLBFlutterViewContainer
...@@ -241,6 +242,8 @@ static NSUInteger kInstanceCounter = 0; ...@@ -241,6 +242,8 @@ static NSUInteger kInstanceCounter = 0;
[self.view insertSubview:FLUTTER_VIEW [self.view insertSubview:FLUTTER_VIEW
atIndex:0]; atIndex:0];
} }
}else{
} }
return self.screenShotView.image != nil; return self.screenShotView.image != nil;
...@@ -262,8 +265,8 @@ static NSUInteger kInstanceCounter = 0; ...@@ -262,8 +265,8 @@ static NSUInteger kInstanceCounter = 0;
[self clearCurrentScreenShotImage]; [self clearCurrentScreenShotImage];
//Remove obsolete screenshot. //Invalidate obsolete screenshot.
[FLBStackCache.sharedInstance remove:self.uniqueIDString]; [FLBStackCache.sharedInstance invalidate:self.uniqueIDString];
} }
#pragma mark - Life circle methods #pragma mark - Life circle methods
...@@ -276,6 +279,10 @@ static NSUInteger kInstanceCounter = 0; ...@@ -276,6 +279,10 @@ static NSUInteger kInstanceCounter = 0;
- (void)viewWillAppear:(BOOL)animated - (void)viewWillAppear:(BOOL)animated
{ {
if(self.navigationController.interactivePopGestureRecognizer.state == UIGestureRecognizerStateBegan){
self.interactiveGestureActive = true;
}
[[FLBFlutterApplication sharedApplication] resume]; [[FLBFlutterApplication sharedApplication] 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.
...@@ -319,17 +326,25 @@ static NSUInteger kInstanceCounter = 0; ...@@ -319,17 +326,25 @@ static NSUInteger kInstanceCounter = 0;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
(int64_t)(2 * NSEC_PER_SEC)), (int64_t)(2 * NSEC_PER_SEC)),
dispatch_get_main_queue(),^{ dispatch_get_main_queue(),^{
[weakSelf showFlutterView]; if (weakSelf.isViewLoaded && weakSelf.view.window) {
// viewController is visible
[weakSelf showFlutterView];
}
}); });
self.interactiveGestureActive = NO;
} }
- (void)viewWillDisappear:(BOOL)animated - (void)viewWillDisappear:(BOOL)animated
{ {
//is top. //is top.
if([FLUTTER_APP isTop:self.uniqueIDString] if([FLUTTER_APP isTop:self.uniqueIDString]
&& self.navigationController.interactivePopGestureRecognizer.state != UIGestureRecognizerStateBegan){ && self.navigationController.interactivePopGestureRecognizer.state != UIGestureRecognizerStateBegan
&& !self.interactiveGestureActive){
[self saveScreenShot]; [self saveScreenShot];
} }
self.interactiveGestureActive = NO;
self.screenShotView.image = [self getSavedScreenShot]; self.screenShotView.image = [self getSavedScreenShot];
if(self.screenShotView.image){ if(self.screenShotView.image){
...@@ -355,6 +370,7 @@ static NSUInteger kInstanceCounter = 0; ...@@ -355,6 +370,7 @@ static NSUInteger kInstanceCounter = 0;
[super viewDidDisappear:animated]; [super viewDidDisappear:animated];
[FLUTTER_APP inactive]; [FLUTTER_APP inactive];
self.interactiveGestureActive = NO;
} }
#pragma mark - FLBViewControllerResultHandler #pragma mark - FLBViewControllerResultHandler
......
...@@ -41,6 +41,12 @@ ...@@ -41,6 +41,12 @@
cache:(FLBStackCache *)cache cache:(FLBStackCache *)cache
completion:(void (^)(NSError *err ,id<FLBStackCacheObject>))completion; 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 @end
...@@ -56,6 +62,7 @@ ...@@ -56,6 +62,7 @@
#pragma mark - basic operations. #pragma mark - basic operations.
- (void)pushObject:(id<FLBStackCacheObject>)obj key:(NSString *)key; - (void)pushObject:(id<FLBStackCacheObject>)obj key:(NSString *)key;
- (id<FLBStackCacheObject>)remove:(NSString *)key; - (id<FLBStackCacheObject>)remove:(NSString *)key;
- (void)invalidate:(NSString *)key;
- (BOOL)empty; - (BOOL)empty;
- (void)clear; - (void)clear;
- (id<FLBStackCacheObject>)objectForKey:(NSString *)key; - (id<FLBStackCacheObject>)objectForKey:(NSString *)key;
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
return; return;
} }
if(!_inMemoryObjectsMap[key]){ if(![_keyStack containsObject:key]){
[_keyStack addObject:key]; [_keyStack addObject:key];
}else{ }else{
//return; //return;
...@@ -136,6 +136,23 @@ ...@@ -136,6 +136,23 @@
return ob; 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 - (void)preloadIfNeeded
{ {
for(NSString *key in self.keyStack.reverseObjectEnumerator){ for(NSString *key in self.keyStack.reverseObjectEnumerator){
......
...@@ -91,4 +91,26 @@ ...@@ -91,4 +91,26 @@
return YES; 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 @end
name: flutter_boost name: flutter_boost
description: A next-generation Flutter-Native hybrid solution. FlutterBoost is a Flutter plugin which enables hybrid integration of Flutter for your existing native apps with minimum efforts. description: A next-generation Flutter-Native hybrid solution. FlutterBoost is a Flutter plugin which enables hybrid integration of Flutter for your existing native apps with minimum efforts.
version: 0.0.39 version: 0.0.407
author: Alibaba Xianyu author: Alibaba Xianyu
homepage: https://github.com/alibaba/flutter_boost homepage: https://github.com/alibaba/flutter_boost
......
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