Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-8493]Modify cacheSize to ensure current view isn't detached #2156

Merged
merged 2 commits into from
May 14, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion iphone/Classes/TiUIScrollableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

// See the code for why we need this...
int lastPage;

BOOL enforceCacheRecalculation;
int cacheSize;
}

Expand Down
24 changes: 18 additions & 6 deletions iphone/Classes/TiUIScrollableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,10 @@ -(void)refreshScrollView:(CGRect)visibleBounds readd:(BOOL)readd
-(void)setFrame:(CGRect)frame_
{
lastPage = [self currentPage];
enforceCacheRecalculation = YES;
[super setFrame:frame_];
[self setCurrentPage_:[NSNumber numberWithInt:lastPage]];
[self setCurrentPage_:[NSNumber numberWithInt:lastPage]];
enforceCacheRecalculation = NO;
}

-(void)setBounds:(CGRect)bounds_
Expand Down Expand Up @@ -525,12 +527,22 @@ -(void)scrollViewDidScroll:(UIScrollView *)sender
CGFloat pageWidth = scrollview.frame.size.width;
int page = currentPage;
int nextPage = floor((scrollview.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
if (page != nextPage) {
[pageControl setCurrentPage:nextPage];
currentPage = nextPage;
[self.proxy replaceValue:NUMINT(currentPage) forKey:@"currentPage" notification:NO];
if (page != nextPage) {
int curCacheSize = cacheSize;
int minCacheSize = cacheSize;
if (enforceCacheRecalculation) {
minCacheSize = ABS(page - nextPage)*2 + 1;
if (minCacheSize < cacheSize) {
minCacheSize = cacheSize;
}
}
cacheSize = minCacheSize;
[pageControl setCurrentPage:nextPage];
currentPage = nextPage;
[self.proxy replaceValue:NUMINT(currentPage) forKey:@"currentPage" notification:NO];
[self manageCache:currentPage];
}
cacheSize = curCacheSize;
}
}

-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
Expand Down