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-15291] Check proxy for background configuration #4729

Merged
merged 2 commits into from
Sep 26, 2013
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
133 changes: 76 additions & 57 deletions iphone/Classes/TiUIListItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,59 +207,10 @@ -(void)setPosition:(int)position isGrouped:(BOOL)grouped
_grouped = grouped;
}

-(void) applyBackgroundWithColor:(id)backgroundColor image:(id)backgroundImage selectedColor:(id)selectedBackgroundColor selectedImage:(id)selectedBackgroundImage
-(void) applyBackgroundWithSelectedColor:(id)selectedBackgroundColor selectedImage:(id)selectedBackgroundImage
{
UIColor* bgColor = (backgroundColor != nil) ? ([[TiUtils colorValue:backgroundColor] _color]) : nil;
UIColor* sbgColor = (selectedBackgroundColor != nil) ? ([[TiUtils colorValue:selectedBackgroundColor] _color]) : nil;
UIImage *bgImage = [[ImageLoader sharedLoader] loadImmediateStretchableImage:[TiUtils toURL:backgroundImage proxy:_proxy] withLeftCap:TiDimensionAuto topCap:TiDimensionAuto];
UIImage *sbgImage = [[ImageLoader sharedLoader] loadImmediateStretchableImage:[TiUtils toURL:selectedBackgroundImage proxy:_proxy] withLeftCap:TiDimensionAuto topCap:TiDimensionAuto];

if (_grouped && ![TiUtils isIOS7OrGreater]) {
//Setting the backgroundView on grouped style is a little complicated
//By default this is not nil. So we will add the stuff as subviews to this
//ios7 does not seem to have a backgroundView for style grouped.
UIView* superView = [self backgroundView];
if (bgImage != nil) {
if (![_bgView isKindOfClass:[UIImageView class]]) {
[_bgView removeFromSuperview];
RELEASE_TO_NIL(_bgView);
_bgView = [[UIImageView alloc] initWithFrame:CGRectZero];
_bgView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[superView addSubview:_bgView];
}
[(UIImageView*)_bgView setImage:bgImage];
[_bgView setBackgroundColor:((bgColor == nil) ? [UIColor clearColor] : bgColor)];
} else {
[_bgView removeFromSuperview];
RELEASE_TO_NIL(_bgView);
}
} else {
if (bgImage != nil) {
//Set the backgroundView to ImageView and set its backgroundColor to bgColor
if ([self.backgroundView isKindOfClass:[UIImageView class]]) {
[(UIImageView*)self.backgroundView setImage:bgImage];
[(UIImageView*)self.backgroundView setBackgroundColor:((bgColor == nil) ? [UIColor clearColor] : bgColor)];
} else {
UIImageView *view_ = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease];
[view_ setImage:bgImage];
[view_ setBackgroundColor:((bgColor == nil) ? [UIColor clearColor] : bgColor)];
self.backgroundView = view_;
}
} else {
if (bgColor != nil) {
if (![self.backgroundView isKindOfClass:[TiSelectedCellBackgroundView class]]) {
self.backgroundView = [[[TiSelectedCellBackgroundView alloc] initWithFrame:CGRectZero] autorelease];
}
TiSelectedCellBackgroundView *bgView = (TiSelectedCellBackgroundView*)self.backgroundView;
bgView.grouped = _grouped;
bgView.fillColor = bgColor;
[bgView setPosition:_positionMask];
} else {
self.backgroundView = nil;
}
}
}

