forked from hyperoslo/ImagePicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfiguration.swift
111 lines (93 loc) · 4.31 KB
/
Configuration.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import AVFoundation
import UIKit
@objc public class ImagePickerConfiguration: NSObject {
// MARK: Colors
@objc public var backgroundColor = UIColor(red: 0.15, green: 0.19, blue: 0.24, alpha: 1)
@objc public var gallerySeparatorColor = UIColor.black.withAlphaComponent(0.6)
@objc public var mainColor = UIColor(red: 0.09, green: 0.11, blue: 0.13, alpha: 1)
@objc public var noImagesColor = UIColor(red: 0.86, green: 0.86, blue: 0.86, alpha: 1)
@objc public var noCameraColor = UIColor(red: 0.86, green: 0.86, blue: 0.86, alpha: 1)
@objc public var settingsColor = UIColor.white
@objc public var bottomContainerColor = UIColor(red: 0.09, green: 0.11, blue: 0.13, alpha: 1)
// MARK: Fonts
@objc public var numberLabelFont = UIFont.systemFont(ofSize: 19, weight: UIFont.Weight.bold)
@objc public var doneButton = UIFont.systemFont(ofSize: 19, weight: UIFont.Weight.medium)
@objc public var flashButton = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.medium)
@objc public var noImagesFont = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.medium)
@objc public var noCameraFont = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.medium)
@objc public var settingsFont = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.medium)
// MARK: Titles
@objc public var OKButtonTitle = "OK"
@objc public var cancelButtonTitle = "Cancel"
@objc public var doneButtonTitle = "Done"
@objc public var noImagesTitle = "No images available"
@objc public var noCameraTitle = "Camera is not available"
@objc public var settingsTitle = "Settings"
@objc public var requestPermissionTitle = "Permission denied"
@objc public var requestPermissionMessage = "Please, allow the application to access to your photo library."
// MARK: Dimensions
@objc public var cellSpacing: CGFloat = 2
@objc public var indicatorWidth: CGFloat = 41
@objc public var indicatorHeight: CGFloat = 8
// MARK: Custom behaviour
@objc public var canRotateCamera = true
@objc public var collapseCollectionViewWhileShot = true
@objc public var recordLocation = true
@objc public var allowMultiplePhotoSelection = true
@objc public var allowVideoSelection = false
@objc public var showsImageCountLabel = true
@objc public var flashButtonAlwaysHidden = false
@objc public var managesAudioSession = true
@objc public var allowPinchToZoom = true
@objc public var allowedOrientations = UIInterfaceOrientationMask.all
@objc public var allowVolumeButtonsToTakePicture = true
@objc public var useLowResolutionPreviewImage = false
// MARK: Images
@objc public var indicatorView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.white.withAlphaComponent(0.6)
view.layer.cornerRadius = 4
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
override public init() {}
}
// MARK: - Orientation
extension ImagePickerConfiguration {
@objc public var rotationTransform: CGAffineTransform {
let currentOrientation = UIDevice.current.orientation
// check if current orientation is allowed
switch currentOrientation {
case .portrait:
if allowedOrientations.contains(.portrait) {
Helper.previousOrientation = currentOrientation
}
case .portraitUpsideDown:
if allowedOrientations.contains(.portraitUpsideDown) {
Helper.previousOrientation = currentOrientation
}
case .landscapeLeft:
if allowedOrientations.contains(.landscapeLeft) {
Helper.previousOrientation = currentOrientation
}
case .landscapeRight:
if allowedOrientations.contains(.landscapeRight) {
Helper.previousOrientation = currentOrientation
}
default: break
}
// set default orientation if current orientation is not allowed
if Helper.previousOrientation == .unknown {
if allowedOrientations.contains(.portrait) {
Helper.previousOrientation = .portrait
} else if allowedOrientations.contains(.landscapeLeft) {
Helper.previousOrientation = .landscapeLeft
} else if allowedOrientations.contains(.landscapeRight) {
Helper.previousOrientation = .landscapeRight
} else if allowedOrientations.contains(.portraitUpsideDown) {
Helper.previousOrientation = .portraitUpsideDown
}
}
return Helper.getTransform(fromDeviceOrientation: Helper.previousOrientation)
}
}