Skip to content

xcode10 #11

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

Merged
merged 2 commits into from
Aug 20, 2018
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
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ matrix:
- {osx_image: xcode9.4, env: 'PLAT=iOS SWFT=3.3 DST="OS=11.4,name=iPhone 5s"'}
- {osx_image: xcode9.4, env: 'PLAT=tvOS SWFT=3.3 DST="OS=11.4,name=Apple TV"'}

- {osx_image: xcode10, env: 'PLAT=iOS SWFT=3.4 DST="OS=12.0,name=iPhone SE"'}
- {osx_image: xcode10, env: 'PLAT=tvOS SWFT=3.4 DST="OS=12.0,name=Apple TV"'}

- {osx_image: xcode9.2, env: 'PLAT=iOS SWFT=4.0 DST="OS=11.2,name=iPhone SE"'}
- {osx_image: xcode9.2, env: 'PLAT=tvOS SWFT=4.0 DST="OS=11.2,name=Apple TV"'}

Expand All @@ -21,6 +24,9 @@ matrix:
- {osx_image: xcode9.3, env: 'PLAT=tvOS SWFT=4.1 DST="OS=9.2,name=Apple TV 1080p"'}
- {osx_image: xcode9.3, env: 'PLAT=tvOS SWFT=4.1 DST="OS=10.2,name=Apple TV 1080p"'}
- {osx_image: xcode9.4, env: 'PLAT=tvOS SWFT=4.1 DST="OS=11.4,name=Apple TV"'}

- {osx_image: xcode10, env: 'PLAT=iOS SWFT=4.2 DST="OS=12.0,name=iPhone SE"'}
- {osx_image: xcode10, env: 'PLAT=tvOS SWFT=4.2 DST="OS=12.0,name=Apple TV"'}
cache:
directories:
- Carthage
Expand Down
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "mxcl/PromiseKit" "6.3.3"
github "mxcl/PromiseKit" "6.3.4"
24 changes: 24 additions & 0 deletions Sources/UIImagePickerController+Promise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import UIKit
#if !os(tvOS)

extension UIViewController {
#if swift(>=4.2)
/// Presents the UIImagePickerController, resolving with the user action.
public func promise(_ vc: UIImagePickerController, animate: PMKAnimationOptions = [.appear, .disappear], completion: (() -> Void)? = nil) -> Promise<[UIImagePickerController.InfoKey: Any]> {
let animated = animate.contains(.appear)
let proxy = UIImagePickerControllerProxy()
vc.delegate = proxy
present(vc, animated: animated, completion: completion)
return proxy.promise.ensure {
vc.presentingViewController?.dismiss(animated: animated, completion: nil)
}
}
#else
/// Presents the UIImagePickerController, resolving with the user action.
public func promise(_ vc: UIImagePickerController, animate: PMKAnimationOptions = [.appear, .disappear], completion: (() -> Void)? = nil) -> Promise<[String: Any]> {
let animated = animate.contains(.appear)
Expand All @@ -16,21 +28,33 @@ extension UIViewController {
vc.presentingViewController?.dismiss(animated: animated, completion: nil)
}
}
#endif
}

@objc private class UIImagePickerControllerProxy: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
#if swift(>=4.2)
let (promise, seal) = Promise<[UIImagePickerController.InfoKey: Any]>.pending()
#else
let (promise, seal) = Promise<[String: Any]>.pending()
#endif
var retainCycle: AnyObject?

required override init() {
super.init()
retainCycle = self
}

#if swift(>=4.2)
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
seal.fulfill(info)
retainCycle = nil
}
#else
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
seal.fulfill(info)
retainCycle = nil
}
#endif

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
seal.reject(UIImagePickerController.PMKError.cancelled)
Expand Down
48 changes: 48 additions & 0 deletions Sources/UIView+Promise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,53 @@ import PromiseKit
import PromiseKit
*/
public extension UIView {
#if swift(>=4.2)
/**
Animate changes to one or more views using the specified duration, delay,
options, and completion handler.

- Parameter duration: The total duration of the animations, measured in
seconds. If you specify a negative value or 0, the changes are made
without animating them.

- Parameter delay: The amount of time (measured in seconds) to wait before
beginning the animations. Specify a value of 0 to begin the animations
immediately.

- Parameter options: A mask of options indicating how you want to perform the
animations. For a list of valid constants, see UIViewAnimationOptions.

- Parameter animations: A block object containing the changes to commit to the
views.

- Returns: A promise that fulfills with a boolean NSNumber indicating
whether or not the animations actually finished.
*/
@discardableResult
static func animate(_: PMKNamespacer, duration: TimeInterval, delay: TimeInterval = 0, options: UIView.AnimationOptions = [], animations: @escaping () -> Void) -> Guarantee<Bool> {
return Guarantee { animate(withDuration: duration, delay: delay, options: options, animations: animations, completion: $0) }
}

@discardableResult
static func animate(_: PMKNamespacer, duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping damping: CGFloat, initialSpringVelocity: CGFloat, options: UIView.AnimationOptions = [], animations: @escaping () -> Void) -> Guarantee<Bool> {
return Guarantee { animate(withDuration: duration, delay: delay, usingSpringWithDamping: damping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: $0) }
}

@discardableResult
static func transition(_: PMKNamespacer, with view: UIView, duration: TimeInterval, options: UIView.AnimationOptions = [], animations: (() -> Void)?) -> Guarantee<Bool> {
return Guarantee { transition(with: view, duration: duration, options: options, animations: animations, completion: $0) }
}

@discardableResult
static func transition(_: PMKNamespacer, from: UIView, to: UIView, duration: TimeInterval, options: UIView.AnimationOptions = []) -> Guarantee<Bool> {
return Guarantee { transition(from: from, to: to, duration: duration, options: options, completion: $0) }
}

@discardableResult
static func perform(_: PMKNamespacer, animation: UIView.SystemAnimation, on views: [UIView], options: UIView.AnimationOptions = [], animations: (() -> Void)?) -> Guarantee<Bool> {
return Guarantee { perform(animation, on: views, options: options, animations: animations, completion: $0) }
}
#else
/**
Animate changes to one or more views using the specified duration, delay,
options, and completion handler.
Expand Down Expand Up @@ -64,4 +111,5 @@ public extension UIView {
static func perform(_: PMKNamespacer, animation: UISystemAnimation, on views: [UIView], options: UIViewAnimationOptions = [], animations: (() -> Void)?) -> Guarantee<Bool> {
return Guarantee { perform(animation, on: views, options: options, animations: animations, completion: $0) }
}
#endif
}