Skip to content
This repository was archived by the owner on Aug 24, 2020. It is now read-only.

Commit 5a0a17b

Browse files
committed
Add dynamic options support
1 parent 9f8136c commit 5a0a17b

File tree

10 files changed

+70
-14
lines changed

10 files changed

+70
-14
lines changed

Bohr.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "Bohr"
3-
s.version = "3.0.0-rc.1"
3+
s.version = "3.0.0-rc.2"
44
s.summary = "Settings screen composing framework"
55
s.homepage = "https://github.com/DavdRoman/Bohr"
66
s.author = { "David Román" => "[email protected]" }

Bohr.xcodeproj/project.pbxproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
75C7ADC91B1AB2F80050C8AA /* Project object */ = {
326326
isa = PBXProject;
327327
attributes = {
328-
LastUpgradeCheck = 0640;
328+
LastUpgradeCheck = 0700;
329329
TargetAttributes = {
330330
75C7ADD21B1AB3010050C8AA = {
331331
CreatedOnToolsVersion = 6.3.2;
@@ -435,6 +435,7 @@
435435
75C7ADCD1B1AB2F80050C8AA /* Debug */ = {
436436
isa = XCBuildConfiguration;
437437
buildSettings = {
438+
ENABLE_TESTABILITY = YES;
438439
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
439440
ONLY_ACTIVE_ARCH = YES;
440441
};
@@ -490,6 +491,7 @@
490491
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
491492
MTL_ENABLE_DEBUG_INFO = YES;
492493
ONLY_ACTIVE_ARCH = YES;
494+
PRODUCT_BUNDLE_IDENTIFIER = "me.davidroman.$(PRODUCT_NAME:rfc1034identifier)";
493495
PRODUCT_NAME = "$(TARGET_NAME)";
494496
PROVISIONING_PROFILE = "";
495497
SDKROOT = iphoneos;
@@ -533,6 +535,7 @@
533535
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
534536
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
535537
MTL_ENABLE_DEBUG_INFO = NO;
538+
PRODUCT_BUNDLE_IDENTIFIER = "me.davidroman.$(PRODUCT_NAME:rfc1034identifier)";
536539
PRODUCT_NAME = "$(TARGET_NAME)";
537540
PROVISIONING_PROFILE = "";
538541
SDKROOT = iphoneos;
@@ -589,6 +592,7 @@
589592
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
590593
MTL_ENABLE_DEBUG_INFO = YES;
591594
ONLY_ACTIVE_ARCH = YES;
595+
PRODUCT_BUNDLE_IDENTIFIER = "me.davidroman.$(PRODUCT_NAME:rfc1034identifier)";
592596
PRODUCT_NAME = "$(TARGET_NAME)";
593597
PROVISIONING_PROFILE = "";
594598
SDKROOT = iphoneos;
@@ -640,6 +644,7 @@
640644
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
641645
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
642646
MTL_ENABLE_DEBUG_INFO = NO;
647+
PRODUCT_BUNDLE_IDENTIFIER = "me.davidroman.$(PRODUCT_NAME:rfc1034identifier)";
643648
PRODUCT_NAME = "$(TARGET_NAME)";
644649
PROVISIONING_PROFILE = "";
645650
SDKROOT = iphoneos;

Bohr.xcodeproj/xcshareddata/xcschemes/Bohr.xcscheme

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0640"
3+
LastUpgradeVersion = "0700"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -23,21 +23,24 @@
2323
</BuildActionEntries>
2424
</BuildAction>
2525
<TestAction
26+
buildConfiguration = "Debug"
2627
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2728
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
28-
shouldUseLaunchSchemeArgsEnv = "YES"
29-
buildConfiguration = "Debug">
29+
shouldUseLaunchSchemeArgsEnv = "YES">
3030
<Testables>
3131
</Testables>
32+
<AdditionalOptions>
33+
</AdditionalOptions>
3234
</TestAction>
3335
<LaunchAction
36+
buildConfiguration = "Debug"
3437
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
3538
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
3639
launchStyle = "0"
3740
useCustomWorkingDirectory = "NO"
38-
buildConfiguration = "Debug"
3941
ignoresPersistentStateOnLaunch = "NO"
4042
debugDocumentVersioning = "YES"
43+
debugServiceExtension = "internal"
4144
allowLocationSimulation = "YES">
4245
<MacroExpansion>
4346
<BuildableReference
@@ -52,10 +55,10 @@
5255
</AdditionalOptions>
5356
</LaunchAction>
5457
<ProfileAction
58+
buildConfiguration = "Release"
5559
shouldUseLaunchSchemeArgsEnv = "YES"
5660
savedToolIdentifier = ""
5761
useCustomWorkingDirectory = "NO"
58-
buildConfiguration = "Release"
5962
debugDocumentVersioning = "YES">
6063
<MacroExpansion>
6164
<BuildableReference

Bohr/BOTableViewCell.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
/// An optional destination view controller to push when the cell is pressed.
3333
@property (nonatomic) UIViewController *destinationViewController;
3434

35+
/// An optional key in order to determine whether the cell should be visible or not depending on its value.
36+
@property (nonatomic) NSString *visibilityKey;
37+
38+
/// A block determining whether the cell should be visible or not.
39+
@property (nonatomic, copy) BOOL (^visibilityBlock)(id settingValue);
40+
3541
/** Initializes a new BOTableViewCell object.
3642
*
3743
* @param title The cell title.

Bohr/BOTableViewController.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
@interface BOTableViewController ()
1717

18+
@property (nonatomic, copy) NSArray *lastSections;
1819
@property (nonatomic) NSArray *sections;
1920
@property (nonatomic) NSArray *footerViews;
2021

@@ -150,6 +151,32 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
150151
}
151152

152153
- (void)reloadTableView {
154+
155+
#pragma mark Dynamic options
156+
157+
NSMutableIndexSet *affectedIndexes = [NSMutableIndexSet new];
158+
159+
for (NSInteger s = 0; s < self.tableView.numberOfSections; s++) {
160+
NSInteger numberOfRows = [self.tableView numberOfRowsInSection:s];
161+
162+
if (numberOfRows != [self.sections[s] cells].count) {
163+
[affectedIndexes addIndex:s];
164+
} else {
165+
for (NSInteger r = 0; r < numberOfRows; r++) {
166+
UITableViewCell *lastCell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:r inSection:s]];
167+
if (![[self.sections[s] cells] containsObject:lastCell]) {
168+
[affectedIndexes addIndex:s];
169+
}
170+
}
171+
}
172+
}
173+
174+
if (affectedIndexes.count > 0) {
175+
[self.tableView beginUpdates];
176+
[self.tableView reloadSections:affectedIndexes withRowAnimation:UITableViewRowAnimationFade];
177+
[self.tableView endUpdates];
178+
}
179+
153180
[UIView performWithoutAnimation:^{
154181
CGPoint previousContentOffset = self.tableView.contentOffset;
155182
[self.tableView beginUpdates];

Bohr/BOTableViewSection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/// The footer title color of the section.
3131
@property (nonatomic) UIFont *footerTitleFont MZ_APPEARANCE_SELECTOR;
3232

33-
/// The cells for the section.
33+
/// The visible cells in the section.
3434
@property (nonatomic, readonly) NSArray *cells;
3535

3636
/** Initializes a new BOTableViewSection object.

Bohr/BOTableViewSection.m

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
@interface BOTableViewSection ()
1212

13+
@property (nonatomic) NSArray *rawCells;
1314
@property (nonatomic) NSArray *cells;
1415

1516
@end
@@ -22,9 +23,9 @@ + (instancetype)appearance {
2223

2324
- (instancetype)init {
2425
if (self = [super init]) {
25-
self.cells = [NSArray new];
26+
self.rawCells = [NSArray new];
2627
// Workaround to UITableViewHeaderFooterView's default 0-sized font driving iOS 9 nuts (yeah, WTF Apple).
27-
self.footerTitleFont = [UIFont fontWithName:@"Helvetica" size:13];
28+
self.footerTitleFont = [UIFont systemFontOfSize:13];
2829
// I mean, really, if you...
2930
// NSLog(@"%@", [UITableViewHeaderFooterView new].textLabel.font);
3031
// you get "font-size: 0.00pt".
@@ -50,7 +51,17 @@ + (instancetype)sectionWithHeaderTitle:(NSString *)headerTitle handler:(void (^)
5051
}
5152

5253
- (void)addCell:(BOTableViewCell *)cell {
53-
self.cells = [self.cells arrayByAddingObject:cell];
54+
self.rawCells = [self.rawCells arrayByAddingObject:cell];
55+
}
56+
57+
- (NSArray *)cells {
58+
return [self.rawCells filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(BOTableViewCell *cell, NSDictionary<NSString *,id> *bindings) {
59+
if (cell.visibilityKey.length > 0) {
60+
return cell.visibilityBlock([[NSUserDefaults standardUserDefaults] objectForKey:cell.visibilityKey]);
61+
}
62+
63+
return YES;
64+
}]];
5465
}
5566

5667
@end

Bohr/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>CFBundleExecutable</key>
88
<string>$(EXECUTABLE_NAME)</string>
99
<key>CFBundleIdentifier</key>
10-
<string>me.davidroman.$(PRODUCT_NAME:rfc1034identifier)</string>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1111
<key>CFBundleInfoDictionaryVersion</key>
1212
<string>6.0</string>
1313
<key>CFBundleName</key>

BohrDemo/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>CFBundleExecutable</key>
88
<string>$(EXECUTABLE_NAME)</string>
99
<key>CFBundleIdentifier</key>
10-
<string>me.davidroman.$(PRODUCT_NAME:rfc1034identifier)</string>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1111
<key>CFBundleInfoDictionaryVersion</key>
1212
<string>6.0</string>
1313
<key>CFBundleName</key>

BohrDemo/TableViewController.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ - (void)setup {
1818

1919
[section addCell:[BOSwitchTableViewCell cellWithTitle:@"Switch 1" key:@"bool_1" handler:nil]];
2020

21-
[section addCell:[BOSwitchTableViewCell cellWithTitle:@"Switch 2" key:@"bool_2" handler:^(BOSwitchTableViewCell *cell) {
21+
[section addCell:[BOSwitchTableViewCell cellWithTitle:@"Switch 2 (dependant on switch 1)" key:@"bool_2" handler:^(BOSwitchTableViewCell *cell) {
22+
cell.visibilityKey = @"bool_1";
23+
cell.visibilityBlock = ^BOOL(id settingValue) {
24+
return [settingValue boolValue];
25+
};
2226
cell.onFooterTitle = @"Switch setting 2 is on";
2327
cell.offFooterTitle = @"Switch setting 2 is off";
2428
}]];

0 commit comments

Comments
 (0)