Skip to content

Commit 67efdfd

Browse files
committed
'Cancel' for PromiseKit -- provides the ability to cancel promises and promise chains
1 parent c0dd945 commit 67efdfd

File tree

10 files changed

+187
-25
lines changed

10 files changed

+187
-25
lines changed

.travis.yml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,35 @@ os: osx
22
language: objective-c
33
matrix:
44
include:
5-
- {osx_image: xcode8.3, env: 'PLAT=iOS SWFT=3.1 DST="OS=8.4,name=iPhone 4S"'}
6-
- {osx_image: xcode8.3, env: 'PLAT=iOS SWFT=3.1 DST="OS=9.3,name=iPhone 6"'}
75
- {osx_image: xcode8.3, env: 'PLAT=iOS SWFT=3.1 DST="OS=10.3.1,name=iPhone SE"'}
8-
- {osx_image: xcode8.3, env: 'PLAT=tvOS SWFT=3.1 DST="OS=9.2,name=Apple TV 1080p"'}
96
- {osx_image: xcode8.3, env: 'PLAT=tvOS SWFT=3.1 DST="OS=10.2,name=Apple TV 1080p"'}
107

118
- {osx_image: xcode9.2, env: 'PLAT=iOS SWFT=3.2 DST="OS=11.2,name=iPhone SE"'}
129
- {osx_image: xcode9.2, env: 'PLAT=tvOS SWFT=3.2 DST="OS=11.2,name=Apple TV"'}
13-
14-
- {osx_image: xcode9.2, env: 'PLAT=iOS SWFT=4.0 DST="OS=8.4,name=iPhone 4s"'}
15-
- {osx_image: xcode9.2, env: 'PLAT=iOS SWFT=4.0 DST="OS=9.3,name=iPhone SE"'}
16-
- {osx_image: xcode9.2, env: 'PLAT=iOS SWFT=4.0 DST="OS=10.3.1,name=iPhone SE"'}
10+
11+
- {osx_image: xcode9.4, env: 'PLAT=iOS SWFT=3.3 DST="OS=11.4,name=iPhone 5s"'}
12+
- {osx_image: xcode9.4, env: 'PLAT=tvOS SWFT=3.3 DST="OS=11.4,name=Apple TV"'}
13+
14+
- {osx_image: xcode10, env: 'PLAT=iOS SWFT=3.4 DST="OS=12.0,name=iPhone SE"'}
15+
- {osx_image: xcode10, env: 'PLAT=tvOS SWFT=3.4 DST="OS=12.0,name=Apple TV"'}
16+
1717
- {osx_image: xcode9.2, env: 'PLAT=iOS SWFT=4.0 DST="OS=11.2,name=iPhone SE"'}
18-
- {osx_image: xcode9.2, env: 'PLAT=tvOS SWFT=4.0 DST="OS=9.2,name=Apple TV 1080p"'}
19-
- {osx_image: xcode9.2, env: 'PLAT=tvOS SWFT=4.0 DST="OS=10.2,name=Apple TV 1080p"'}
2018
- {osx_image: xcode9.2, env: 'PLAT=tvOS SWFT=4.0 DST="OS=11.2,name=Apple TV"'}
19+
20+
- {osx_image: xcode9.4, env: 'PLAT=iOS SWFT=4.1 DST="OS=8.4,name=iPhone 4s"'}
21+
- {osx_image: xcode9.4, env: 'PLAT=iOS SWFT=4.1 DST="OS=9.3,name=iPhone 5s"'}
22+
- {osx_image: xcode9.4, env: 'PLAT=iOS SWFT=4.1 DST="OS=10.3.1,name=iPhone SE"'}
23+
- {osx_image: xcode9.4, env: 'PLAT=iOS SWFT=4.1 DST="OS=11.4,name=iPhone 5s"'}
24+
- {osx_image: xcode9.3, env: 'PLAT=tvOS SWFT=4.1 DST="OS=9.2,name=Apple TV 1080p"'}
25+
- {osx_image: xcode9.3, env: 'PLAT=tvOS SWFT=4.1 DST="OS=10.2,name=Apple TV 1080p"'}
26+
- {osx_image: xcode9.4, env: 'PLAT=tvOS SWFT=4.1 DST="OS=11.4,name=Apple TV"'}
27+
28+
- {osx_image: xcode10, env: 'PLAT=iOS SWFT=4.2 DST="OS=12.0,name=iPhone SE"'}
29+
- {osx_image: xcode10, env: 'PLAT=tvOS SWFT=4.2 DST="OS=12.0,name=Apple TV"'}
2130
cache:
2231
directories:
2332
- Carthage
2433
install:
2534
- carthage bootstrap --cache-builds --no-use-binaries --platform $PLAT
2635
script:
27-
- xcodebuild -scheme PMKUIKit -quiet -destination "$DST" build SWIFT_VERSION="$SWFT"
36+
- xcodebuild -scheme PMKUIKit -target PMKUIKit -quiet -destination "$DST" build SWIFT_VERSION="$SWFT" SWIFT_TREAT_WARNINGS_AS_ERRORS=YES

Cartfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
github "mxcl/PromiseKit" ~> 6.0
1+
#github "mxcl/PromiseKit" ~> 6.0
2+
github "dougzilla32/PromiseKit" "CoreCancel"

Cartfile.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "mxcl/PromiseKit" "6.1.0"
1+
github "dougzilla32/PromiseKit" "087b3cf470890ff9ea841212e2f3e285fecf3988"

PMKUIKit.xcodeproj/project.pbxproj

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
63C9C4581D5D339B00101ECE /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 630B2DF51D5D0AD400DC10E9 /* [email protected] */; };
2626
63C9C45E1D5D341600101ECE /* PMKUIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63C7FFA71D5BEE09003BAE60 /* PMKUIKit.framework */; };
2727
63C9C45F1D5D341600101ECE /* PMKUIKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 63C7FFA71D5BEE09003BAE60 /* PMKUIKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
28+
911E6FC620F571F7006F49B9 /* TestUIViewPropertyAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 911E6FC520F571F7006F49B9 /* TestUIViewPropertyAnimator.swift */; };
2829
/* End PBXBuildFile section */
2930

3031
/* Begin PBXContainerItemProxy section */
@@ -95,6 +96,7 @@
9596
63C9C4451D5D334700101ECE /* PMKTestsHost.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PMKTestsHost.app; sourceTree = BUILT_PRODUCTS_DIR; };
9697
63CCF8121D5C0C4E00503216 /* Cartfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Cartfile; sourceTree = "<group>"; };
9798
63CCF8171D5C11B500503216 /* Carthage.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Carthage.xcconfig; sourceTree = "<group>"; };
99+
911E6FC520F571F7006F49B9 /* TestUIViewPropertyAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestUIViewPropertyAnimator.swift; sourceTree = "<group>"; };
98100
/* End PBXFileReference section */
99101

