Skip to content

Commit

Permalink
Move selection inversion logic from setSelect to touchUpInside for mu…
Browse files Browse the repository at this point in the history
…ltiple selection buttons; Break otherButtons retain cycle
  • Loading branch information
DavydLiu committed Apr 19, 2018
1 parent a2b0eb1 commit ddfd531
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 33 deletions.
18 changes: 9 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/

## Various settings
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
Expand All @@ -18,12 +24,6 @@ DerivedData/
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

---

## [1.4.12](https://github.com/DavydLiu/DLRadioButton/releases/tag/1.4.12) (04/19/2018)
* Move selection inversion logic from `setSelect` to `touchUpInside` for multiple selection buttons
* Break otherButtons retain cycle

## [1.4.11](https://github.com/DavydLiu/DLRadioButton/releases/tag/1.4.11) (10/09/2017)
* Fix disconnected action responders in Swift example.

Expand Down
4 changes: 2 additions & 2 deletions DLRadioButton.podspec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "DLRadioButton",
"version": "1.4.11",
"version": "1.4.12",
"summary": "A highly customizable Radio Button for iOS",
"description": "A highly customizable Radio Button for iOS.\n\n* Buttons are drew by UIBezierPath, customize it however you want.\n* You can also use pictures to indicate buttons' selection state.\n",
"homepage": "https://github.com/DavydLiu/DLRadioButton",
Expand All @@ -17,7 +17,7 @@
},
"source": {
"git": "https://github.com/DavydLiu/DLRadioButton.git",
"tag": "1.4.11"
"tag": "1.4.12"
},
"source_files": "DLRadioButton/**/*.{h,m}",
"exclude_files": "Classes/Exclude",
Expand Down
6 changes: 5 additions & 1 deletion DLRadioButton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
634D5B511C5D8B0F00A3740D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0900;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "David Liu";
TargetAttributes = {
634D5B591C5D8B0F00A3740D = {
Expand Down Expand Up @@ -274,13 +274,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -330,13 +332,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -56,7 +55,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
35 changes: 26 additions & 9 deletions DLRadioButton/DLRadioButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

@implementation DLRadioButton

@synthesize otherButtons = _otherButtons;

- (void)setOtherButtons:(NSArray *)otherButtons {
if (![DLRadioButton isGroupModifing]) {
[DLRadioButton groupModifing:YES];
Expand All @@ -20,7 +22,22 @@ - (void)setOtherButtons:(NSArray *)otherButtons {
}
[DLRadioButton groupModifing:NO];
}
_otherButtons = otherButtons;
NSMutableArray *otherButtonsForCurrentButton = [[NSMutableArray alloc] initWithCapacity:otherButtons.count];
for (DLRadioButton *radioButton in otherButtons) {
[otherButtonsForCurrentButton addObject:[NSValue valueWithNonretainedObject:radioButton]];
}
_otherButtons = [otherButtonsForCurrentButton copy];
}

- (NSArray *)otherButtons {
if ([_otherButtons count]) {
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:[_otherButtons count]];
for (NSValue *value in _otherButtons) {
[buttons addObject:[value nonretainedObjectValue]];
}
return buttons;
}
return nil;
}

- (void)setIcon:(UIImage *)icon {
Expand Down Expand Up @@ -135,7 +152,11 @@ - (UIImage *)drawIconWithSelection:(BOOL)selected {
}

- (void)touchUpInside {
[self setSelected:YES];
if (self.isMultipleSelectionEnabled) {
[self setSelected:!self.isSelected];
} else {
[self setSelected:YES];
}
}

- (void)initRadioButton {
Expand Down Expand Up @@ -229,13 +250,9 @@ - (void)setSelected:(BOOL)selected {
[self.imageView.layer addAnimation:animation forKey:@"icon"];
}

if (self.isMultipleSelectionEnabled) {
[super setSelected:!self.isSelected];
} else {
[super setSelected:selected];
if (selected) {
[self deselectOtherButtons];
}
[super setSelected:selected];
if (!self.isMultipleSelectionEnabled && selected) {
[self deselectOtherButtons];
}
}

Expand Down
7 changes: 0 additions & 7 deletions DLRadioButtonTests/DLRadioButtonTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ - (void)testMultipleButtonsSelection {
XCTAssertFalse([[self.firstButton selectedButtons] containsObject:self.firstButton]);
XCTAssertTrue([[self.firstButton selectedButtons] containsObject:self.secondButton]);
XCTAssertTrue([[self.firstButton selectedButtons] containsObject:self.thirdButton]);

// first and second button should be selected.
[self.firstButton setSelected:YES];
[self.thirdButton setSelected:YES];
XCTAssertTrue([[self.secondButton selectedButtons] containsObject:self.firstButton]);
XCTAssertTrue([[self.secondButton selectedButtons] containsObject:self.secondButton]);
XCTAssertFalse([[self.secondButton selectedButtons] containsObject:self.thirdButton]);
}

- (void)testButtonsGroupModifingPerformance {
Expand Down
Binary file modified Example/DLRadioButton.framework/DLRadioButton
Binary file not shown.
Binary file modified Example/DLRadioButton.framework/Info.plist
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</data>
<key>Info.plist</key>
<data>
H2f+pX210ZzH8k+DltNm5269P9w=
h5EbFNLfZfsX9O854CrDq9aZ9qo=
</data>
<key>Modules/module.modulemap</key>
<data>
Expand Down
6 changes: 5 additions & 1 deletion Example/DLRadioButtonExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
attributes = {
CLASSPREFIX = DL;
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "Xingruo Liu";
TargetAttributes = {
D1BE39FE19A7D263004BD3F5 = {
Expand Down Expand Up @@ -232,12 +232,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -284,12 +286,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
6 changes: 6 additions & 0 deletions Example/DLRadioButtonExample/DLDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ - (void)viewDidLoad {

// enable multiple selection for water, beer and wine buttons.
self.waterButton.multipleSelectionEnabled = YES;
// set selection states programmatically
for (DLRadioButton *radioButton in self.waterButton.otherButtons) {
radioButton.selected = YES;
}

// programmatically add button
// first button
Expand Down Expand Up @@ -46,6 +50,8 @@ - (void)viewDidLoad {
}

firstRadioButton.otherButtons = otherButtons;
// set selection state programmatically
firstRadioButton.otherButtons[1].selected = YES;
}

#pragma mark - Helper
Expand Down
6 changes: 6 additions & 0 deletions Example/DLRadioButtonExample/DemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class DemoViewController : UIViewController {

// enable multiple selection for water, beer and wine buttons.
self.waterButton.isMultipleSelectionEnabled = true;
// set selection states programmatically
for radioButton in self.waterButton.otherButtons {
radioButton.isSelected = true;
}

// programmatically add buttons
// first button
Expand Down Expand Up @@ -36,6 +40,8 @@ class DemoViewController : UIViewController {
}

firstRadioButton.otherButtons = otherButtons;
// set selection state programmatically
firstRadioButton.otherButtons[1].isSelected = true;
}

// MARK: Helper
Expand Down

0 comments on commit ddfd531

Please sign in to comment.