16
16
#import " RNTableFooterView.h"
17
17
#import " RNTableHeaderView.h"
18
18
#import " RNReactModuleCell.h"
19
+ #import < AVFoundation/AVFoundation.h>
19
20
20
21
@interface RNTableView ()<UITableViewDataSource, UITableViewDelegate> {
21
22
id <RNTableViewDatasource> datasource;
@@ -107,7 +108,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge {
107
108
_autoFocus = YES ;
108
109
_autoFocusAnimate = YES ;
109
110
_allowsToggle = NO ;
110
- _allowsMultipleSelection = NO ;
111
+ _allowsMultipleSelection = YES ;
111
112
}
112
113
return self;
113
114
}
@@ -209,7 +210,7 @@ - (void)createTableView {
209
210
_tableView.dataSource = self;
210
211
_tableView.delegate = self;
211
212
_tableView.tableFooterView = [[UIView alloc ] initWithFrame: CGRectZero ];
212
- _tableView.allowsMultipleSelectionDuringEditing = NO ;
213
+ _tableView.allowsMultipleSelectionDuringEditing = YES ;
213
214
_tableView.contentInset = self.contentInset ;
214
215
_tableView.contentOffset = self.contentOffset ;
215
216
_tableView.scrollIndicatorInsets = self.scrollIndicatorInsets ;
@@ -347,6 +348,9 @@ -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cel
347
348
}
348
349
349
350
}
351
+
352
+ // Every cell can have it's own text color.
353
+ cell.textLabel .textColor = [RCTConvert UIColor: item[@" textColor" ]];
350
354
351
355
if (self.selectedBackgroundColor && [item[@" selected" ] intValue ])
352
356
{
@@ -377,6 +381,38 @@ -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cel
377
381
UIGraphicsEndImageContext ();
378
382
} else {
379
383
cell.imageView .image = image;
384
+
385
+ // Load artwork.
386
+ NSURL *fileURL = [NSURL fileURLWithPath: item[@" filePath" ]];
387
+ AVAsset *asset = [AVURLAsset URLAssetWithURL: fileURL options: nil ];
388
+ for (NSString *format in [asset availableMetadataFormats ]) {
389
+ for (AVMetadataItem *item in [asset metadataForFormat: format]) {
390
+ if ([[item commonKey ] isEqualToString: @" artwork" ]) {
391
+ UIImage *artwork = nil ;
392
+ if ([item.keySpace isEqualToString: AVMetadataKeySpaceiTunes]) {
393
+ artwork = [UIImage imageWithData: [item.value copyWithZone: nil ]];
394
+ }
395
+ else { // if ([item.keySpace isEqualToString:AVMetadataKeySpaceID3]) {
396
+ if (floor (NSFoundationVersionNumber ) > NSFoundationVersionNumber_iOS_7_1) {
397
+ artwork = [UIImage imageWithData: item.dataValue];
398
+ } else {
399
+ NSDictionary *dict;
400
+ [item.value copyWithZone: nil ];
401
+ artwork = [UIImage imageWithData: [dict objectForKey: @" data" ]];
402
+ }
403
+ }
404
+ cell.imageView .image = artwork;
405
+ }
406
+ }
407
+ }
408
+
409
+ // Custom size.
410
+ CGSize itemSize = CGSizeMake (48 , 48 );
411
+ UIGraphicsBeginImageContextWithOptions (itemSize, NO , UIScreen.mainScreen .scale );
412
+ CGRect imageRect = CGRectMake (0.0 , 0.0 , itemSize.width , itemSize.height );
413
+ [cell.imageView.image drawInRect: imageRect];
414
+ cell.imageView .image = UIGraphicsGetImageFromCurrentImageContext ();
415
+ UIGraphicsEndImageContext ();
380
416
}
381
417
}
382
418
@@ -496,9 +532,29 @@ -(UITableViewCell* )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS
496
532
if (item[@" selectionStyle" ] != nil ) {
497
533
cell.selectionStyle = [RCTConvert int: item[@" selectionStyle" ]];
498
534
}
535
+
536
+ // Add a custom accessory button.
537
+ UIButton *button = [UIButton buttonWithType: UIButtonTypeCustom];
538
+ [button addTarget: self action: @selector (checkButtonTapped:event: ) forControlEvents: UIControlEventTouchUpInside];
539
+ [button setTitle: @" \uF1D8 " forState: UIControlStateNormal];
540
+ [button setTitleColor: [RCTConvert UIColor: item[@" accessoryColor" ]] forState: UIControlStateNormal];
541
+ [button.titleLabel setFont: [UIFont fontWithName: @" Material Design Icons" size: 22 .0f ]];
542
+ button.frame = CGRectMake (0 , 0 , 48 , 64 );
543
+ cell.accessoryView = button;
544
+
499
545
return cell;
500
546
}
501
547
548
+ - (void )checkButtonTapped : (id )sender event : (id )event {
549
+ NSSet *touches = [event allTouches ];
550
+ UITouch *touch = [touches anyObject ];
551
+ CGPoint currentTouchPosition = [touch locationInView: self .tableView];
552
+ NSIndexPath *indexPath = [self .tableView indexPathForRowAtPoint: currentTouchPosition];
553
+ if (indexPath != nil ){
554
+ [self tableView: self .tableView accessoryButtonTappedForRowWithIndexPath: indexPath];
555
+ }
556
+ }
557
+
502
558
-(NSString *)tableView : (UITableView *)tableView titleForHeaderInSection : (NSInteger )section {
503
559
return _sections[section][@" label" ];
504
560
}
@@ -524,7 +580,9 @@ -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPat
524
580
}
525
581
526
582
- (void )tableView : (UITableView *)tableView didSelectRowAtIndexPath : (NSIndexPath *)indexPath {
527
- [tableView deselectRowAtIndexPath: indexPath animated: NO ];
583
+ if (!_editing) {
584
+ [tableView deselectRowAtIndexPath: indexPath animated: NO ];
585
+ }
528
586
529
587
NSMutableDictionary *newValue = [self dataForRow: indexPath.item section: indexPath.section];
530
588
newValue[@" target" ] = self.reactTag ;
0 commit comments