100102
/* Begin PBXFrameworksBuildPhase section */
@@ -186,6 +188,7 @@
186188
637E2C8E1D5C2E720043E370 /* TestUIImagePickerController.swift */,
187189
637E2C8F1D5C2E720043E370 /* TestUIViewController.m */,
188190
6332142A1D83CD17009F67CE /* TestUIView.swift */,
191+
911E6FC520F571F7006F49B9 /* TestUIViewPropertyAnimator.swift */,
189192
637E2C9A1D5C2F600043E370 /* infrastructure.swift */,
190193
);
191194
path = Tests;
@@ -287,7 +290,7 @@
287290
isa = PBXProject;
288291
attributes = {
289292
LastSwiftUpdateCheck = 0800;
290-
LastUpgradeCheck = 0900;
293+
LastUpgradeCheck = 1000;
291294
ORGANIZATIONNAME = "Max Howell";
292295
TargetAttributes = {
293296
630B2DFF1D5D0AF500DC10E9 = {
@@ -402,6 +405,7 @@
402405
isa = PBXSourcesBuildPhase;
403406
buildActionMask = 2147483647;
404407
files = (
408+
911E6FC620F571F7006F49B9 /* TestUIViewPropertyAnimator.swift in Sources */,
405409
637E2C951D5C2E720043E370 /* TestUIImagePickerController.swift in Sources */,
406410
637E2C961D5C2E720043E370 /* TestUIViewController.m in Sources */,
407411
637E2C9B1D5C2F600043E370 /* infrastructure.swift in Sources */,
@@ -455,7 +459,7 @@
455459
PRODUCT_NAME = "$(TARGET_NAME)";
456460
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
457461
SWIFT_SUPPRESS_WARNINGS = YES;
458-
SWIFT_VERSION = 3.0;
462+
SWIFT_VERSION = 4.0;
459463
TEST_TARGET_NAME = PMKTestsHost;
460464
};
461465
name = Debug;
@@ -471,7 +475,7 @@
471475
PRODUCT_BUNDLE_IDENTIFIER = org.promisekit.tests.ui.UIKit;
472476
PRODUCT_NAME = "$(TARGET_NAME)";
473477
SWIFT_SUPPRESS_WARNINGS = YES;
474-
SWIFT_VERSION = 3.0;
478+
SWIFT_VERSION = 4.0;
475479
TEST_TARGET_NAME = PMKTestsHost;
476480
};
477481
name = Release;
@@ -491,13 +495,15 @@
491495
CLANG_WARN_BOOL_CONVERSION = YES;
492496
CLANG_WARN_COMMA = YES;
493497
CLANG_WARN_CONSTANT_CONVERSION = YES;
498+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
494499
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
495500
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
496501
CLANG_WARN_EMPTY_BODY = YES;
497502
CLANG_WARN_ENUM_CONVERSION = YES;
498503
CLANG_WARN_INFINITE_RECURSION = YES;
499504
CLANG_WARN_INT_CONVERSION = YES;
500505
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
506+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
501507
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
502508
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
503509
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -534,6 +540,7 @@
534540
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvsimulator appletvos";
535541
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
536542
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
543+
SWIFT_VERSION = 3.0;
537544
TARGETED_DEVICE_FAMILY = "1,2,3,4";
538545
TVOS_DEPLOYMENT_TARGET = 9.0;
539546
WATCHOS_DEPLOYMENT_TARGET = 2.0;
@@ -555,13 +562,15 @@
555562
CLANG_WARN_BOOL_CONVERSION = YES;
556563
CLANG_WARN_COMMA = YES;
557564
CLANG_WARN_CONSTANT_CONVERSION = YES;
565+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
558566
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
559567
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
560568
CLANG_WARN_EMPTY_BODY = YES;
561569
CLANG_WARN_ENUM_CONVERSION = YES;
562570
CLANG_WARN_INFINITE_RECURSION = YES;
563571
CLANG_WARN_INT_CONVERSION = YES;
564572
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
573+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
565574
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
566575
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
567576
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -590,6 +599,7 @@
590599
PRODUCT_BUNDLE_IDENTIFIER = org.promisekit.UIKit;
591600
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvsimulator appletvos";
592601
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
602+
SWIFT_VERSION = 3.0;
593603
TARGETED_DEVICE_FAMILY = "1,2,3,4";
594604
TVOS_DEPLOYMENT_TARGET = 9.0;
595605
VALIDATE_PRODUCT = YES;
@@ -611,7 +621,6 @@
611621
PRODUCT_MODULE_NAME = "${TARGET_NAME}";
612622
PRODUCT_NAME = "$(TARGET_NAME)";
613623
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
614-
SWIFT_VERSION = 3.0;
615624
};
616625
name = Debug;
617626
};
@@ -628,7 +637,6 @@
628637
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
629638
PRODUCT_MODULE_NAME = "${TARGET_NAME}";
630639
PRODUCT_NAME = "$(TARGET_NAME)";
631-
SWIFT_VERSION = 3.0;
632640
};
633641
name = Release;
634642
};
@@ -643,7 +651,7 @@
643651
PRODUCT_NAME = "$(TARGET_NAME)";
644652
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
645653
SWIFT_SUPPRESS_WARNINGS = YES;
646-
SWIFT_VERSION = 3.0;
654+
SWIFT_VERSION = 4.0;
647655
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PMKTestsHost.app/PMKTestsHost";
648656
};
649657
name = Debug;
@@ -658,7 +666,7 @@
658666
PRODUCT_BUNDLE_IDENTIFIER = org.promisekit.tests.UIKit;
659667
PRODUCT_NAME = "$(TARGET_NAME)";
660668
SWIFT_SUPPRESS_WARNINGS = YES;
661-
SWIFT_VERSION = 3.0;
669+
SWIFT_VERSION = 4.0;
662670
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PMKTestsHost.app/PMKTestsHost";
663671
};
664672
name = Release;
@@ -675,7 +683,7 @@
675683
PRODUCT_BUNDLE_IDENTIFIER = org.promisekit.tests.host.UIKit;
676684
PRODUCT_NAME = "$(TARGET_NAME)";
677685
SDKROOT = iphoneos;
678-
SWIFT_VERSION = 3.0;
686+
SWIFT_VERSION = 4.0;
679687
};
680688
name = Debug;
681689
};
@@ -691,7 +699,7 @@
691699
PRODUCT_BUNDLE_IDENTIFIER = org.promisekit.tests.host.UIKit;
692700
PRODUCT_NAME = "$(TARGET_NAME)";
693701
SDKROOT = iphoneos;
694-
SWIFT_VERSION = 3.0;
702+
SWIFT_VERSION = 4.0;
695703
};
696704
name = Release;
697705
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

