forked from SwiftKickMobile/SwiftMessages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimator.swift
68 lines (52 loc) · 2.11 KB
/
Animator.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// Animator.swift
// SwiftMessages
//
// Created by Timothy Moose on 6/4/17.
// Copyright © 2017 SwiftKick Mobile. All rights reserved.
//
import UIKit
public typealias AnimationCompletion = (_ completed: Bool) -> Void
public protocol AnimationDelegate: class {
func hide(animator: Animator)
func panStarted(animator: Animator)
func panEnded(animator: Animator)
}
/**
An option set that represents the known types of safe zone conflicts
that may need custom margin adustments.
*/
public struct SafeZoneConflicts: OptionSet {
public let rawValue: Int
public init(rawValue: Int) {
self.rawValue = rawValue
}
/// Message view behind status bar
public static let statusBar = SafeZoneConflicts(rawValue: 1 << 0)
/// Message view behind the sensor notch on iPhone X
public static let sensorNotch = SafeZoneConflicts(rawValue: 1 << 1)
/// Message view behind home indicator on iPhone X
public static let homeIndicator = SafeZoneConflicts(rawValue: 1 << 2)
/// Message view covering status bar on iPhone 8 or lower. One would expect the
/// top safe zone to be 0, but in the current version of iOS 11, it is non-zero (20),
/// which SwiftMessages will automatically compensate for by subtracting that amount
/// form the layout margins.
public static let coveredStatusBar = SafeZoneConflicts(rawValue: 1 << 3)
}
public class AnimationContext {
public let messageView: UIView
public let containerView: UIView
public let safeZoneConflicts: SafeZoneConflicts
public let interactiveHide: Bool
init(messageView: UIView, containerView: UIView, safeZoneConflicts: SafeZoneConflicts, interactiveHide: Bool) {
self.messageView = messageView
self.containerView = containerView
self.safeZoneConflicts = safeZoneConflicts
self.interactiveHide = interactiveHide
}
}
public protocol Animator: class {
weak var delegate: AnimationDelegate? { get set }
func show(context: AnimationContext, completion: @escaping AnimationCompletion)
func hide(context: AnimationContext, completion: @escaping AnimationCompletion)
}