Skip to content

Commit

Permalink
Merge pull request #3661 from vishalduggal/timob-11335
Browse files Browse the repository at this point in the history
[TIMOB-11335] Animate gradientLayer opacity
  • Loading branch information
srahim committed Jan 7, 2013
2 parents b2715a0 + d759734 commit 189daf1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion iphone/Classes/TiUITableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
-(void) setBackgroundGradient_:(TiGradient *)newGradient;
-(void) setSelectedBackgroundGradient_:(TiGradient *)newGradient;

-(void) updateGradientLayer:(BOOL)useSelected;
-(void) updateGradientLayer:(BOOL)useSelected withAnimation:(BOOL)animated;
-(CGSize)computeCellSize;

@end
Expand Down
23 changes: 15 additions & 8 deletions iphone/Classes/TiUITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ -(BOOL) selectedOrHighlighted
}


-(void) updateGradientLayer:(BOOL)useSelected
-(void) updateGradientLayer:(BOOL)useSelected withAnimation:(BOOL)animated
{
TiGradient * currentGradient = useSelected?selectedBackgroundGradient:backgroundGradient;

Expand All @@ -200,7 +200,7 @@ -(void) updateGradientLayer:(BOOL)useSelected
//Because there's the chance that the other state still has the gradient, let's keep it around.
return;
}

CALayer * ourLayer = [self layer];

if(gradientLayer == nil)
Expand All @@ -222,31 +222,38 @@ -(void) updateGradientLayer:(BOOL)useSelected
[[self textLabel] setBackgroundColor:[UIColor clearColor]];
}
}
if (animated) {
CABasicAnimation *flash = [CABasicAnimation animationWithKeyPath:@"opacity"];
flash.fromValue = [NSNumber numberWithFloat:0.0];
flash.toValue = [NSNumber numberWithFloat:1.0];
flash.duration = 1.0;
[gradientLayer addAnimation:flash forKey:@"flashAnimation"];
}
[gradientLayer setNeedsDisplay];
}

-(void)setSelected:(BOOL)yn animated:(BOOL)animated
{
[super setSelected:yn animated:animated];
[self updateGradientLayer:yn|[self isHighlighted]];
[self updateGradientLayer:yn|[self isHighlighted] withAnimation:animated];
}

-(void)setHighlighted:(BOOL)yn animated:(BOOL)animated
{
[super setHighlighted:yn animated:animated];
[self updateGradientLayer:yn|[self isSelected]];
[self updateGradientLayer:yn|[self isSelected] withAnimation:animated];
}

-(void)setHighlighted:(BOOL)yn
{
[super setHighlighted:yn];
[self updateGradientLayer:yn|[self isHighlighted]];
[self updateGradientLayer:yn|[self isSelected] withAnimation:NO];
}

-(void)setSelected:(BOOL)yn
{
[super setSelected:yn];
[self updateGradientLayer:yn|[self isHighlighted]];
[self updateGradientLayer:yn|[self isHighlighted] withAnimation:NO];
}

-(void) setBackgroundGradient_:(TiGradient *)newGradient
Expand All @@ -260,7 +267,7 @@ -(void) setBackgroundGradient_:(TiGradient *)newGradient

if(![self selectedOrHighlighted])
{
[self updateGradientLayer:NO];
[self updateGradientLayer:NO withAnimation:NO];
}
}

Expand All @@ -275,7 +282,7 @@ -(void) setSelectedBackgroundGradient_:(TiGradient *)newGradient

if([self selectedOrHighlighted])
{
[self updateGradientLayer:YES];
[self updateGradientLayer:YES withAnimation:NO];
}
}

Expand Down

0 comments on commit 189daf1

Please sign in to comment.