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-11510] reproxy subviews of tableview rows when className specified #3260

Merged
merged 3 commits into from
Oct 30, 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
41 changes: 35 additions & 6 deletions iphone/Classes/TiUITableViewRowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,9 @@ -(UIView*)view

- (void)prepareTableRowForReuse
{
if (![self.tableClass isEqualToString:defaultRowTableClass]) {
return;
}
RELEASE_TO_NIL(rowContainerView);

// ... But that's not enough. We need to detatch the views
Expand Down Expand Up @@ -720,26 +723,52 @@ -(void)configureChildren:(UITableViewCell*)cell
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 (!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* subviews = [self children];
for (TiViewProxy *proxy in subviews)
{
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];
if (uiview != nil) {
[uiview transferProxy:proxy deep:YES];
}
[proxy setReproxying:YES];
TiUIView *uiview = [proxy view];
[self redelegateViews:proxy toView:contentView];
[rowContainerView addSubview:uiview];
if (uiview == nil) {
[rowContainerView addSubview:[proxy view]];
}
[proxy setReproxying:NO];
}
}];
}
configuredChildren = YES;
}
Expand Down
10 changes: 9 additions & 1 deletion iphone/Classes/TiUIView.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,16 @@ void ModifyScrollViewForKeyboardHeightAndContentHeightWithResponderRect(UIScroll
/*
Tells the view to change its proxy to the new one provided.
@param newProxy The new proxy to set on the view.
@param deep true for deep transfer
*/
-(void)transferProxy:(TiViewProxy*)newProxy;
-(void)transferProxy:(TiViewProxy*)newProxy deep:(BOOL)deep;

/*
Returns whether the view tree matches proxy tree for later transfer.
@param proxy The proxy to validate view tree with.
@param deep true for deep validation
*/
-(BOOL)validateTransferToProxy:(TiViewProxy*)proxy deep:(BOOL)deep;

/**
Tells the view to update its touch handling state.
Expand Down
37 changes: 36 additions & 1 deletion iphone/Classes/TiUIView.m
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ -(void)setKrollValue:(id)value forKey:(NSString *)key withObject:(id)props
}
}

-(void)transferProxy:(TiViewProxy*)newProxy
-(void)transferProxy:(TiViewProxy*)newProxy deep:(BOOL)deep
{
TiViewProxy * oldProxy = (TiViewProxy *)[self proxy];

Expand Down Expand Up @@ -752,13 +752,48 @@ -(void)transferProxy:(TiViewProxy*)newProxy
[self setKrollValue:newValue forKey:thisKey withObject:nil];
}

if (deep) {
NSArray *subProxies = [newProxy children];
[[oldProxy children] enumerateObjectsUsingBlock:^(TiViewProxy *oldSubProxy, NSUInteger idx, BOOL *stop) {
TiViewProxy *newSubProxy = idx < [subProxies count] ? [subProxies objectAtIndex:idx] : nil;
[[oldSubProxy view] transferProxy:newSubProxy deep:YES];
}];
}
[oldProxy release];

[newProxy setReproxying:NO];
[self release];
}
}

-(BOOL)validateTransferToProxy:(TiViewProxy*)newProxy deep:(BOOL)deep
{
TiViewProxy * oldProxy = (TiViewProxy *)[self proxy];

if (oldProxy == newProxy) {
return YES;
}
if (![newProxy isMemberOfClass:[oldProxy class]]) {
return NO;
}

__block BOOL result = YES;
if (deep) {
NSArray *subProxies = [newProxy children];
NSArray *oldSubProxies = [oldProxy children];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self. We really should consider a childrenCount property to shortcut the copying that would be done here if the counts differ.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BlainHamon these used not only for counts, but actual iterations too.

if ([subProxies count] != [oldSubProxies count]) {
return NO;
}
[oldSubProxies enumerateObjectsUsingBlock:^(TiViewProxy *oldSubProxy, NSUInteger idx, BOOL *stop) {
TiViewProxy *newSubProxy = [subProxies objectAtIndex:idx];
result = [[oldSubProxy view] validateTransferToProxy:newSubProxy deep:YES];
if (!result) {
*stop = YES;
}
}];
}
return result;
}

-(id)proxyValueForKey:(NSString *)key
{
Expand Down