Skip to content

Commit

Permalink
Define default item configuration on item directly (jjochen#121)
Browse files Browse the repository at this point in the history
Define default item configuration on item directly
  • Loading branch information
jjochen authored Jan 21, 2018
1 parent 64ff69e commit f014c12
Show file tree
Hide file tree
Showing 24 changed files with 866 additions and 394 deletions.
20 changes: 16 additions & 4 deletions Example/JJFloatingActionButton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
195269411FD7E53B0053C785 /* JJCircleViewSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1952693F1FD7E4CD0053C785 /* JJCircleViewSpec.swift */; };
195269431FD7E6200053C785 /* UIColorExtensionsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 195269421FD7E6200053C785 /* UIColorExtensionsSpec.swift */; };
195269451FD7E63B0053C785 /* JJActionItemSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 195269441FD7E63B0053C785 /* JJActionItemSpec.swift */; };
1957C8C6201282D500F1574B /* JJFloatingActionButtonAppearanceSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1957C8C42012815000F1574B /* JJFloatingActionButtonAppearanceSpec.swift */; };
1957C8C8201283EF00F1574B /* JJActionItemAppearanceSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1957C8C7201283EF00F1574B /* JJActionItemAppearanceSpec.swift */; };
1957C8CA20128AD200F1574B /* JJFloatingActionButtonDelegateSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1957C8C920128AD200F1574B /* JJFloatingActionButtonDelegateSpec.swift */; };
198B66011FBAE904009A17F2 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 198B66001FBAE904009A17F2 /* AppDelegate.swift */; };
198B66031FBAE904009A17F2 /* BasicsExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 198B66021FBAE904009A17F2 /* BasicsExampleViewController.swift */; };
198B66051FBAE904009A17F2 /* InterfaceBuilderExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 198B66041FBAE904009A17F2 /* InterfaceBuilderExampleViewController.swift */; };
Expand All @@ -23,7 +26,7 @@
198EA7E41FD73F6D00F7DA3E /* JJCircleView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 198EA7E31FD73F6D00F7DA3E /* JJCircleView.xib */; };
199592AC1FD73F070058BEFC /* JJFloatingActionButton.xib in Resources */ = {isa = PBXBuildFile; fileRef = 199592AB1FD73F070058BEFC /* JJFloatingActionButton.xib */; };
19B10AD81FFCEF0800D70C32 /* JJFloationgActionButtonDelegateMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19B10AD71FFCEF0800D70C32 /* JJFloationgActionButtonDelegateMock.swift */; };
19B10ADA1FFD1F5600D70C32 /* JJFloatingActionButtonPlacementSpecs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19B10AD91FFD1F5600D70C32 /* JJFloatingActionButtonPlacementSpecs.swift */; };
19B10ADA1FFD1F5600D70C32 /* JJFloatingActionButtonPlacementSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19B10AD91FFD1F5600D70C32 /* JJFloatingActionButtonPlacementSpec.swift */; };
19D311DD200F8A630023477D /* CircularPopExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19D311DC200F8A630023477D /* CircularPopExampleViewController.swift */; };
19E247E61FD7E6F6009A7BA1 /* JJActionItem.xib in Resources */ = {isa = PBXBuildFile; fileRef = 19E247E41FD7E6B5009A7BA1 /* JJActionItem.xib */; };
19E247E81FD83CA7009A7BA1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 198B66091FBAE904009A17F2 /* Assets.xcassets */; };
Expand Down Expand Up @@ -53,6 +56,9 @@
195269421FD7E6200053C785 /* UIColorExtensionsSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColorExtensionsSpec.swift; sourceTree = "<group>"; };
195269441FD7E63B0053C785 /* JJActionItemSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JJActionItemSpec.swift; sourceTree = "<group>"; };
195637221FDA9EFB0003B8FF /* config.yml */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = text; lineEnding = 0; name = config.yml; path = ../../.circleci/config.yml; sourceTree = "<group>"; tabWidth = 2; usesTabs = 0; };
1957C8C42012815000F1574B /* JJFloatingActionButtonAppearanceSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JJFloatingActionButtonAppearanceSpec.swift; sourceTree = "<group>"; };
1957C8C7201283EF00F1574B /* JJActionItemAppearanceSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JJActionItemAppearanceSpec.swift; sourceTree = "<group>"; };
1957C8C920128AD200F1574B /* JJFloatingActionButtonDelegateSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JJFloatingActionButtonDelegateSpec.swift; sourceTree = "<group>"; };
198B65FD1FBAE904009A17F2 /* JJFloatingActionButton_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JJFloatingActionButton_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
198B66001FBAE904009A17F2 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
198B66021FBAE904009A17F2 /* BasicsExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicsExampleViewController.swift; sourceTree = "<group>"; };
Expand All @@ -73,7 +79,7 @@
199592AB1FD73F070058BEFC /* JJFloatingActionButton.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = JJFloatingActionButton.xib; sourceTree = "<group>"; };
19B10AC21FF7BDDD00D70C32 /* .jazzy.yaml */ = {isa = PBXFileReference; lastKnownFileType = text; name = .jazzy.yaml; path = ../../.jazzy.yaml; sourceTree = "<group>"; };
19B10AD71FFCEF0800D70C32 /* JJFloationgActionButtonDelegateMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JJFloationgActionButtonDelegateMock.swift; sourceTree = "<group>"; };
19B10AD91FFD1F5600D70C32 /* JJFloatingActionButtonPlacementSpecs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JJFloatingActionButtonPlacementSpecs.swift; sourceTree = "<group>"; };
19B10AD91FFD1F5600D70C32 /* JJFloatingActionButtonPlacementSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JJFloatingActionButtonPlacementSpec.swift; sourceTree = "<group>"; };
19B10ADB1FFE692100D70C32 /* Rakefile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; fileEncoding = 4; indentWidth = 2; name = Rakefile; path = ../../Rakefile; sourceTree = "<group>"; tabWidth = 2; };
19D311DC200F8A630023477D /* CircularPopExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CircularPopExampleViewController.swift; sourceTree = "<group>"; };
19DF53B81FF59AE5006E292F /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Package.swift; path = ../../Package.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -153,8 +159,11 @@
198B66191FBAE904009A17F2 /* Info.plist */,
195269441FD7E63B0053C785 /* JJActionItemSpec.swift */,
1952693F1FD7E4CD0053C785 /* JJCircleViewSpec.swift */,
19B10AD91FFD1F5600D70C32 /* JJFloatingActionButtonPlacementSpecs.swift */,
19B10AD91FFD1F5600D70C32 /* JJFloatingActionButtonPlacementSpec.swift */,
198B66171FBAE904009A17F2 /* JJFloatingActionButtonSpec.swift */,
1957C8C920128AD200F1574B /* JJFloatingActionButtonDelegateSpec.swift */,
1957C8C42012815000F1574B /* JJFloatingActionButtonAppearanceSpec.swift */,
1957C8C7201283EF00F1574B /* JJActionItemAppearanceSpec.swift */,
195269421FD7E6200053C785 /* UIColorExtensionsSpec.swift */,
19B10ADD1FFFA83F00D70C32 /* Mocks */,
199592AA1FD73ED50058BEFC /* Resources */,
Expand Down Expand Up @@ -465,7 +474,10 @@
19B10AD81FFCEF0800D70C32 /* JJFloationgActionButtonDelegateMock.swift in Sources */,
195269411FD7E53B0053C785 /* JJCircleViewSpec.swift in Sources */,
195269431FD7E6200053C785 /* UIColorExtensionsSpec.swift in Sources */,
19B10ADA1FFD1F5600D70C32 /* JJFloatingActionButtonPlacementSpecs.swift in Sources */,
1957C8CA20128AD200F1574B /* JJFloatingActionButtonDelegateSpec.swift in Sources */,
19B10ADA1FFD1F5600D70C32 /* JJFloatingActionButtonPlacementSpec.swift in Sources */,
1957C8C6201282D500F1574B /* JJFloatingActionButtonAppearanceSpec.swift in Sources */,
1957C8C8201283EF00F1574B /* JJActionItemAppearanceSpec.swift in Sources */,
195269451FD7E63B0053C785 /* JJActionItemSpec.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,31 @@ internal class ConfigurationExampleViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

actionButton.overlayView.backgroundColor = UIColor(hue: 0.31, saturation: 0.37, brightness: 0.10, alpha: 0.30)
actionButton.buttonImage = #imageLiteral(resourceName: "Dots")
actionButton.buttonColor = .red
actionButton.defaultButtonImage = #imageLiteral(resourceName: "Dots")
actionButton.buttonOpeningStyle = .transition(image: #imageLiteral(resourceName: "X"))
actionButton.buttonImageColor = .white
actionButton.shadowColor = .black
actionButton.shadowOffset = CGSize(width: 0, height: 1)
actionButton.shadowOpacity = Float(0.5)
actionButton.shadowRadius = CGFloat(2)
actionButton.itemTitleFont = .boldSystemFont(ofSize: UIFont.systemFontSize)
actionButton.itemButtonColor = .white
actionButton.itemImageColor = .red
actionButton.itemTitleColor = .white
actionButton.itemShadowColor = .black
actionButton.itemShadowOffset = CGSize(width: 0, height: 1)
actionButton.itemShadowOpacity = Float(0.4)
actionButton.itemShadowRadius = CGFloat(2)
actionButton.itemSizeRatio = CGFloat(0.75)

actionButton.buttonOpeningStyle = .transition(image: #imageLiteral(resourceName: "X"))
actionButton.itemOpeningStyle = .popUp(interItemSpacing: 14)
actionButton.overlayView.backgroundColor = UIColor(hue: 0.31, saturation: 0.37, brightness: 0.10, alpha: 0.30)

actionButton.layer.shadowColor = UIColor.black.cgColor
actionButton.layer.shadowOffset = CGSize(width: 0, height: 1)
actionButton.layer.shadowOpacity = Float(0.4)
actionButton.layer.shadowRadius = CGFloat(2)

actionButton.itemSizeRatio = CGFloat(0.75)
actionButton.configureDefaultItem { item in
item.titleLabel.font = .boldSystemFont(ofSize: UIFont.systemFontSize)
item.titleLabel.textColor = .white
item.buttonColor = .white
item.buttonImageColor = .red

item.layer.shadowColor = UIColor.black.cgColor
item.layer.shadowOffset = CGSize(width: 0, height: 1)
item.layer.shadowOpacity = Float(0.4)
item.layer.shadowRadius = CGFloat(2)
}

actionButton.addItem(title: "Balloon", image: #imageLiteral(resourceName: "Baloon")) { item in
Helper.showAlert(for: item)
Expand All @@ -61,10 +67,10 @@ internal class ConfigurationExampleViewController: UIViewController {
}

let item3 = actionButton.addItem()
item3.circleView.color = .black
item3.imageView.image = #imageLiteral(resourceName: "Owl")
item3.imageView.tintColor = .white
item3.titleLabel.text = "Owl"
item3.imageView.image = #imageLiteral(resourceName: "Owl")
item3.buttonColor = .black
item3.buttonImageColor = .white
item3.action = { item in
Helper.showAlert(for: item)
}
Expand Down
143 changes: 143 additions & 0 deletions Example/Tests/JJActionItemAppearanceSpec.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
//
// JJActionItemAppearanceSpec.swift
//
// Copyright (c) 2017-Present Jochen Pfeiffer
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

import Foundation
@testable import JJFloatingActionButton
import Nimble
import Nimble_Snapshots
import Quick

class JJActionItemAppearanceSpec: QuickSpec {

override func spec() {

describe("JJActionItem") {

var item: JJActionItem!

beforeEach {
item = JJActionItem()
}

it("stores button image correctly") {
let value1 = #imageLiteral(resourceName: "Owl")
item.buttonImage = value1
expect(item.buttonImage) == value1
expect(item.imageView.image) == value1

let value2 = #imageLiteral(resourceName: "Like")
item.imageView.image = value2
expect(item.buttonImage) == value2
expect(item.imageView.image) == value2
}

it("stores button color correctly") {
let value1 = UIColor.red
item.buttonColor = value1
expect(item.buttonColor) == value1
expect(item.circleView.color) == value1

let value2 = UIColor.blue
item.circleView.color = value2
expect(item.buttonColor) == value2
expect(item.circleView.color) == value2
}

it("stores highlighted button color correctly") {
let value1 = UIColor.red
item.highlightedButtonColor = value1
expect(item.highlightedButtonColor) == value1
expect(item.circleView.highlightedColor) == value1

let value2 = UIColor.blue
item.circleView.highlightedColor = value2
expect(item.highlightedButtonColor) == value2
expect(item.circleView.highlightedColor) == value2
}

it("stores button image color correctly") {
let value1 = UIColor.red
item.buttonImageColor = value1
expect(item.buttonImageColor) == value1
expect(item.imageView.tintColor) == value1

let value2 = UIColor.blue
item.imageView.tintColor = value2
expect(item.buttonImageColor) == value2
expect(item.imageView.tintColor) == value2
}

it("stores shadow color correctly") {
let value1 = UIColor.red
item.shadowColor = value1
expect(item.shadowColor) == value1
expect(UIColor(cgColor: item.layer.shadowColor!)) == value1

let value2 = UIColor.blue
item.layer.shadowColor = value2.cgColor
expect(item.shadowColor) == value2
expect(UIColor(cgColor: item.layer.shadowColor!)) == value2

item.shadowColor = nil
expect(item.shadowColor).to(beNil())
}

it("stores shadow offset correctly") {
let value1 = CGSize(width: 2, height: 4)
item.shadowOffset = value1
expect(item.shadowOffset) == value1
expect(item.layer.shadowOffset) == value1

let value2 = CGSize(width: 3, height: 2)
item.layer.shadowOffset = value2
expect(item.shadowOffset) == value2
expect(item.layer.shadowOffset) == value2
}

it("stores shadow opacity correctly") {
let value1 = Float(0.8)
item.shadowOpacity = value1
expect(item.shadowOpacity) == value1
expect(item.layer.shadowOpacity) == value1

let value2 = Float(0.5)
item.layer.shadowOpacity = value2
expect(item.shadowOpacity) == value2
expect(item.layer.shadowOpacity) == value2
}

it("stores shadow radius correctly") {
let value1 = CGFloat(8)
item.shadowRadius = value1
expect(item.shadowRadius) == value1
expect(item.layer.shadowRadius) == value1

let value2 = CGFloat(5)
item.layer.shadowRadius = value2
expect(item.shadowRadius) == value2
expect(item.layer.shadowRadius) == value2
}
}
}
}
Loading

0 comments on commit f014c12

Please sign in to comment.