Skip to content

Commit

Permalink
Make angle configurable for circular style (#288)
Browse files Browse the repository at this point in the history
* Make angle configurable for circular style

* Add documentation

* Add tests for custom angles

* Unify nimble tolerance

* unify nimble pixel tolerance

* Regenerate 2x reference images

* remove unused code

* format code
  • Loading branch information
jjochen authored Jan 9, 2024
1 parent 7a8b6d3 commit cfe52c8
Show file tree
Hide file tree
Showing 70 changed files with 138 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class ConfigurationExampleViewController: UIViewController {
item.bottomAnchor.constraint(equalTo: previousView.topAnchor, constant: -5).isActive = true
item.leftAnchor.constraint(equalTo: previousView.rightAnchor, constant: -2).isActive = true
previousItem = item

}
}

Expand Down
88 changes: 63 additions & 25 deletions Example/Tests/AnimationConfigurationSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import Quick
import XCTest

class AnimationConfigurationSpec: QuickSpec {
let pixelTolerance = 0.5
override class func spec() {
describe("JJFloatingActionButton") {
var actionButton: JJFloatingActionButton!
Expand All @@ -51,7 +50,8 @@ class AnimationConfigurationSpec: QuickSpec {
actionButton.addItem(image: #imageLiteral(resourceName: "Balloon"))
actionButton.addItem(image: #imageLiteral(resourceName: "Owl"))

setNimbleTolerance(0.003)
setNimbleTolerance(0.01)
setNimblePixelTolerance(0.01)
}

it("is on the right side of the screen") {
Expand All @@ -71,7 +71,7 @@ class AnimationConfigurationSpec: QuickSpec {
it("it looks correct") {
actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}
}

Expand All @@ -84,7 +84,7 @@ class AnimationConfigurationSpec: QuickSpec {
it("it looks correct") {
actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}
}

Expand All @@ -96,7 +96,7 @@ class AnimationConfigurationSpec: QuickSpec {

it("it looks correct") {
actionButton.open(animated: false)
expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}
}

Expand All @@ -114,7 +114,7 @@ class AnimationConfigurationSpec: QuickSpec {

actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}

it("it looks correct with 2 items") {
Expand All @@ -123,7 +123,7 @@ class AnimationConfigurationSpec: QuickSpec {

actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}

it("it looks correct with 1 item") {
Expand All @@ -132,7 +132,7 @@ class AnimationConfigurationSpec: QuickSpec {

actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}

it("looks correct when item have background color") {
Expand All @@ -146,7 +146,7 @@ class AnimationConfigurationSpec: QuickSpec {

actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}

it("it looks correct when opened and closed") {
Expand All @@ -157,7 +157,7 @@ class AnimationConfigurationSpec: QuickSpec {
actionButton.open(animated: false)
actionButton.close(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}
}

Expand All @@ -170,7 +170,7 @@ class AnimationConfigurationSpec: QuickSpec {
it("it looks correct") {
actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}
}

Expand All @@ -190,7 +190,7 @@ class AnimationConfigurationSpec: QuickSpec {

actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}

it("it looks correct with horizontal offset") {
Expand All @@ -199,7 +199,7 @@ class AnimationConfigurationSpec: QuickSpec {

actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}

it("it looks correct with items offsetted") {
Expand All @@ -208,7 +208,7 @@ class AnimationConfigurationSpec: QuickSpec {

actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}

it("it looks correct with circular offset items") {
Expand All @@ -217,7 +217,7 @@ class AnimationConfigurationSpec: QuickSpec {

actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}
}
}
Expand All @@ -240,7 +240,8 @@ class AnimationConfigurationSpec: QuickSpec {
actionButton.addItem(image: #imageLiteral(resourceName: "Balloon"))
actionButton.addItem(image: #imageLiteral(resourceName: "Owl"))

setNimbleTolerance(0.002)
setNimbleTolerance(0.01)
setNimblePixelTolerance(0.01)
}

it("is on the left side of the screen") {
Expand All @@ -261,7 +262,7 @@ class AnimationConfigurationSpec: QuickSpec {

actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}

it("it looks correct with 2 items") {
Expand All @@ -270,7 +271,7 @@ class AnimationConfigurationSpec: QuickSpec {

actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}

it("it looks correct with 1 item") {
Expand All @@ -279,7 +280,7 @@ class AnimationConfigurationSpec: QuickSpec {

actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}
}

Expand All @@ -299,7 +300,7 @@ class AnimationConfigurationSpec: QuickSpec {

actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}

it("it looks correct with items offsetted") {
Expand All @@ -308,7 +309,7 @@ class AnimationConfigurationSpec: QuickSpec {

actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}

it("it looks correct with circular offset items") {
Expand All @@ -317,7 +318,7 @@ class AnimationConfigurationSpec: QuickSpec {

actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}
}

Expand Down Expand Up @@ -348,11 +349,10 @@ class AnimationConfigurationSpec: QuickSpec {
it("looks correct") {
actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot(pixelTolerance: 0.01))
expect(superview).to(haveValidSnapshot())
}

// disabled for now. Fails on older operating systems. ToDo!
xit("looks correct with slide in configuration") {
it("looks correct with slide in configuration") {
let configuration = JJItemAnimationConfiguration()
configuration.openState = JJItemPreparation { item, _, _, _ in
item.alpha = 1
Expand All @@ -366,5 +366,43 @@ class AnimationConfigurationSpec: QuickSpec {
}
}
}

describe("JJFloatingActionButton in center") {
var actionButton: JJFloatingActionButton!
var superview: UIView!

beforeEach {
let superviewFrame = CGRect(origin: .zero, size: CGSize(width: 300, height: 400))
let actionButtonFrame = CGRect(origin: CGPoint(x: 132, y: 330), size: CGSize(width: 56, height: 56))

superview = UIView(frame: superviewFrame)
superview.backgroundColor = .white

actionButton = JJFloatingActionButton(frame: actionButtonFrame)
superview.addSubview(actionButton)

actionButton.addItem(image: #imageLiteral(resourceName: "Like"))
actionButton.addItem(image: #imageLiteral(resourceName: "Balloon"))
actionButton.addItem(image: #imageLiteral(resourceName: "Owl"))

setNimbleTolerance(0.01)
setNimblePixelTolerance(0.01)
}

context("when using circular pop up style with custom angles") {
beforeEach {
actionButton.itemAnimationConfiguration = .circularPopUp(withRadius: 80,
angleForItem: { index, numberOfItems, _ in
CGFloat.pi + CGFloat(index) * CGFloat.pi / (CGFloat(numberOfItems) - 1)
})
}

it("it looks correct") {
actionButton.open(animated: false)

expect(superview).to(haveValidSnapshot())
}
}
}
}
}
6 changes: 2 additions & 4 deletions Example/Tests/JJActionItemSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class JJActionItemSpec: QuickSpec {
actionItem.circleView.widthAnchor.constraint(equalToConstant: 40).isActive = true
actionItem.circleView.heightAnchor.constraint(equalToConstant: 40).isActive = true

setNimbleTolerance(0.002)
setNimbleTolerance(0.01)
}

it("looks correct") {
Expand Down Expand Up @@ -104,13 +104,11 @@ class JJActionItemSpec: QuickSpec {
}

it("looks correct with smaller image size") {
setNimbleTolerance(0.005)
actionItem.imageSize = CGSize(width: 10, height: 10)
expect(actionItem).to(haveValidSnapshot())
}

it("looks correct with bigger image size") {
setNimbleTolerance(0.025)
actionItem.imageSize = CGSize(width: 30, height: 30)
expect(actionItem).to(haveValidSnapshot())
}
Expand All @@ -132,7 +130,7 @@ class JJActionItemSpec: QuickSpec {
actionItem?.circleView.widthAnchor.constraint(equalToConstant: 40).isActive = true
actionItem?.circleView.heightAnchor.constraint(equalToConstant: 40).isActive = true

setNimbleTolerance(0.002)
setNimbleTolerance(0.01)
}

it("looks correct") {
Expand Down
Loading

0 comments on commit cfe52c8

Please sign in to comment.