Permalink
Browse files

Merge pull request #3424 from mstepanov/timob-11760

[TIMOB-11760] Make TableViewRow reuse conditional
  • Loading branch information...
2 parents 4b933d4 + 0ce81dd commit 30d1747da93ddfb8cf2364280017867cc2bb895c @vishalduggal vishalduggal committed Nov 20, 2012
Showing with 71 additions and 49 deletions.
  1. +1 −0 iphone/Classes/TiUITableViewRowProxy.h
  2. +70 −49 iphone/Classes/TiUITableViewRowProxy.m
@@ -43,6 +43,7 @@ typedef enum
#pragma mark Public APIs
@property(nonatomic,readonly) NSString *tableClass;
+@property(nonatomic, readwrite) BOOL reusable;
#pragma mark Framework
@@ -255,6 +255,7 @@ - (void) dealloc
@implementation TiUITableViewRowProxy
@synthesize tableClass, table, section, row, callbackCell;
+@synthesize reusable;
-(NSString *)className
{
@@ -649,7 +650,7 @@ -(UIView *)parentViewForChild:(TiViewProxy *)child
-(BOOL)viewAttached
{
- return rowContainerView != nil;
+ return callbackCell != nil;
}
-(BOOL)canHaveControllerParent
@@ -679,6 +680,10 @@ -(UIView*)view
- (void)prepareTableRowForReuse
{
+ if (!self.reusable) {
+ [rowContainerView removeFromSuperview];
+ return;
+ }
if (![self.tableClass isEqualToString:defaultRowTableClass]) {
return;
}
@@ -691,6 +696,18 @@ - (void)prepareTableRowForReuse
}
}
+- (void)didReceiveMemoryWarning:(NSNotification *)notification
+{
+ if (self.viewAttached) {
+ return;
+ }
+
+ RELEASE_TO_NIL(rowContainerView);
+ for (TiViewProxy* child in [self children]) {
+ [child detachView];
+ }
+}
+
-(void)configureChildren:(UITableViewCell*)cell
{
// this method is called when the cell is initially created
@@ -716,59 +733,63 @@ -(void)configureChildren:(UITableViewCell*)cell
[contentView setFrame:rect];
}
rect.origin = CGPointZero;
- RELEASE_TO_NIL(rowContainerView);
- for (UIView* subview in [[cell contentView] subviews]) {
- if ([subview isKindOfClass:[TiUITableViewRowContainer class]]) {
- rowContainerView = [subview retain];
- break;
- }
- }
- NSArray *rowChildren = [self children];
- if (rowContainerView != nil) {
- __block BOOL canReproxy = YES;
- NSArray *existingSubviews = [rowContainerView subviews];
- if ([rowChildren count] != [existingSubviews count]) {
- canReproxy = NO;
- } else {
- [rowChildren enumerateObjectsUsingBlock:^(TiViewProxy *proxy, NSUInteger idx, BOOL *stop) {
- TiUIView *uiview = [existingSubviews objectAtIndex:idx];
- if (![uiview validateTransferToProxy:proxy deep:YES]) {
- canReproxy = NO;
- *stop = YES;
+ if (self.reusable || (rowContainerView == nil)) {
+ if (self.reusable) {
+ RELEASE_TO_NIL(rowContainerView);
+ for (UIView* subview in [[cell contentView] subviews]) {
+ if ([subview isKindOfClass:[TiUITableViewRowContainer class]]) {
+ rowContainerView = [subview retain];
+ break;
}
- }];
+ }
}
- if (!canReproxy) {
- DebugLog(@"[ERROR] TableViewRow structures for className %@ does not match", self.tableClass);
- [existingSubviews enumerateObjectsUsingBlock:^(TiUIView *child, NSUInteger idx, BOOL *stop) {
- [(TiViewProxy *)child.proxy detachView];
- }];
+ NSArray *rowChildren = [self children];
+ if (self.reusable && (rowContainerView != nil)) {
+ __block BOOL canReproxy = YES;
+ NSArray *existingSubviews = [rowContainerView subviews];
+ if ([rowChildren count] != [existingSubviews count]) {
+ canReproxy = NO;
+ } else {
+ [rowChildren enumerateObjectsUsingBlock:^(TiViewProxy *proxy, NSUInteger idx, BOOL *stop) {
+ TiUIView *uiview = [existingSubviews objectAtIndex:idx];
+ if (![uiview validateTransferToProxy:proxy deep:YES]) {
+ canReproxy = NO;
+ *stop = YES;
+ }
+ }];
+ }
+ if (!canReproxy) {
+ DebugLog(@"[ERROR] TableViewRow structures for className %@ does not match", self.tableClass);
+ [existingSubviews enumerateObjectsUsingBlock:^(TiUIView *child, NSUInteger idx, BOOL *stop) {
+ [(TiViewProxy *)child.proxy detachView];
+ }];
+ }
}
- }
- if (rowContainerView == nil) {
- rowContainerView = [[TiUITableViewRowContainer alloc] initWithFrame:rect];
- [contentView addSubview:rowContainerView];
- }
- [rowContainerView setBackgroundColor:[UIColor clearColor]];
- [rowContainerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
-
- NSArray *existingSubviews = [rowContainerView subviews];
- [rowChildren enumerateObjectsUsingBlock:^(TiViewProxy *proxy, NSUInteger idx, BOOL *stop) {
- TiUIView *uiview = idx < [existingSubviews count] ? [existingSubviews objectAtIndex:idx] : nil;
- if (!CGRectEqualToRect([proxy sandboxBounds], rect)) {
- [proxy setSandboxBounds:rect];
+ if (rowContainerView == nil) {
+ rowContainerView = [[TiUITableViewRowContainer alloc] initWithFrame:rect];
+ [contentView addSubview:rowContainerView];
}
- [proxy windowWillOpen];
- if (uiview != nil) {
+ [rowContainerView setBackgroundColor:[UIColor clearColor]];
+ [rowContainerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
+
+ NSArray *existingSubviews = [rowContainerView subviews];
+ [rowChildren enumerateObjectsUsingBlock:^(TiViewProxy *proxy, NSUInteger idx, BOOL *stop) {
+ TiUIView *uiview = idx < [existingSubviews count] ? [existingSubviews objectAtIndex:idx] : nil;
+ if (!CGRectEqualToRect([proxy sandboxBounds], rect)) {
+ [proxy setSandboxBounds:rect];
+ }
+ [proxy windowWillOpen];
[uiview transferProxy:proxy deep:YES];
- }
- [proxy setReproxying:YES];
- [self redelegateViews:proxy toView:contentView];
- if (uiview == nil) {
- [rowContainerView addSubview:[proxy view]];
- }
- [proxy setReproxying:NO];
- }];
+ [proxy setReproxying:YES];
+ [self redelegateViews:proxy toView:contentView];
+ if (uiview == nil) {
+ [rowContainerView addSubview:[proxy view]];
+ }
+ [proxy setReproxying:NO];
+ }];
+ } else {
+ [contentView addSubview:rowContainerView];
+ }
}
configuredChildren = YES;
}

0 comments on commit 30d1747

Please sign in to comment.