Skip to content

Commit

Permalink
Merge pull request #4260 from vishalduggal/timob-13417
Browse files Browse the repository at this point in the history
[TIMOB-13417] iOS: ListView V2 UI enhancements
  • Loading branch information
srahim committed May 15, 2013
2 parents 96bdfdd + 01cd20f commit a64a024
Show file tree
Hide file tree
Showing 15 changed files with 765 additions and 182 deletions.
32 changes: 32 additions & 0 deletions iphone/Classes/TiSelectedCellbackgroundView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2013 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#if defined(USE_TI_UITABLEVIEW) || defined(USE_TI_UILISTVIEW)

#import <UIKit/UIKit.h>

typedef enum
{
TiCellBackgroundViewPositionTop,
TiCellBackgroundViewPositionMiddle,
TiCellBackgroundViewPositionBottom,
TiCellBackgroundViewPositionSingleLine
} TiCellBackgroundViewPosition;


@interface TiSelectedCellBackgroundView : UIView
{
TiCellBackgroundViewPosition position;
UIColor *fillColor;
BOOL grouped;
}
@property(nonatomic) TiCellBackgroundViewPosition position;
@property(nonatomic,retain) UIColor *fillColor;
@property(nonatomic) BOOL grouped;

@end

#endif
145 changes: 145 additions & 0 deletions iphone/Classes/TiSelectedCellbackgroundView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2013 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#if defined(USE_TI_UITABLEVIEW) || defined(USE_TI_UILISTVIEW)

#import "TiSelectedCellbackgroundView.h"

static void addRoundedRectToPath(CGContextRef context, CGRect rect,
float ovalWidth,float ovalHeight)

{
float fw, fh;

if (ovalWidth == 0 || ovalHeight == 0) {// 1
CGContextAddRect(context, rect);
return;
}

CGContextSaveGState(context);// 2

CGContextTranslateCTM (context, CGRectGetMinX(rect),// 3
CGRectGetMinY(rect));
CGContextScaleCTM (context, ovalWidth, ovalHeight);// 4
fw = CGRectGetWidth (rect) / ovalWidth;// 5
fh = CGRectGetHeight (rect) / ovalHeight;// 6

CGContextMoveToPoint(context, fw, fh/2); // 7
CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1);// 8
CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1);// 9
CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1);// 10
CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); // 11
CGContextClosePath(context);// 12

CGContextRestoreGState(context);// 13
}

#define ROUND_SIZE 10


@implementation TiSelectedCellBackgroundView

@synthesize position,fillColor,grouped;

- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame])
{
self.fillColor = [UIColor clearColor];
position = TiCellBackgroundViewPositionMiddle;
}
return self;
}

-(void)dealloc
{
[fillColor release];
[super dealloc];
}

-(BOOL)isOpaque
{
return (CGColorGetAlpha([fillColor CGColor]) == 1.0);
}

-(void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(ctx, [fillColor CGColor]);
CGContextSetStrokeColorWithColor(ctx, [fillColor CGColor]);
CGContextSetLineWidth(ctx, 2);

if (grouped && position == TiCellBackgroundViewPositionTop)
{
CGFloat minx = CGRectGetMinX(rect), midx = CGRectGetMidX(rect), maxx = CGRectGetMaxX(rect) ;
CGFloat miny = CGRectGetMinY(rect), maxy = CGRectGetMaxY(rect);

CGContextMoveToPoint(ctx, minx, maxy);
CGContextAddArcToPoint(ctx, minx, miny, midx, miny, ROUND_SIZE);
CGContextAddArcToPoint(ctx, maxx, miny, maxx, maxy, ROUND_SIZE);
CGContextAddLineToPoint(ctx, maxx, maxy);

// Close the path
CGContextClosePath(ctx);
CGContextSaveGState(ctx);
CGContextDrawPath(ctx, kCGPathFill);
return;
}
else if (grouped && position == TiCellBackgroundViewPositionBottom)
{
CGFloat minx = CGRectGetMinX(rect) , midx = CGRectGetMidX(rect), maxx = CGRectGetMaxX(rect) ;
CGFloat miny = CGRectGetMinY(rect) , maxy = CGRectGetMaxY(rect) ;

CGContextMoveToPoint(ctx, minx, miny);
CGContextAddArcToPoint(ctx, minx, maxy, midx, maxy, ROUND_SIZE);
CGContextAddArcToPoint(ctx, maxx, maxy, maxx, miny, ROUND_SIZE);
CGContextAddLineToPoint(ctx, maxx, miny);
CGContextClosePath(ctx);
CGContextSaveGState(ctx);
CGContextDrawPath(ctx, kCGPathFill);
return;
}
else if (!grouped || position == TiCellBackgroundViewPositionMiddle)
{
CGFloat minx = CGRectGetMinX(rect), maxx = CGRectGetMaxX(rect);
CGFloat miny = CGRectGetMinY(rect), maxy = CGRectGetMaxY(rect);
CGContextMoveToPoint(ctx, minx, miny);
CGContextAddLineToPoint(ctx, maxx, miny);
CGContextAddLineToPoint(ctx, maxx, maxy);
CGContextAddLineToPoint(ctx, minx, maxy);
CGContextClosePath(ctx);
CGContextSaveGState(ctx);
CGContextDrawPath(ctx, kCGPathFill);
return;
}
else if (grouped && position == TiCellBackgroundViewPositionSingleLine)
{
CGContextBeginPath(ctx);
addRoundedRectToPath(ctx, rect, ROUND_SIZE*1.5, ROUND_SIZE*1.5);
CGContextFillPath(ctx);

CGContextSetLineWidth(ctx, 2);
CGContextBeginPath(ctx);
addRoundedRectToPath(ctx, rect, ROUND_SIZE*1.5, ROUND_SIZE*1.5);
CGContextStrokePath(ctx);

return;
}
[super drawRect:rect];
}

-(void)setPosition:(TiCellBackgroundViewPosition)inPosition
{
if(position != inPosition)
{
position = inPosition;
[self setNeedsDisplay];
}
}

@end

#endif
8 changes: 7 additions & 1 deletion iphone/Classes/TiUIListItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
#import <UIKit/UIKit.h>
#import "TiUIListView.h"
#import "TiUIListItemProxy.h"
#import "TiSelectedCellbackgroundView.h"

enum {
TiUIListItemTemplateStyleCustom = -1
};

@interface TiUIListItem : UITableViewCell
{
TiGradientLayer * gradientLayer;
TiGradient * backgroundGradient;
TiGradient * selectedBackgroundGradient;
}

@property (nonatomic, readonly) NSInteger templateStyle;
@property (nonatomic, readonly) TiUIListItemProxy *proxy;
Expand All @@ -24,7 +30,7 @@ enum {
- (id)initWithProxy:(TiUIListItemProxy *)proxy reuseIdentifier:(NSString *)reuseIdentifier;

- (BOOL)canApplyDataItem:(NSDictionary *)otherItem;

- (void)setPosition:(int)position isGrouped:(BOOL)grouped;
@end

#endif

0 comments on commit a64a024

Please sign in to comment.