Skip to content

Commit 544945a

Browse files
committed
Add support for optionally customizing the cell accessory type
1 parent 22f5482 commit 544945a

File tree

6 files changed

+119
-15
lines changed

6 files changed

+119
-15
lines changed

Classes/GlobalStateExplorers/Globals/FLEXGlobalsEntry.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,20 @@ typedef void (^FLEXNestedGlobalEntriesHandler)(FLEXUserGlobalEntriesContainer *
8585
@interface FLEXGlobalsEntry : NSObject
8686

8787
@property (nonatomic, readonly, nonnull) FLEXGlobalsEntryNameFuture entryNameFuture;
88+
@property (nonatomic, readonly) UITableViewCellAccessoryType cellAccessoryType;
8889
@property (nonatomic, readonly, nullable) FLEXGlobalsEntryViewControllerFuture viewControllerFuture;
8990
@property (nonatomic, readonly, nullable) FLEXGlobalsEntryRowAction rowAction;
9091

91-
+ (instancetype)entryWithEntry:(Class<FLEXGlobalsEntry>)entry row:(FLEXGlobalsRow)row;
92+
+ (instancetype)entryWithEntry:(Class<FLEXGlobalsEntry>)entry
93+
cellAccessoryType:(UITableViewCellAccessoryType)cellAccessoryType
94+
row:(FLEXGlobalsRow)row;
9295

9396
+ (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
97+
cellAccessoryType:(UITableViewCellAccessoryType)cellAccessoryType
9498
viewControllerFuture:(FLEXGlobalsEntryViewControllerFuture)viewControllerFuture;
9599

96100
+ (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
101+
cellAccessoryType:(UITableViewCellAccessoryType)cellAccessoryType
97102
action:(FLEXGlobalsEntryRowAction)rowSelectedAction;
98103

99104
@end

Classes/GlobalStateExplorers/Globals/FLEXGlobalsEntry.m

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010

1111
@implementation FLEXGlobalsEntry
1212

13-
+ (instancetype)entryWithEntry:(Class<FLEXGlobalsEntry>)cls row:(FLEXGlobalsRow)row {
13+
+ (instancetype)entryWithEntry:(Class<FLEXGlobalsEntry>)cls
14+
cellAccessoryType:(UITableViewCellAccessoryType)cellAccessoryType
15+
row:(FLEXGlobalsRow)row {
1416
BOOL providesVCs = [cls respondsToSelector:@selector(globalsEntryViewController:)];
1517
BOOL providesActions = [cls respondsToSelector:@selector(globalsEntryRowAction:)];
1618
NSParameterAssert(cls);
1719
NSParameterAssert(providesVCs || providesActions);
1820

1921
FLEXGlobalsEntry *entry = [self new];
2022
entry->_entryNameFuture = ^{ return [cls globalsEntryTitle:row]; };
23+
entry->_cellAccessoryType = cellAccessoryType;
2124

2225
if (providesVCs) {
2326
id action = providesActions ? [cls globalsEntryRowAction:row] : nil;
@@ -34,24 +37,28 @@ + (instancetype)entryWithEntry:(Class<FLEXGlobalsEntry>)cls row:(FLEXGlobalsRow)
3437
}
3538

3639
+ (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
40+
cellAccessoryType:(UITableViewCellAccessoryType)cellAccessoryType
3741
viewControllerFuture:(FLEXGlobalsEntryViewControllerFuture)viewControllerFuture {
3842
NSParameterAssert(nameFuture);
3943
NSParameterAssert(viewControllerFuture);
4044

4145
FLEXGlobalsEntry *entry = [self new];
4246
entry->_entryNameFuture = [nameFuture copy];
47+
entry->_cellAccessoryType = cellAccessoryType;
4348
entry->_viewControllerFuture = [viewControllerFuture copy];
4449

4550
return entry;
4651
}
4752

4853
+ (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
54+
cellAccessoryType:(UITableViewCellAccessoryType)cellAccessoryType
4955
action:(FLEXGlobalsEntryRowAction)rowSelectedAction {
5056
NSParameterAssert(nameFuture);
5157
NSParameterAssert(rowSelectedAction);
5258

5359
FLEXGlobalsEntry *entry = [self new];
5460
entry->_entryNameFuture = [nameFuture copy];
61+
entry->_cellAccessoryType = cellAccessoryType;
5562
entry->_rowAction = [rowSelectedAction copy];
5663

5764
return entry;
@@ -77,7 +84,10 @@ @implementation NSObject (FLEXGlobalsEntry)
7784

7885
+ (FLEXGlobalsEntry *)flex_concreteGlobalsEntry:(FLEXGlobalsRow)row {
7986
if ([self conformsToProtocol:@protocol(FLEXGlobalsEntry)]) {
80-
return [FLEXGlobalsEntry entryWithEntry:self row:row];
87+
return [FLEXGlobalsEntry entryWithEntry:self
88+
cellAccessoryType:UITableViewCellAccessoryDisclosureIndicator
89+
row:row
90+
];
8191
}
8292

8393
return nil;

Classes/GlobalStateExplorers/Globals/FLEXGlobalsSection.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ - (UIViewController *)viewControllerToPushForRow:(NSInteger)row {
6969
}
7070

7171
- (void)configureCell:(__kindof UITableViewCell *)cell forRow:(NSInteger)row {
72-
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
72+
cell.accessoryType = self.rows[row].cellAccessoryType;
7373
cell.textLabel.font = UIFont.flex_defaultTableCellFont;
7474
cell.textLabel.text = self.rows[row].entryNameFuture();
7575
}

Classes/GlobalStateExplorers/Globals/FLEXUserGlobalEntriesContainer.h

+55
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ NS_ASSUME_NONNULL_BEGIN
2626
/// you may want to use __weak references.
2727
- (void)registerGlobalEntryWithName:(NSString *)entryName objectFutureBlock:(id (^)(void))objectFutureBlock;
2828

29+
/// Adds an entry at the top of the list of Global State items.
30+
/// Call this method before this view controller is displayed.
31+
/// @param entryName The string to be displayed in the cell.
32+
/// @param cellAccessoryType The accessory type to be used for the cell.
33+
/// @param objectFutureBlock When you tap on the row, information about the object returned
34+
/// by this block will be displayed. Passing a block that returns an object allows you to display
35+
/// information about an object whose actual pointer may change at runtime (e.g. +currentUser)
36+
/// @note This method must be called from the main thread.
37+
/// The objectFutureBlock will be invoked from the main thread and may return nil.
38+
/// @note The passed block will be copied and retain for the duration of the application,
39+
/// you may want to use __weak references.
40+
- (void)registerGlobalEntryWithName:(NSString *)entryName
41+
cellAccessoryType:(UITableViewCellAccessoryType)cellAccessoryType
42+
objectFutureBlock:(id (^)(void))objectFutureBlock;
43+
2944
/// Adds an entry at the top of the list of Global State items.
3045
/// Call this method before this view controller is displayed.
3146
/// @param entryName The string to be displayed in the cell.
@@ -38,6 +53,20 @@ NS_ASSUME_NONNULL_BEGIN
3853
- (void)registerGlobalEntryWithName:(NSString *)entryName
3954
viewControllerFutureBlock:(UIViewController * (^)(void))viewControllerFutureBlock;
4055

56+
/// Adds an entry at the top of the list of Global State items.
57+
/// Call this method before this view controller is displayed.
58+
/// @param entryName The string to be displayed in the cell.
59+
/// @param cellAccessoryType The accessory type to be used for the cell.
60+
/// @param viewControllerFutureBlock When you tap on the row, view controller returned
61+
/// by this block will be pushed on the navigation controller stack.
62+
/// @note This method must be called from the main thread.
63+
/// The viewControllerFutureBlock will be invoked from the main thread and may not return nil.
64+
/// @note The passed block will be copied and retain for the duration of the application,
65+
/// you may want to use __weak references as needed.
66+
- (void)registerGlobalEntryWithName:(NSString *)entryName
67+
cellAccessoryType:(UITableViewCellAccessoryType)cellAccessoryType
68+
viewControllerFutureBlock:(UIViewController * (^)(void))viewControllerFutureBlock;
69+
4170
/// Adds an entry at the top of the list of Global State items.
4271
/// @param entryName The string to be displayed in the cell.
4372
/// @param rowSelectedAction When you tap on the row, this block will be invoked
@@ -48,6 +77,19 @@ NS_ASSUME_NONNULL_BEGIN
4877
/// you may want to use __weak references as needed.
4978
- (void)registerGlobalEntryWithName:(NSString *)entryName action:(FLEXGlobalsEntryRowAction)rowSelectedAction;
5079

80+
/// Adds an entry at the top of the list of Global State items.
81+
/// @param entryName The string to be displayed in the cell.
82+
/// @param cellAccessoryType The accessory type to be used for the cell.
83+
/// @param rowSelectedAction When you tap on the row, this block will be invoked
84+
/// with the host table view view controller. Use it to deselect the row or present an alert.
85+
/// @note This method must be called from the main thread.
86+
/// The rowSelectedAction will be invoked from the main thread.
87+
/// @note The passed block will be copied and retained for the duration of the application,
88+
/// you may want to use __weak references as needed.
89+
- (void)registerGlobalEntryWithName:(NSString *)entryName
90+
cellAccessoryType:(UITableViewCellAccessoryType)cellAccessoryType
91+
action:(FLEXGlobalsEntryRowAction)rowSelectedAction;
92+
5193
/// Adds an entry at the top of the list of Global State items.
5294
/// @param entryName The string to be displayed in the cell.
5395
/// @param nestedEntriesHandler When you tap on the row, this block will be invoked
@@ -58,6 +100,19 @@ NS_ASSUME_NONNULL_BEGIN
58100
/// you may want to use __weak references as needed.
59101
- (void)registerNestedGlobalEntryWithName:(NSString *)entryName handler:(FLEXNestedGlobalEntriesHandler)nestedEntriesHandler;
60102

103+
/// Adds an entry at the top of the list of Global State items.
104+
/// @param entryName The string to be displayed in the cell.
105+
/// @param cellAccessoryType The accessory type to be used for the cell.
106+
/// @param nestedEntriesHandler When you tap on the row, this block will be invoked
107+
/// with the container object. Use it to register nested entries.
108+
/// @note This method must be called from the main thread.
109+
/// The nestedEntriesHandler will be invoked from the main thread.
110+
/// @note The passed block will be copied and retained for the duration of the application,
111+
/// you may want to use __weak references as needed.
112+
- (void)registerNestedGlobalEntryWithName:(NSString *)entryName
113+
cellAccessoryType:(UITableViewCellAccessoryType)cellAccessoryType
114+
handler:(FLEXNestedGlobalEntriesHandler)nestedEntriesHandler;
115+
61116
/// Removes all registered global entries.
62117
- (void)clearGlobalEntries;
63118

Classes/GlobalStateExplorers/Globals/FLEXUserGlobalEntriesContainer.m

+38-4
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,45 @@ - (instancetype)init {
2828
}
2929

3030
- (void)registerGlobalEntryWithName:(NSString *)entryName objectFutureBlock:(id (^)(void))objectFutureBlock {
31+
[self registerGlobalEntryWithName:entryName
32+
cellAccessoryType:UITableViewCellAccessoryDisclosureIndicator
33+
objectFutureBlock:objectFutureBlock
34+
];
35+
}
36+
37+
- (void)registerGlobalEntryWithName:(NSString *)entryName cellAccessoryType:(UITableViewCellAccessoryType)cellAccessoryType objectFutureBlock:(id (^)(void))objectFutureBlock {
3138
NSParameterAssert(entryName);
3239
NSParameterAssert(objectFutureBlock);
3340
NSAssert(NSThread.isMainThread, @"This method must be called from the main thread.");
3441

3542
entryName = entryName.copy;
3643
FLEXGlobalsEntry *entry = [FLEXGlobalsEntry entryWithNameFuture:^NSString *{
3744
return entryName;
38-
} viewControllerFuture:^UIViewController *{
45+
} cellAccessoryType:cellAccessoryType viewControllerFuture:^UIViewController *{
3946
return [FLEXObjectExplorerFactory explorerViewControllerForObject:objectFutureBlock()];
4047
}];
4148

4249
[self.entries addObject:entry];
4350
}
4451

4552
- (void)registerGlobalEntryWithName:(NSString *)entryName viewControllerFutureBlock:(UIViewController * (^)(void))viewControllerFutureBlock {
53+
[self registerGlobalEntryWithName:entryName
54+
cellAccessoryType:UITableViewCellAccessoryDisclosureIndicator
55+
viewControllerFutureBlock:viewControllerFutureBlock
56+
];
57+
}
58+
59+
- (void)registerGlobalEntryWithName:(NSString *)entryName
60+
cellAccessoryType:(UITableViewCellAccessoryType)cellAccessoryType
61+
viewControllerFutureBlock:(UIViewController * (^)(void))viewControllerFutureBlock {
4662
NSParameterAssert(entryName);
4763
NSParameterAssert(viewControllerFutureBlock);
4864
NSAssert(NSThread.isMainThread, @"This method must be called from the main thread.");
4965

5066
entryName = entryName.copy;
5167
FLEXGlobalsEntry *entry = [FLEXGlobalsEntry entryWithNameFuture:^NSString *{
5268
return entryName;
53-
} viewControllerFuture:^UIViewController *{
69+
} cellAccessoryType:cellAccessoryType viewControllerFuture:^UIViewController *{
5470
UIViewController *viewController = viewControllerFutureBlock();
5571
NSCAssert(viewController, @"'%@' entry returned nil viewController. viewControllerFutureBlock should never return nil.", entryName);
5672
return viewController;
@@ -60,27 +76,45 @@ - (void)registerGlobalEntryWithName:(NSString *)entryName viewControllerFutureBl
6076
}
6177

6278
- (void)registerGlobalEntryWithName:(NSString *)entryName action:(FLEXGlobalsEntryRowAction)rowSelectedAction {
79+
[self registerGlobalEntryWithName:entryName
80+
cellAccessoryType:UITableViewCellAccessoryDisclosureIndicator
81+
action:rowSelectedAction
82+
];
83+
}
84+
85+
- (void)registerGlobalEntryWithName:(NSString *)entryName
86+
cellAccessoryType:(UITableViewCellAccessoryType)cellAccessoryType
87+
action:(FLEXGlobalsEntryRowAction)rowSelectedAction {
6388
NSParameterAssert(entryName);
6489
NSParameterAssert(rowSelectedAction);
6590
NSAssert(NSThread.isMainThread, @"This method must be called from the main thread.");
6691

6792
entryName = entryName.copy;
6893
FLEXGlobalsEntry *entry = [FLEXGlobalsEntry entryWithNameFuture:^NSString * _Nonnull{
6994
return entryName;
70-
} action:rowSelectedAction];
95+
} cellAccessoryType:cellAccessoryType action:rowSelectedAction];
7196

7297
[self.entries addObject:entry];
7398
}
7499

75100
- (void)registerNestedGlobalEntryWithName:(NSString *)entryName handler:(FLEXNestedGlobalEntriesHandler)nestedEntriesHandler {
101+
[self registerNestedGlobalEntryWithName:entryName
102+
cellAccessoryType:UITableViewCellAccessoryDisclosureIndicator
103+
handler:nestedEntriesHandler
104+
];
105+
}
106+
107+
- (void)registerNestedGlobalEntryWithName:(NSString *)entryName
108+
cellAccessoryType:(UITableViewCellAccessoryType)cellAccessoryType
109+
handler:(FLEXNestedGlobalEntriesHandler)nestedEntriesHandler {
76110
NSParameterAssert(entryName);
77111
NSParameterAssert(nestedEntriesHandler);
78112
NSAssert(NSThread.isMainThread, @"This method must be called from the main thread.");
79113

80114
entryName = entryName.copy;
81115
FLEXGlobalsEntry *entry = [FLEXGlobalsEntry entryWithNameFuture:^NSString * _Nonnull{
82116
return entryName;
83-
} viewControllerFuture:^UIViewController * _Nullable{
117+
} cellAccessoryType:cellAccessoryType viewControllerFuture:^UIViewController * _Nullable{
84118
FLEXUserGlobalEntriesContainer *container = [FLEXUserGlobalEntriesContainer new];
85119
nestedEntriesHandler(container);
86120

Example/FLEXample/AppDelegate.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2828

2929
// To show off the global entries, register one of each type
3030

31-
FLEXManager.shared.globalEntriesContainer.registerGlobalEntry(withName: "Level 1 - Object") {
31+
FLEXManager.shared.globalEntriesContainer.registerGlobalEntry(withName: "Level 1 - Object", cellAccessoryType: .none) {
3232
return "Level 1 - Object"
3333
}
3434

35-
FLEXManager.shared.globalEntriesContainer.registerGlobalEntry(withName: "Level 1 - View controller") {
35+
FLEXManager.shared.globalEntriesContainer.registerGlobalEntry(withName: "Level 1 - View controller", cellAccessoryType: .none) {
3636
let label = UILabel()
3737
label.text = "Level 1 - View controller"
3838
label.translatesAutoresizingMaskIntoConstraints = false
@@ -48,16 +48,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4848
return controller
4949
}
5050

51-
FLEXManager.shared.globalEntriesContainer.registerGlobalEntry(withName: "Level 1 - Action") { host in
51+
FLEXManager.shared.globalEntriesContainer.registerGlobalEntry(withName: "Level 1 - Action", cellAccessoryType: .none) { host in
5252
FLEXAlert.showQuickAlert("Level 1 - Action", from: host)
5353
}
5454

5555
FLEXManager.shared.globalEntriesContainer.registerNestedGlobalEntry(withName: "Level 1 - Nested") { container in
56-
container.registerGlobalEntry(withName: "Level 2 - Object") {
56+
container.registerGlobalEntry(withName: "Level 2 - Object", cellAccessoryType: .none) {
5757
return "Level 2 - Object"
5858
}
5959

60-
container.registerGlobalEntry(withName: "Level 2 - View controller") {
60+
container.registerGlobalEntry(withName: "Level 2 - View controller", cellAccessoryType: .none) {
6161
let label = UILabel()
6262
label.text = "Level 2 - View controller"
6363
label.translatesAutoresizingMaskIntoConstraints = false
@@ -73,12 +73,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
7373
return controller
7474
}
7575

76-
container.registerGlobalEntry(withName: "Level 2 - Action") { host in
76+
container.registerGlobalEntry(withName: "Level 2 - Action", cellAccessoryType: .none) { host in
7777
FLEXAlert.showQuickAlert("Level 2 - Action", from: host)
7878
}
7979

8080
container.registerNestedGlobalEntry(withName: "Level 2 - Nested") { level2Container in
81-
level2Container.registerGlobalEntry(withName: "Level 3 - Action") { host in
81+
level2Container.registerGlobalEntry(withName: "Level 3 - Action", cellAccessoryType: .none) { host in
8282
FLEXAlert.showQuickAlert("Level 3 - Action", from: host)
8383
}
8484
}

0 commit comments

Comments
 (0)