Skip to content

Commit

Permalink
Updated internal logic for "selectedIndex"
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrommcarrasco committed Jan 27, 2019
1 parent 7f90e02 commit 201ed18
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- SliceControl (1.2.0)
- SliceControl (1.3.0)

DEPENDENCIES:
- SliceControl (from `..`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: ".."

SPEC CHECKSUMS:
SliceControl: 2ca026d878e460a8b1e2e68be85f878a5ab9c783
SliceControl: 6f4b8a068f35efdecfa00408037a434fa850cb59

PODFILE CHECKSUM: 472c6bdd43948203743cec6a19ad73dd429ea8e0

Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/SliceControl.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion SliceControl.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.swift_version = "4.2"
s.name = "SliceControl"
s.version = "1.2.0"
s.version = "1.3.0"
s.summary = "🍰 Simply a better & animated UISegmentedControl"
s.description = "🍰 Simply a better & animated UISegmentedControl"

Expand Down
23 changes: 8 additions & 15 deletions SliceControl/Core/SliceControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ public final class SliceControl: UIControl {
private var selectedLeadingConstraint: NSLayoutConstraint?

// MARK: Public Properties
public private(set) var selectedIndex: Int
public var selectedIndex: Int {
didSet {
guard optionLabels.indices.contains(selectedIndex) else { return }
animateSelection(for: optionLabels[selectedIndex])
}
}
public weak var delegate: SliceControlDelegate?

// MARK: Private Properties
Expand Down Expand Up @@ -62,14 +67,6 @@ public final class SliceControl: UIControl {
}
}

// MARK: - Reset
extension SliceControl {

public func reset() {
selected(item: optionLabels[startIndex], isReset: true)
}
}

// MARK: - Actions
extension SliceControl {

Expand Down Expand Up @@ -128,14 +125,10 @@ private extension SliceControl {
static let velocity: CGFloat = 0.7
}

func selected(item: UILabel, isReset: Bool = false) {
func selected(item: UILabel) {
guard let index = optionLabels.index(of: item) else { return }
selectedIndex = index
animateSelection(for: item)

if !isReset {
delegate?.sliceControl(self, didSelectItemAt: index)
}
delegate?.sliceControl(self, didSelectItemAt: index)
}

func animateSelection(for item: UILabel) {
Expand Down

0 comments on commit 201ed18

Please sign in to comment.