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

Fix cache problems.

parent fc3b7e84
......@@ -39,6 +39,7 @@
@property (nonatomic,strong,readwrite) NSDictionary *params;
@property (nonatomic,strong) UIImageView *screenShotView;
@property (nonatomic,assign) long long identifier;
@property (nonatomic,assign) BOOL interactiveGestureActive;
@end
@implementation FLBFlutterViewContainer
......@@ -241,6 +242,8 @@ static NSUInteger kInstanceCounter = 0;
[self.view insertSubview:FLUTTER_VIEW
atIndex:0];
}
}else{
}
return self.screenShotView.image != nil;
......@@ -262,8 +265,8 @@ static NSUInteger kInstanceCounter = 0;
[self clearCurrentScreenShotImage];
//Remove obsolete screenshot.
[FLBStackCache.sharedInstance remove:self.uniqueIDString];
//Invalidate obsolete screenshot.
[FLBStackCache.sharedInstance invalidate:self.uniqueIDString];
}
#pragma mark - Life circle methods
......@@ -276,6 +279,10 @@ static NSUInteger kInstanceCounter = 0;
- (void)viewWillAppear:(BOOL)animated
{
if(self.navigationController.interactivePopGestureRecognizer.state == UIGestureRecognizerStateBegan){
self.interactiveGestureActive = true;
}
[[FLBFlutterApplication sharedApplication] resume];
//For new page we should attach flutter view in view will appear
//for better performance.
......@@ -319,17 +326,25 @@ static NSUInteger kInstanceCounter = 0;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
(int64_t)(2 * NSEC_PER_SEC)),
dispatch_get_main_queue(),^{
[weakSelf showFlutterView];
if (weakSelf.isViewLoaded && weakSelf.view.window) {
// viewController is visible
[weakSelf showFlutterView];
}
});
self.interactiveGestureActive = NO;
}
- (void)viewWillDisappear:(BOOL)animated
{
//is top.
if([FLUTTER_APP isTop:self.uniqueIDString]
&& self.navigationController.interactivePopGestureRecognizer.state != UIGestureRecognizerStateBegan){
&& self.navigationController.interactivePopGestureRecognizer.state != UIGestureRecognizerStateBegan
&& !self.interactiveGestureActive){
[self saveScreenShot];
}
self.interactiveGestureActive = NO;
self.screenShotView.image = [self getSavedScreenShot];
if(self.screenShotView.image){
......@@ -355,6 +370,7 @@ static NSUInteger kInstanceCounter = 0;
[super viewDidDisappear:animated];
[FLUTTER_APP inactive];
self.interactiveGestureActive = NO;
}
#pragma mark - FLBViewControllerResultHandler
......
......@@ -41,6 +41,12 @@
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
......@@ -56,6 +62,7 @@
#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;
......
......@@ -84,7 +84,7 @@
return;
}
if(!_inMemoryObjectsMap[key]){
if(![_keyStack containsObject:key]){
[_keyStack addObject:key];
}else{
//return;
......@@ -136,6 +136,23 @@
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){
......
......@@ -91,4 +91,26 @@
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
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.
version: 0.0.39
version: 0.0.407
author: Alibaba Xianyu
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