PMKUIKit.xcodeproj/xcshareddata/xcschemes/PMKUIKit.xcscheme

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0900"
3+
LastUpgradeVersion = "1000"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -40,7 +40,6 @@
4040
buildConfiguration = "Debug"
4141
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4242
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
43-
language = ""
4443
shouldUseLaunchSchemeArgsEnv = "YES">
4544
<Testables>
4645
<TestableReference
@@ -88,7 +87,6 @@
8887
buildConfiguration = "Debug"
8988
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
9089
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
91-
language = ""
9290
launchStyle = "0"
9391
useCustomWorkingDirectory = "NO"
9492
ignoresPersistentStateOnLaunch = "NO"

Sources/UIImagePickerController+Promise.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ import UIKit
66
#if !os(tvOS)
77

88
extension UIViewController {
9+
#if swift(>=4.2)
10+
/// Presents the UIImagePickerController, resolving with the user action.
11+
public func promise(_ vc: UIImagePickerController, animate: PMKAnimationOptions = [.appear, .disappear], completion: (() -> Void)? = nil) -> Promise<[UIImagePickerController.InfoKey: Any]> {
12+
let animated = animate.contains(.appear)
13+
let proxy = UIImagePickerControllerProxy()
14+
vc.delegate = proxy
15+
present(vc, animated: animated, completion: completion)
16+
return proxy.promise.ensure {
17+
vc.presentingViewController?.dismiss(animated: animated, completion: nil)
18+
}
19+
}
20+
#else
921
/// Presents the UIImagePickerController, resolving with the user action.
1022
public func promise(_ vc: UIImagePickerController, animate: PMKAnimationOptions = [.appear, .disappear], completion: (() -> Void)? = nil) -> Promise<[String: Any]> {
1123
let animated = animate.contains(.appear)
@@ -16,21 +28,33 @@ extension UIViewController {
1628
vc.presentingViewController?.dismiss(animated: animated, completion: nil)
1729
}
1830
}
31+
#endif
1932
}
2033

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

2542
required override init() {
2643
super.init()
2744
retainCycle = self
2845
}
2946

47+
#if swift(>=4.2)
48+
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
49+
seal.fulfill(info)
50+
retainCycle = nil
51+
}
52+
#else
3053
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
3154
seal.fulfill(info)
3255
retainCycle = nil
3356
}
57+
#endif
3458

3559
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
3660
seal.reject(UIImagePickerController.PMKError.cancelled)

