From 8e297c925a8502fb0d42fc264b9be7cd2a11553d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvis=20Nu=C3=B1ez?= Date: Sun, 13 Nov 2016 11:01:35 +0100 Subject: [PATCH] Use Switch instead of Toggle --- Demo.xcodeproj/project.pbxproj | 28 +++++----- .../xcshareddata/xcschemes/Tests.xcscheme | 2 +- ...oggleFieldCell.h => FORMSwitchFieldCell.h} | 4 +- ...oggleFieldCell.m => FORMSwitchFieldCell.m} | 52 +++++++++---------- Source/FORMDataSource.m | 8 +-- Source/FORMDefaultStyle.m | 6 +-- Source/Models/FORMField.h | 2 +- Source/Models/FORMField.m | 8 +-- Tests/FORMDataSourceTests.m | 14 ++--- Tests/FORMDataTests.m | 10 ++-- Tests/FORMFieldTests.m | 12 ++--- Tests/JSONs/styled-fields.json | 6 +-- .../{toggle-field.json => switch-field.json} | 6 +-- 13 files changed, 79 insertions(+), 79 deletions(-) rename Source/Cells/Switch/{FORMToggleFieldCell.h => FORMSwitchFieldCell.h} (58%) rename Source/Cells/Switch/{FORMToggleFieldCell.m => FORMSwitchFieldCell.m} (50%) rename Tests/JSONs/{toggle-field.json => switch-field.json} (75%) diff --git a/Demo.xcodeproj/project.pbxproj b/Demo.xcodeproj/project.pbxproj index e5aff188..f85919f0 100644 --- a/Demo.xcodeproj/project.pbxproj +++ b/Demo.xcodeproj/project.pbxproj @@ -150,8 +150,8 @@ 42ED55BB3985830447C7EC6F /* Pods_CocoaPods_Basic_ObjC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 07A98696E9AE57AA5ED35615 /* Pods_CocoaPods_Basic_ObjC.framework */; }; 43B5CBB8974CFFEFAD7535CE /* Pods_CocoaPods_Payment.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3841465E0BCB95DB9D521885 /* Pods_CocoaPods_Payment.framework */; }; 739F1D308833B568F7E3EDCF /* Pods_CocoaPods_iPhone_Storyboard.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6283A96200ECA336FF064FA2 /* Pods_CocoaPods_iPhone_Storyboard.framework */; }; - 7A1D3E391DD78E2A0002C33C /* FORMToggleFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A1D3E381DD78E2A0002C33C /* FORMToggleFieldCell.m */; }; - 7A1D3E3B1DD7A1570002C33C /* toggle-field.json in Resources */ = {isa = PBXBuildFile; fileRef = 7A1D3E3A1DD7A1570002C33C /* toggle-field.json */; }; + 7A1D3E391DD78E2A0002C33C /* FORMSwitchFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A1D3E381DD78E2A0002C33C /* FORMSwitchFieldCell.m */; }; + 7A1D3E3B1DD7A1570002C33C /* switch-field.json in Resources */ = {isa = PBXBuildFile; fileRef = 7A1D3E3A1DD7A1570002C33C /* switch-field.json */; }; 7A41ADEF1DABE0EB0063DB62 /* FORMSegmentFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A41ADEE1DABE0EB0063DB62 /* FORMSegmentFieldCell.m */; }; 7A41ADF11DAC2FCD0063DB62 /* segment-field.json in Resources */ = {isa = PBXBuildFile; fileRef = 7A41ADF01DAC2FCD0063DB62 /* segment-field.json */; }; 7A4ABAF31D7DBE7200DAE893 /* FORMSpacerFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A4ABAF21D7DBE7200DAE893 /* FORMSpacerFieldCell.m */; }; @@ -398,9 +398,9 @@ 71ED68BA8DBA9D8DEB2F1288 /* Pods-CocoaPods-LoginDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CocoaPods-LoginDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CocoaPods-LoginDemo/Pods-CocoaPods-LoginDemo.debug.xcconfig"; sourceTree = ""; }; 729E65C530FAEB51178E6C77 /* Pods-CocoaPods-Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CocoaPods-Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-CocoaPods-Tests/Pods-CocoaPods-Tests.release.xcconfig"; sourceTree = ""; }; 7313DABFEEF45FCCCD39281E /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 7A1D3E371DD78E2A0002C33C /* FORMToggleFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FORMToggleFieldCell.h; path = Switch/FORMToggleFieldCell.h; sourceTree = ""; }; - 7A1D3E381DD78E2A0002C33C /* FORMToggleFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FORMToggleFieldCell.m; path = Switch/FORMToggleFieldCell.m; sourceTree = ""; }; - 7A1D3E3A1DD7A1570002C33C /* toggle-field.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "toggle-field.json"; sourceTree = ""; }; + 7A1D3E371DD78E2A0002C33C /* FORMSwitchFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FORMSwitchFieldCell.h; path = Switch/FORMSwitchFieldCell.h; sourceTree = ""; }; + 7A1D3E381DD78E2A0002C33C /* FORMSwitchFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FORMSwitchFieldCell.m; path = Switch/FORMSwitchFieldCell.m; sourceTree = ""; }; + 7A1D3E3A1DD7A1570002C33C /* switch-field.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "switch-field.json"; sourceTree = ""; }; 7A41ADED1DABE0EB0063DB62 /* FORMSegmentFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FORMSegmentFieldCell.h; path = Switch/FORMSegmentFieldCell.h; sourceTree = ""; }; 7A41ADEE1DABE0EB0063DB62 /* FORMSegmentFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FORMSegmentFieldCell.m; path = Switch/FORMSegmentFieldCell.m; sourceTree = ""; }; 7A41ADF01DAC2FCD0063DB62 /* segment-field.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "segment-field.json"; sourceTree = ""; }; @@ -586,7 +586,7 @@ 140803641BEA50AB0098C288 /* Cells */ = { isa = PBXGroup; children = ( - 7A1D3E361DD78DF10002C33C /* Toggle */, + 7A1D3E361DD78DF10002C33C /* Switch */, 7A41ADE91DABD2930063DB62 /* Segment */, 7AB346BD1D78C83100AAAD2E /* Spacer */, 140803651BEA50AB0098C288 /* Base */, @@ -784,7 +784,7 @@ 1408042B1BEA50C00098C288 /* simple-section.json */, 1408042C1BEA50C00098C288 /* simple-text-field.json */, 1408042D1BEA50C00098C288 /* styled-fields.json */, - 7A1D3E3A1DD7A1570002C33C /* toggle-field.json */, + 7A1D3E3A1DD7A1570002C33C /* switch-field.json */, ); path = JSONs; sourceTree = ""; @@ -1012,13 +1012,13 @@ name = Frameworks; sourceTree = ""; }; - 7A1D3E361DD78DF10002C33C /* Toggle */ = { + 7A1D3E361DD78DF10002C33C /* Switch */ = { isa = PBXGroup; children = ( - 7A1D3E371DD78E2A0002C33C /* FORMToggleFieldCell.h */, - 7A1D3E381DD78E2A0002C33C /* FORMToggleFieldCell.m */, + 7A1D3E371DD78E2A0002C33C /* FORMSwitchFieldCell.h */, + 7A1D3E381DD78E2A0002C33C /* FORMSwitchFieldCell.m */, ); - name = Toggle; + name = Switch; sourceTree = ""; }; 7A41ADE91DABD2930063DB62 /* Segment */ = { @@ -1233,7 +1233,7 @@ attributes = { CLASSPREFIX = ""; LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0810; ORGANIZATIONNAME = ""; TargetAttributes = { 1406BB791BEA520D00131623 = { @@ -1383,7 +1383,7 @@ 1408043F1BEA50C00098C288 /* collapsed-groups.json in Resources */, 7A41ADF11DAC2FCD0063DB62 /* segment-field.json in Resources */, 1408044E1BEA50C00098C288 /* simple-text-field.json in Resources */, - 7A1D3E3B1DD7A1570002C33C /* toggle-field.json in Resources */, + 7A1D3E3B1DD7A1570002C33C /* switch-field.json in Resources */, 1408044A1BEA50C00098C288 /* postal_codes.json in Resources */, 1408044C1BEA50C00098C288 /* simple-number-field.json in Resources */, 140804401BEA50C00098C288 /* counter-field.json in Resources */, @@ -1867,7 +1867,7 @@ 140804001BEA50AB0098C288 /* DDMathEvaluator+FORM.m in Sources */, 140803E81BEA50AB0098C288 /* FORMData.m in Sources */, 140803DB1BEA50AB0098C288 /* FORMPopoverFieldCell.m in Sources */, - 7A1D3E391DD78E2A0002C33C /* FORMToggleFieldCell.m in Sources */, + 7A1D3E391DD78E2A0002C33C /* FORMSwitchFieldCell.m in Sources */, 140803F41BEA50AB0098C288 /* FORMNameInputValidator.m in Sources */, 1408043C1BEA50C00098C288 /* FORMValidatorTests.m in Sources */, 140804381BEA50C00098C288 /* FORMSectionTests.m in Sources */, diff --git a/Demo.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/Demo.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index bccce122..779edb74 100644 --- a/Demo.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/Demo.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ 0) { - self.toggle.accessibilityLabel = field.accessibilityLabel; + self.switchControl.accessibilityLabel = field.accessibilityLabel; } else { - self.toggle.accessibilityLabel = self.headingLabel.text; + self.switchControl.accessibilityLabel = self.headingLabel.text; } } @@ -53,13 +53,13 @@ - (void)updateWithField:(FORMField *)field { - (void)layoutSubviews { [super layoutSubviews]; - self.toggle.frame = [self toggleFrame]; + self.switchControl.frame = [self switchFrame]; } -- (CGRect)toggleFrame { +- (CGRect)switchFrame { CGFloat marginX = FORMTextFieldCellMarginX; - CGFloat marginTop = FORMToggleFieldCellMarginTop; - CGFloat marginBotton = FORMToggleFieldCellMarginBottom; + CGFloat marginTop = FORMSwitchFieldCellMarginTop; + CGFloat marginBotton = FORMSwitchFieldCellMarginBottom; CGFloat width = CGRectGetWidth(self.frame) - (marginX * 2); CGFloat height = CGRectGetHeight(self.frame) - marginTop - marginBotton; @@ -70,7 +70,7 @@ - (CGRect)toggleFrame { #pragma mark - Actions -- (void)toggleAction:(id)sender { +- (void)switchAction:(id)sender { self.field.value = [sender isOn] ? @YES : @NO; if ([self.delegate respondsToSelector:@selector(fieldCell:updatedWithField:)]) { @@ -81,21 +81,21 @@ - (void)toggleAction:(id)sender { #pragma mark - Styling - (void)setTintColor:(UIColor *)tintColor { - NSString *style = [self.field.styles valueForKey:FORMToggleTintColorKey]; + NSString *style = [self.field.styles valueForKey:FORMSwitchTintColorKey]; if ([style length] > 0) { tintColor = [[UIColor alloc] initWithHex:style]; } - self.toggle.onTintColor = tintColor; + self.switchControl.onTintColor = tintColor; } - (void)setBackgroundColor:(UIColor *)backgroundColor { - NSString *style = [self.field.styles valueForKey:FORMToggleBackgroundColorKey]; + NSString *style = [self.field.styles valueForKey:FORMSwitchBackgroundColorKey]; if ([style length] > 0) { backgroundColor = [[UIColor alloc] initWithHex:style]; } - self.toggle.backgroundColor = backgroundColor; + self.switchControl.backgroundColor = backgroundColor; } @end diff --git a/Source/FORMDataSource.m b/Source/FORMDataSource.m index f4a71dcf..7f672c43 100755 --- a/Source/FORMDataSource.m +++ b/Source/FORMDataSource.m @@ -9,7 +9,7 @@ #import "FORMButtonFieldCell.h" #import "FORMSpacerFieldCell.h" #import "FORMSegmentFieldCell.h" -#import "FORMToggleFieldCell.h" +#import "FORMSwitchFieldCell.h" #import "FORMFieldValue.h" #import "HYPParsedRelationship.h" @@ -196,9 +196,9 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView forCellWithReuseIdentifier:identifier]; break; - case FORMFieldTypeToggle: - identifier = [NSString stringWithFormat:@"%@-%@", FORMToggleFieldCellIdentifier, field.fieldID]; - [collectionView registerClass:[FORMToggleFieldCell class] + case FORMFieldTypeSwitch: + identifier = [NSString stringWithFormat:@"%@-%@", FORMSwitchFieldCellIdentifier, field.fieldID]; + [collectionView registerClass:[FORMSwitchFieldCell class] forCellWithReuseIdentifier:identifier]; break; diff --git a/Source/FORMDefaultStyle.m b/Source/FORMDefaultStyle.m index 3070bbdb..0e08e0fd 100755 --- a/Source/FORMDefaultStyle.m +++ b/Source/FORMDefaultStyle.m @@ -10,7 +10,7 @@ #import "FORMTextFieldCell.h" #import "FORMButtonFieldCell.h" #import "FORMSegmentFieldCell.h" -#import "FORMToggleFieldCell.h" +#import "FORMSwitchFieldCell.h" #import "FORMBaseFieldCell.h" @import Hex; @@ -107,8 +107,8 @@ + (void)applyStyle { [[FORMSegmentFieldCell appearance] setBackgroundColor:[[UIColor alloc] initWithHex:@"FFFFFF"]]; [[FORMSegmentFieldCell appearance] setTintColor:[[UIColor alloc] initWithHex:@"3DAFEB"]]; - [[FORMToggleFieldCell appearance] setBackgroundColor:[[UIColor alloc] initWithHex:@"FFFFFF"]]; - [[FORMToggleFieldCell appearance] setTintColor:[[UIColor alloc] initWithHex:@"3DAFEB"]]; + [[FORMSwitchFieldCell appearance] setBackgroundColor:[[UIColor alloc] initWithHex:@"FFFFFF"]]; + [[FORMSwitchFieldCell appearance] setTintColor:[[UIColor alloc] initWithHex:@"3DAFEB"]]; } diff --git a/Source/Models/FORMField.h b/Source/Models/FORMField.h index ef39da5a..dfc242b2 100755 --- a/Source/Models/FORMField.h +++ b/Source/Models/FORMField.h @@ -19,7 +19,7 @@ typedef NS_ENUM(NSInteger, FORMFieldType) { FORMFieldTypeSpacer, FORMFieldTypeCount, FORMFieldTypeSegment, - FORMFieldTypeToggle, + FORMFieldTypeSwitch, FORMFieldTypeCustom }; diff --git a/Source/Models/FORMField.m b/Source/Models/FORMField.m index 74af3c55..722ff783 100755 --- a/Source/Models/FORMField.m +++ b/Source/Models/FORMField.m @@ -141,7 +141,7 @@ - (void)setValue:(id)fieldValue { case FORMFieldTypeButton: case FORMFieldTypeSpacer: case FORMFieldTypeSegment: - case FORMFieldTypeToggle: + case FORMFieldTypeSwitch: case FORMFieldTypeCustom: break; } @@ -183,7 +183,7 @@ - (id)rawFieldValue { case FORMFieldTypeButton: case FORMFieldTypeSpacer: case FORMFieldTypeSegment: - case FORMFieldTypeToggle: + case FORMFieldTypeSwitch: case FORMFieldTypeCustom: return nil; } @@ -259,8 +259,8 @@ - (FORMFieldType)typeFromTypeString:(NSString *)typeString { return FORMFieldTypeSpacer; } else if ([typeString isEqualToString:@"segment"]) { return FORMFieldTypeSegment; - } else if ([typeString isEqualToString:@"toggle"]) { - return FORMFieldTypeToggle; + } else if ([typeString isEqualToString:@"switch"]) { + return FORMFieldTypeSwitch; } else { return FORMFieldTypeCustom; } diff --git a/Tests/FORMDataSourceTests.m b/Tests/FORMDataSourceTests.m index 176a7806..ce57f6fe 100755 --- a/Tests/FORMDataSourceTests.m +++ b/Tests/FORMDataSourceTests.m @@ -947,14 +947,14 @@ - (void)testStyleFields { XCTAssertEqualObjects([segmentField.styles objectForKey:@"font"], @"AvenirNext-DemiBold"); XCTAssertEqualObjects([segmentField.styles objectForKey:@"font_size"], @"16.0"); - // Toggle Field Styles - FORMField *toggleField = [dataSource fieldWithID:@"styled_toggle" includingHiddenFields:NO]; - XCTAssertNotNil(toggleField); + // Switch Field Styles + FORMField *switchField = [dataSource fieldWithID:@"styled_switch" includingHiddenFields:NO]; + XCTAssertNotNil(switchField); - [dataSource fieldCell:nil updatedWithField:toggleField]; - XCTAssertNotNil(toggleField.styles); - XCTAssertEqualObjects([toggleField.styles objectForKey:@"tint_color"], @"#FF0000"); - XCTAssertEqualObjects([toggleField.styles objectForKey:@"background_color"], @"#FFFFFF"); + [dataSource fieldCell:nil updatedWithField:switchField]; + XCTAssertNotNil(switchField.styles); + XCTAssertEqualObjects([switchField.styles objectForKey:@"tint_color"], @"#FF0000"); + XCTAssertEqualObjects([switchField.styles objectForKey:@"background_color"], @"#FFFFFF"); // Text Field Styles FORMField *textField = [dataSource fieldWithID:@"styled_text_field" includingHiddenFields:NO]; diff --git a/Tests/FORMDataTests.m b/Tests/FORMDataTests.m index aece7847..9bab8308 100755 --- a/Tests/FORMDataTests.m +++ b/Tests/FORMDataTests.m @@ -824,8 +824,8 @@ - (void)testInitializatingASegmentFieldWithAValueInTheJSON { XCTAssertEqualObjects(formData.values[@"segment"], @"part_1"); } -- (void)testInitializatingAToggleFieldWithAValueInTheJSON { - NSArray *JSON = [NSJSONSerialization JSONObjectWithContentsOfFile:@"toggle-field.json" +- (void)testInitializatingASwitchFieldWithAValueInTheJSON { + NSArray *JSON = [NSJSONSerialization JSONObjectWithContentsOfFile:@"switch-field.json" inBundle:[NSBundle bundleForClass:[self class]]]; FORMData *formData = [[FORMData alloc] initWithJSON:JSON @@ -833,7 +833,7 @@ - (void)testInitializatingAToggleFieldWithAValueInTheJSON { disabledFieldIDs:nil disabled:NO]; - XCTAssertEqualObjects(formData.values[@"toggle"], @YES); + XCTAssertEqualObjects(formData.values[@"switch"], @YES); } - (void)testFieldStyles { @@ -874,8 +874,8 @@ - (void)testFieldStyles { XCTAssertEqualObjects([field.styles objectForKey:@"font"], @"AvenirNext-DemiBold"); XCTAssertEqualObjects([field.styles objectForKey:@"font_size"], @"16.0"); - // Toggle Styles - field = [formData fieldWithID:@"styled_toggle" includingHiddenFields:NO]; + // Switch Styles + field = [formData fieldWithID:@"styled_switch" includingHiddenFields:NO]; XCTAssertNotNil(field); XCTAssertNotNil(field.styles); diff --git a/Tests/FORMFieldTests.m b/Tests/FORMFieldTests.m index e6bb04d5..cb93c5e9 100755 --- a/Tests/FORMFieldTests.m +++ b/Tests/FORMFieldTests.m @@ -187,20 +187,20 @@ - (void)testInitWithDictionary { XCTAssertNil(field.validation); XCTAssertFalse(field.hidden); - field = [[FORMField alloc] initWithDictionary:@{@"id": @"toggle_control", - @"title": @"Toggle Control", + field = [[FORMField alloc] initWithDictionary:@{@"id": @"switch_control", + @"title": @"Switch Control", @"accessibility_label": @"Accessibility label", - @"type": @"toggle", + @"type": @"switch", @"value": @YES, @"size": @{@"width": @30, @"height": @1} } position:1 disabled:NO - disabledFieldsIDs:@[@"toggle_control"]]; + disabledFieldsIDs:@[@"switch_control"]]; XCTAssertNotNil(field); - XCTAssertEqualObjects(field.typeString, @"toggle"); - XCTAssertTrue(field.type == FORMFieldTypeToggle); + XCTAssertEqualObjects(field.typeString, @"switch"); + XCTAssertTrue(field.type == FORMFieldTypeSwitch); XCTAssertEqualObjects(field.value, @YES); XCTAssertEqualObjects(field.accessibilityLabel, @"Accessibility label"); diff --git a/Tests/JSONs/styled-fields.json b/Tests/JSONs/styled-fields.json index 0a6ed732..ee047cb6 100755 --- a/Tests/JSONs/styled-fields.json +++ b/Tests/JSONs/styled-fields.json @@ -112,9 +112,9 @@ }, }, { - "id":"styled_toggle", - "title":"Styled Toggle", - "type":"toggle", + "id":"styled_switch", + "title":"Styled Switch", + "type":"switch", "styles":{ "background_color":"#FFFFFF", "tint_color":"#FF0000" diff --git a/Tests/JSONs/toggle-field.json b/Tests/JSONs/switch-field.json similarity index 75% rename from Tests/JSONs/toggle-field.json rename to Tests/JSONs/switch-field.json index 14bb687b..c81e80de 100755 --- a/Tests/JSONs/toggle-field.json +++ b/Tests/JSONs/switch-field.json @@ -7,9 +7,9 @@ "id": "section", "fields": [ { - "id": "toggle", - "title": "My Toggle", - "type": "toggle", + "id": "switch", + "title": "My Switch", + "type": "switch", "value": true, "size": { "width": 25,