Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass completion flag to callbacks for animations #112

Merged
merged 1 commit into from
Mar 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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