Sources/UIView+Promise.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,53 @@ import PromiseKit
1919
import PromiseKit
2020
*/
2121
public extension UIView {
22+
#if swift(>=4.2)
23+
/**
24+
Animate changes to one or more views using the specified duration, delay,
25+
options, and completion handler.
26+
27+
- Parameter duration: The total duration of the animations, measured in
28+
seconds. If you specify a negative value or 0, the changes are made
29+
without animating them.
30+
31+
- Parameter delay: The amount of time (measured in seconds) to wait before
32+
beginning the animations. Specify a value of 0 to begin the animations
33+
immediately.
34+
35+
- Parameter options: A mask of options indicating how you want to perform the
36+
animations. For a list of valid constants, see UIViewAnimationOptions.
37+
38+
- Parameter animations: A block object containing the changes to commit to the
39+
views.
40+
41+
- Returns: A promise that fulfills with a boolean NSNumber indicating
42+
whether or not the animations actually finished.
43+
*/
44+
@discardableResult
45+
static func animate(_: PMKNamespacer, duration: TimeInterval, delay: TimeInterval = 0, options: UIView.AnimationOptions = [], animations: @escaping () -> Void) -> Guarantee<Bool> {
46+
return Guarantee { animate(withDuration: duration, delay: delay, options: options, animations: animations, completion: $0) }
47+
}
48+
49+
@discardableResult
50+
static func animate(_: PMKNamespacer, duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping damping: CGFloat, initialSpringVelocity: CGFloat, options: UIView.AnimationOptions = [], animations: @escaping () -> Void) -> Guarantee<Bool> {
51+
return Guarantee { animate(withDuration: duration, delay: delay, usingSpringWithDamping: damping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: $0) }
52+
}
53+
54+
@discardableResult
55+
static func transition(_: PMKNamespacer, with view: UIView, duration: TimeInterval, options: UIView.AnimationOptions = [], animations: (() -> Void)?) -> Guarantee<Bool> {
56+
return Guarantee { transition(with: view, duration: duration, options: options, animations: animations, completion: $0) }
57+
}
58+
59+
@discardableResult
60+
static func transition(_: PMKNamespacer, from: UIView, to: UIView, duration: TimeInterval, options: UIView.AnimationOptions = []) -> Guarantee<Bool> {
61+
return Guarantee { transition(from: from, to: to, duration: duration, options: options, completion: $0) }
62+
}
63+
64+
@discardableResult
65+
static func perform(_: PMKNamespacer, animation: UIView.SystemAnimation, on views: [UIView], options: UIView.AnimationOptions = [], animations: (() -> Void)?) -> Guarantee<Bool> {
66+
return Guarantee { perform(animation, on: views, options: options, animations: animations, completion: $0) }
67+
}
68+
#else
2269
/**
2370
Animate changes to one or more views using the specified duration, delay,
2471
options, and completion handler.
@@ -64,4 +111,5 @@ public extension UIView {
64111
static func perform(_: PMKNamespacer, animation: UISystemAnimation, on views: [UIView], options: UIViewAnimationOptions = [], animations: (() -> Void)?) -> Guarantee<Bool> {
65112
return Guarantee { perform(animation, on: views, options: options, animations: animations, completion: $0) }
66113
}
114+
#endif
67115
}

Sources/UIViewPropertyAnimator+Promise.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,29 @@ import UIKit
66
@available(iOS 10, tvOS 10, *)
77
public extension UIViewPropertyAnimator {
88
func startAnimation(_: PMKNamespacer) -> Guarantee<UIViewAnimatingPosition> {
9-
return Guarantee {
9+
return Guarantee<UIViewAnimatingPosition>(cancellableTask: self) {
1010
addCompletion($0)
1111
startAnimation()
1212
}
1313
}
1414
}
15+
16+
@available(iOS 10, tvOS 10, *)
17+
extension UIViewPropertyAnimator: CancellableTask {
18+
public func cancel() {
19+
stopAnimation(true)
20+
}
21+
22+
public var isCancelled: Bool {
23+
return (state == .inactive) && (fractionComplete < 1.0)
24+
}
25+
}
26+
27+
//////////////////////////////////////////////////////////// Cancellable wrapper
28+
29+
@available(iOS 10, tvOS 10, *)
30+
extension UIViewPropertyAnimator {
31+
public func cancellableStartAnimation(_: PMKNamespacer) -> CancellablePromise<UIViewAnimatingPosition> {
32+
return cancellable(startAnimation(.promise))
33+
}
34+
}

0 commit comments

Comments
 (0)