if (sbgImage != nil) {
if ([self.selectedBackgroundView isKindOfClass:[UIImageView class]]) {
[(UIImageView*)self.selectedBackgroundView setImage:sbgImage];
Expand Down Expand Up @@ -311,17 +262,75 @@ - (void)configureCellBackground
{
//Ensure that we store the default backgroundColor
if ([_initialValues objectForKey:@"backgroundColor"] == nil) {
id initialValue = [self backgroundColor];
id initialValue = nil;
if (_templateStyle == TiUIListItemTemplateStyleCustom) {
initialValue = [[TiUtils colorValue:[_proxy valueForKey:@"backgroundColor"]] color];
}
if (IS_NULL_OR_NIL(initialValue)) {
initialValue = [self backgroundColor];
}
[_initialValues setObject:(initialValue != nil ? initialValue : [NSNull null]) forKey:@"backgroundColor"];
}
id propertiesValue = [_dataItem objectForKey:@"properties"];
NSDictionary *properties = ([propertiesValue isKindOfClass:[NSDictionary class]]) ? propertiesValue : nil;
id colorValue = [properties objectForKey:@"backgroundColor"];
UIColor *color = colorValue != nil ? [[TiUtils colorValue:colorValue] _color] : nil;
if (color == nil) {
color = [_initialValues objectForKey:@"backgroundColor"];
id initVal = [_initialValues objectForKey:@"backgroundColor"];
if ([initVal isKindOfClass:[UIColor class]]) {
color = initVal;
} else {
color = [[TiUtils colorValue:initVal] color];
}
}
self.backgroundColor = color;

//Ensure that we store the backgroundImage
if ([_initialValues objectForKey:@"backgroundImage"] == nil) {
id initialValue = nil;
if (_templateStyle == TiUIListItemTemplateStyleCustom) {
initialValue = [_proxy valueForKey:@"backgroundImage"];
}
[_initialValues setObject:(initialValue != nil ? initialValue : [NSNull null]) forKey:@"backgroundImage"];
}
id backgroundImage = [properties objectForKey:@"backgroundImage"];
if (IS_NULL_OR_NIL(backgroundImage)) {
backgroundImage = [_initialValues objectForKey:@"backgroundImage"];
}
UIImage* bgImage = [[ImageLoader sharedLoader] loadImmediateStretchableImage:[TiUtils toURL:backgroundImage proxy:_proxy] withLeftCap:TiDimensionAuto topCap:TiDimensionAuto];
if (_grouped && ![TiUtils isIOS7OrGreater]) {
UIView* superView = [self backgroundView];
if (bgImage != nil) {
if (![_bgView isKindOfClass:[UIImageView class]]) {
[_bgView removeFromSuperview];
RELEASE_TO_NIL(_bgView);
_bgView = [[UIImageView alloc] initWithFrame:CGRectZero];
_bgView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[superView addSubview:_bgView];
}
[(UIImageView*)_bgView setImage:bgImage];
[_bgView setBackgroundColor:[UIColor clearColor]];
} else {
[_bgView removeFromSuperview];
RELEASE_TO_NIL(_bgView);
}
} else {
if (bgImage != nil) {
//Set the backgroundView to ImageView and set its backgroundColor to bgColor
if ([self.backgroundView isKindOfClass:[UIImageView class]]) {
[(UIImageView*)self.backgroundView setImage:bgImage];
[(UIImageView*)self.backgroundView setBackgroundColor:[UIColor clearColor]];
} else {
UIImageView *view_ = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease];
[view_ setImage:bgImage];
[view_ setBackgroundColor:[UIColor clearColor]];
self.backgroundView = view_;
}
} else {
self.backgroundView = nil;
}
}

}

- (void)setDataItem:(NSDictionary *)dataItem
Expand Down Expand Up @@ -421,18 +430,28 @@ - (void)setDataItem:(NSDictionary *)dataItem
}

id backgroundGradientValue = [properties objectForKey:@"backgroundGradient"];
if (IS_NULL_OR_NIL(backgroundGradientValue)) {
backgroundGradientValue = [_proxy valueForKey:@"backgroundGradient"];
}
[self setBackgroundGradient_:backgroundGradientValue];


id selectedBackgroundGradientValue = [properties objectForKey:@"selectedBackgroundGradient"];
if (IS_NULL_OR_NIL(selectedBackgroundGradientValue)) {
backgroundGradientValue = [_proxy valueForKey:@"selectedBackgroundGradient"];
}
[self setSelectedBackgroundGradient_:selectedBackgroundGradientValue];

id selectedbackgroundColorValue = [properties objectForKey:@"selectedBackgroundColor"];
if (IS_NULL_OR_NIL(selectedbackgroundColorValue)) {
selectedbackgroundColorValue = [_proxy valueForKey:@"selectedBackgroundColor"];
}

id backgroundColorValue = [properties objectForKey:@"backgroundColor"];
id selectedbackgroundColorValue = [properties objectForKey:@"selectedBackgroundColor"];
id backgroundImageValue = [properties objectForKey:@"backgroundImage"];
id selectedBackgroundImageValue = [properties objectForKey:@"selectedBackgroundImage"];
[self applyBackgroundWithColor:backgroundColorValue image:backgroundImageValue selectedColor:selectedbackgroundColorValue selectedImage:selectedBackgroundImageValue];
id selectedBackgroundImageValue = [properties objectForKey:@"selectedBackgroundImage"];
if (IS_NULL_OR_NIL(selectedBackgroundImageValue)) {
selectedBackgroundImageValue = [_proxy valueForKey:@"selectedBackgroundImage"];
}
[self applyBackgroundWithSelectedColor:selectedbackgroundColorValue selectedImage:selectedBackgroundImageValue];
[_resetKeys enumerateObjectsUsingBlock:^(NSString *keyPath, BOOL *stop) {
id value = [_initialValues objectForKey:keyPath];
[self setValue:(value != [NSNull null] ? value : nil) forKeyPath:keyPath];
Expand Down
4 changes: 0 additions & 4 deletions iphone/Classes/TiUIListItemProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ -(void)propertyChanged:(NSString*)key oldValue:(id)oldValue newValue:(id)newValu
TiThreadPerformOnMainThread(^{
_listItem.accessoryType = [TiUtils intValue:newValue def:UITableViewCellAccessoryNone];
}, YES);
} else if ([key isEqualToString:@"backgroundColor"]) {
TiThreadPerformOnMainThread(^{
_listItem.backgroundColor = [[TiUtils colorValue:newValue] _color];
}, YES);
} else if ([key isEqualToString:@"selectionStyle"]) {
TiThreadPerformOnMainThread(^{
_listItem.selectionStyle = [TiUtils intValue:newValue def:UITableViewCellSelectionStyleBlue];
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiUISearchBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ -(UISearchBar*)searchBar
[searchView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[searchView setDelegate:self];
[searchView setShowsCancelButton:[(TiUISearchBarProxy *)[self proxy] showsCancelButton]];
[self addSubview:searchView];
}
return searchView;
}
Expand Down