-
Notifications
You must be signed in to change notification settings - Fork 748
/
Copy pathAnimator.swift
78 lines (59 loc) · 2.66 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
69
70
71
72
73
74
75
76
77
//
// 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: AnyObject {
func hide(animator: Animator)
func panStarted(animator: Animator)
func panEnded(animator: Animator)
}
/**
An option set representing the known types of safe area conflicts
that could require margin adjustments on the message view in order to
get the layouts to look right.
*/
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 is over the status bar on an iPhone 8 or lower. This is a special
/// case because we logically expect the top safe area to be zero, but it is reported as 20
/// (which seems like an iOS bug). We use the `overStatusBar` to indicate this special case.
public static let overStatusBar = 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: AnyObject {
/// Adopting classes should declare as `weak`.
var delegate: AnimationDelegate? { get set }
func show(context: AnimationContext, completion: @escaping AnimationCompletion)
func hide(context: AnimationContext, completion: @escaping AnimationCompletion)
/// The show animation duration. If the animation duration is unknown, such as if using `UIDynamicAnimator`,
/// then provide an estimate. This value is used by `SwiftMessagesSegue`.
var showDuration: TimeInterval { get }
/// The hide animation duration. If the animation duration is unknown, such as if using `UIDynamicAnimator`,
/// then provide an estimate. This value is used by `SwiftMessagesSegue`.
var hideDuration: TimeInterval { get }
}