|
@@ -14,6 +14,9 @@
|
14
|
14
|
* limitations under the License.
|
15
|
15
|
*/
|
16
|
16
|
|
|
17
|
+/// Alias defining a completion closure that returns a Bool
|
|
18
|
+public typealias CompletionAction = (Bool) -> Void
|
|
19
|
+
|
17
|
20
|
/// A window that allows its root view controller to be presented
|
18
|
21
|
/// in full screen or in a custom Picture in Picture mode
|
19
|
22
|
open class PiPWindow: UIWindow {
|
|
@@ -50,23 +53,23 @@ open class PiPWindow: UIWindow {
|
50
|
53
|
}
|
51
|
54
|
|
52
|
55
|
/// animate in the window
|
53
|
|
- open func show() {
|
|
56
|
+ open func show(completion: CompletionAction? = nil) {
|
54
|
57
|
if self.isHidden || self.alpha < 1 {
|
55
|
58
|
self.isHidden = false
|
56
|
59
|
self.alpha = 0
|
57
|
|
- animateTransition {
|
|
60
|
+
|
|
61
|
+ animateTransition(animations: {
|
58
|
62
|
self.alpha = 1
|
59
|
|
- }
|
|
63
|
+ }, completion: completion)
|
60
|
64
|
}
|
61
|
65
|
}
|
62
|
66
|
|
63
|
67
|
/// animate out the window
|
64
|
|
- open func hide() {
|
|
68
|
+ open func hide(completion: CompletionAction? = nil) {
|
65
|
69
|
if !self.isHidden || self.alpha > 0 {
|
66
|
|
- animateTransition {
|
67
|
|
- self.alpha = 0
|
68
|
|
- self.isHidden = true
|
69
|
|
- }
|
|
70
|
+ animateTransition(animations: {
|
|
71
|
+ self.alpha = 1
|
|
72
|
+ }, completion: completion)
|
70
|
73
|
}
|
71
|
74
|
}
|
72
|
75
|
|
|
@@ -175,11 +178,12 @@ open class PiPWindow: UIWindow {
|
175
|
178
|
|
176
|
179
|
// MARK: - Animation transition
|
177
|
180
|
|
178
|
|
- private func animateTransition(animations: @escaping () -> Void) {
|
|
181
|
+ private func animateTransition(animations: @escaping () -> Void,
|
|
182
|
+ completion: CompletionAction?) {
|
179
|
183
|
UIView.animate(withDuration: 0.1,
|
180
|
184
|
delay: 0,
|
181
|
185
|
options: .beginFromCurrentState,
|
182
|
186
|
animations: animations,
|
183
|
|
- completion: nil)
|
|
187
|
+ completion: completion)
|
184
|
188
|
}
|
185
|
189
|
}
|