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-16628] iOS: Support tintColor of TableViewRow and listItem #5471

Merged
merged 3 commits into from
Mar 17, 2014
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
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