Skip to content

Commit

Permalink
Merge pull request #112 from Skyscanner/pass-completed-argument-for-a…
Browse files Browse the repository at this point in the history
…nimation-completions

Pass completion flag to callbacks for animations
  • Loading branch information
Hugo Tunius authored Mar 1, 2017
2 parents f4d1854 + 190d905 commit ca6a35b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
Master(unreleased)
-----------------

### Breaking

Change implementation of anmimation callbacks to include boolean completed flag.

#### Before
```swift
textfield.setTitleVisible(false, animated: true) {
// Perform callback actions
}
```

#### Now

```swift
textfield.setTitleVisible(false, animated: true) { completed in
// Do callback actions using completed flag
}
```

See (#112)[https://github.com/Skyscanner/SkyFloatingLabelTextField/pull/112]


v2.0.1
------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ShowcaseExampleViewController: UIViewController, UITextFieldDelegate {
}
}

func showingTitleInAnimationComplete() {
func showingTitleInAnimationComplete(_ completed: Bool) {
// If a field is not filled out, display the highlighted title for 0.3 seco
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
self.showingTitleInProgress = false
Expand Down
10 changes: 4 additions & 6 deletions Sources/SkyFloatingLabelTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ open class SkyFloatingLabelTextField: UITextField {
/*
* Set this value to make the title visible
*/
open func setTitleVisible(_ titleVisible:Bool, animated:Bool = false, animationCompletion: (()->())? = nil) {
open func setTitleVisible(_ titleVisible:Bool, animated:Bool = false, animationCompletion: ((_ completed: Bool) -> Void)? = nil) {
if(_titleVisible == titleVisible) {
return
}
Expand All @@ -429,7 +429,7 @@ open class SkyFloatingLabelTextField: UITextField {
return self.hasText || self.hasErrorMessage || _titleVisible
}

fileprivate func updateTitleVisibility(_ animated:Bool = false, completion: (()->())? = nil) {
fileprivate func updateTitleVisibility(_ animated:Bool = false, completion: ((_ completed: Bool) -> Void)? = nil) {
let alpha:CGFloat = self.isTitleVisible() ? 1.0 : 0.0
let frame:CGRect = self.titleLabelRectForBounds(self.bounds, editing: self.isTitleVisible())
let updateBlock = { () -> Void in
Expand All @@ -442,12 +442,10 @@ open class SkyFloatingLabelTextField: UITextField {

UIView.animate(withDuration: duration, delay: 0, options: animationOptions, animations: { () -> Void in
updateBlock()
}, completion: { _ in
completion?()
})
}, completion: completion)
} else {
updateBlock()
completion?()
completion?(true)
}
}

Expand Down

0 comments on commit ca6a35b

Please sign in to comment.