Skip to content

Commit

Permalink
Merge pull request tidev#5471 from vishalduggal/timob-16628
Browse files Browse the repository at this point in the history
[TIMOB-16628] iOS: Support tintColor of TableViewRow and listItem
  • Loading branch information
srahim committed Mar 17, 2014
2 parents 3ef6c4a + 68fc5fe commit 67b3192
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 18 deletions.
40 changes: 28 additions & 12 deletions iphone/Classes/TiUIListItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,36 @@ -(void) applyBackgroundWithSelectedColor:(id)selectedBackgroundColor selectedIma
}
}

-(BOOL)compareDataItemValue:(NSString*)theKey withItem:(NSDictionary *)otherItem
{
id propertiesValue = [_dataItem objectForKey:@"properties"];
NSDictionary *properties = ([propertiesValue isKindOfClass:[NSDictionary class]]) ? propertiesValue : nil;
id curValue = [properties objectForKey:theKey];

propertiesValue = [otherItem objectForKey:@"properties"];
properties = ([propertiesValue isKindOfClass:[NSDictionary class]]) ? propertiesValue : nil;
id otherValue = [properties objectForKey:theKey];
return ( (curValue == otherValue) || [curValue isEqual:otherValue]);

}

- (BOOL)canApplyDataItem:(NSDictionary *)otherItem;
{
id template = [_dataItem objectForKey:@"template"];
id otherTemplate = [otherItem objectForKey:@"template"];
BOOL same = (template == otherTemplate) || [template isEqual:otherTemplate];
if (same) {
id propertiesValue = [_dataItem objectForKey:@"properties"];
NSDictionary *properties = ([propertiesValue isKindOfClass:[NSDictionary class]]) ? propertiesValue : nil;
id heightValue = [properties objectForKey:@"height"];

propertiesValue = [otherItem objectForKey:@"properties"];
properties = ([propertiesValue isKindOfClass:[NSDictionary class]]) ? propertiesValue : nil;
id otherHeightValue = [properties objectForKey:@"height"];
same = (heightValue == otherHeightValue) || [heightValue isEqual:otherHeightValue];
id template = [_dataItem objectForKey:@"template"];
id otherTemplate = [otherItem objectForKey:@"template"];
BOOL same = (template == otherTemplate) || [template isEqual:otherTemplate];
if (same) {
same = [self compareDataItemValue:@"height" withItem:otherItem];
}
//These properties are applied in willDisplayCell. So force reload.
if (same) {
same = [self compareDataItemValue:@"backgroundColor" withItem:otherItem];
}
if (same) {
same = [self compareDataItemValue:@"backgroundImage" withItem:otherItem];
}
if (same) {
same = [self compareDataItemValue:@"tintColor" withItem:otherItem];
}
return same;
}
Expand Down
21 changes: 16 additions & 5 deletions iphone/Classes/TiUIListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1287,14 +1287,25 @@ - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInte

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (searchActive || (tableView != _tableView)) {
return;
}
//Let the cell configure its background
[(TiUIListItem*)cell configureCellBackground];

//Tell the proxy about the cell to be displayed
[self.listViewProxy willDisplayCell:indexPath];
if ([TiUtils isIOS7OrGreater]) {
NSIndexPath* realPath = [self pathForSearchPath:indexPath];
id tintValue = [self valueWithKey:@"tintColor" atIndexPath:realPath];
UIColor* theTint = [[TiUtils colorValue:tintValue] color];
if (theTint == nil) {
theTint = [tableView tintColor];
}
[cell performSelector:@selector(setTintColor:) withObject:theTint];
}

if (searchActive || (tableView != _tableView)) {
return;
} else {
//Tell the proxy about the cell to be displayed for marker event
[self.listViewProxy willDisplayCell:indexPath];
}
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Expand Down
20 changes: 19 additions & 1 deletion iphone/Classes/TiUITableViewRowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,25 @@ -(void)configureChildren:(UITableViewCell*)cell
configuredChildren = YES;
}

-(void)configureTintColor:(UITableViewCell*)cell
{
if ([TiUtils isIOS7OrGreater]) {
UIColor* theTint = nil;
id theColor = [self valueForUndefinedKey:@"tintColor"];
if (theColor != nil) {
theTint = [[TiUtils colorValue:theColor] color];
}
if (theTint == nil) {
theTint = [[table tableView] tintColor];
}
[cell performSelector:@selector(setTintColor:) withObject:theTint];
}
}

-(void)initializeTableViewCell:(UITableViewCell*)cell
{
modifyingRow = YES;
[self configureTintColor:cell];
[self configureTitle:cell];
[self configureSelectionStyle:cell];
[self configureLeftSide:cell];
Expand Down Expand Up @@ -889,7 +905,7 @@ -(void)propertyChanged:(NSString*)key oldValue:(id)oldValue newValue:(id)newValu
@"title", @"accessibilityLabel", @"backgroundImage",
@"leftImage",@"hasDetail",@"hasCheck",@"hasChild",
@"indentionLevel",@"selectionStyle",@"color",@"selectedColor",
@"height",@"width",@"backgroundColor",@"rightImage",
@"height",@"width",@"backgroundColor",@"rightImage",@"tintColor",
nil];
}

Expand Down Expand Up @@ -918,6 +934,8 @@ -(void)propertyChanged:(NSString*)key oldValue:(id)oldValue newValue:(id)newValu
[self triggerRowUpdate];
} else if ([key isEqualToString:@"accessibilityLabel"]){
callbackCell.accessibilityLabel = [TiUtils stringValue:newValue];
} else if ([key isEqualToString:@"tintColor"]){
[self configureTintColor:callbackCell];
}
}, NO);
}
Expand Down

0 comments on commit 67b3192

Please sign in to comment.