-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathFLEXGlobalsSection.m
More file actions
86 lines (66 loc) · 2.03 KB
/
Copy pathFLEXGlobalsSection.m
File metadata and controls
86 lines (66 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// FLEXGlobalsSection.m
// FLEX
//
// Created by Tanner Bennett on 7/11/19.
// Copyright © 2020 FLEX Team. All rights reserved.
//
#import "FLEXGlobalsSection.h"
#import "NSArray+FLEX.h"
#import "UIFont+FLEX.h"
@interface FLEXGlobalsSection ()
/// Filtered rows
@property (nonatomic) NSArray<FLEXGlobalsEntry *> *rows;
/// Unfiltered rows
@property (nonatomic) NSArray<FLEXGlobalsEntry *> *allRows;
@end
@implementation FLEXGlobalsSection
#pragma mark - Initialization
+ (instancetype)title:(NSString *)title rows:(NSArray<FLEXGlobalsEntry *> *)rows {
FLEXGlobalsSection *s = [self new];
s->_title = title;
s.allRows = rows;
return s;
}
- (void)setAllRows:(NSArray<FLEXGlobalsEntry *> *)allRows {
_allRows = allRows.copy;
[self reloadData];
}
#pragma mark - Overrides
- (NSInteger)numberOfRows {
return self.rows.count;
}
- (void)setFilterText:(NSString *)filterText {
super.filterText = filterText;
[self reloadData];
}
- (void)reloadData {
NSString *filterText = self.filterText;
if (filterText.length) {
self.rows = [self.allRows flex_filtered:^BOOL(FLEXGlobalsEntry *entry, NSUInteger idx) {
return [entry.entryNameFuture() localizedCaseInsensitiveContainsString:filterText];
}];
} else {
self.rows = self.allRows;
}
}
- (BOOL)canSelectRow:(NSInteger)row {
return YES;
}
- (void (^)(__kindof UIViewController *))didSelectRowAction:(NSInteger)row {
return (id)self.rows[row].rowAction;
}
- (UIViewController *)viewControllerToPushForRow:(NSInteger)row {
return self.rows[row].viewControllerFuture ? self.rows[row].viewControllerFuture() : nil;
}
- (void)configureCell:(__kindof UITableViewCell *)cell forRow:(NSInteger)row {
cell.accessoryType = self.rows[row].cellAccessoryType;
cell.textLabel.font = UIFont.flex_defaultTableCellFont;
cell.textLabel.text = self.rows[row].entryNameFuture();
}
@end
@implementation FLEXGlobalsSection (Subscripting)
- (id)objectAtIndexedSubscript:(NSUInteger)idx {
return self.rows[idx];
}
@end