Last active
June 11, 2016 23:58
-
-
Save talkol/94e391cd240f2d492b0cad5a5b4fe541 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "RNTableView.h" | |
#import "RCTConvert.h" | |
#import "RCTEventDispatcher.h" | |
#import "RCTUtils.h" | |
#import "UIView+React.h" | |
@interface RNTableView()<UITableViewDataSource, UITableViewDelegate> | |
@property (strong, nonatomic) UITableView *tableView; | |
@end | |
@implementation RNTableView | |
RCTBridge *_bridge; | |
RCTEventDispatcher *_eventDispatcher; | |
NSMutableArray *_unusedCells; | |
- (instancetype)initWithBridge:(RCTBridge *)bridge { | |
RCTAssertParam(bridge); | |
if ((self = [super initWithFrame:CGRectZero])) { | |
_eventDispatcher = bridge.eventDispatcher; | |
_bridge = bridge; | |
while ([_bridge respondsToSelector:NSSelectorFromString(@"parentBridge")] && [_bridge valueForKey:@"parentBridge"]) { | |
_bridge = [_bridge valueForKey:@"parentBridge"]; | |
} | |
_unusedCells = [NSMutableArray array]; | |
[self createTableView]; | |
} | |
return self; | |
} | |
RCT_NOT_IMPLEMENTED(-initWithFrame:(CGRect)frame) | |
RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder) | |
- (void)layoutSubviews { | |
[self.tableView setFrame:self.frame]; | |
} | |
- (void)createTableView { | |
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; | |
_tableView.dataSource = self; | |
_tableView.delegate = self; | |
_tableView.backgroundColor = [UIColor whiteColor]; | |
[self addSubview:_tableView]; | |
} | |
- (void)setRowHeight:(float)rowHeight { | |
_tableView.estimatedRowHeight = rowHeight; | |
_rowHeight = rowHeight; | |
} | |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView { | |
return 1; | |
} | |
- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section { | |
return self.numRows; | |
} | |
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { | |
return self.rowHeight; | |
} | |
// the interesting parts are still missing here | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment