react-native-video-trim 1.0.20 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/VideoTrim.swift +7 -1
- package/ios/VideoTrimmer.swift +387 -330
- package/ios/VideoTrimmerThumb.swift +139 -90
- package/ios/VideoTrimmerViewController.swift +224 -166
- package/package.json +1 -1
|
@@ -1,72 +1,92 @@
|
|
|
1
|
-
//
|
|
2
|
-
// VideoTrimmerThumb.swift
|
|
3
|
-
// react-native-video-trim
|
|
4
|
-
//
|
|
5
|
-
// Created by Duc Trung Mai on 17/1/24.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
1
|
import UIKit
|
|
9
2
|
|
|
10
3
|
@available(iOS 13.0, *)
|
|
11
4
|
class VideoTrimmerThumb: UIView {
|
|
12
|
-
var isActive = false
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
5
|
+
private var isActive = false
|
|
6
|
+
|
|
7
|
+
private let leadingChevronImageView: UIImageView = {
|
|
8
|
+
let imageView = UIImageView(image: UIImage(systemName: "chevron.compact.left"))
|
|
9
|
+
imageView.contentMode = .scaleAspectFill
|
|
10
|
+
imageView.tintColor = .black
|
|
11
|
+
imageView.tintAdjustmentMode = .normal
|
|
12
|
+
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
13
|
+
return imageView
|
|
14
|
+
}()
|
|
15
|
+
|
|
16
|
+
private let trailingChevronView: UIImageView = {
|
|
17
|
+
let imageView = UIImageView(image: UIImage(systemName: "chevron.compact.right"))
|
|
18
|
+
imageView.contentMode = .scaleAspectFill
|
|
19
|
+
imageView.tintColor = .black
|
|
20
|
+
imageView.tintAdjustmentMode = .normal
|
|
21
|
+
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
22
|
+
return imageView
|
|
23
|
+
}()
|
|
24
|
+
|
|
25
|
+
private let wrapperView: UIView = {
|
|
26
|
+
let view = UIView()
|
|
27
|
+
view.translatesAutoresizingMaskIntoConstraints = false
|
|
28
|
+
return view
|
|
29
|
+
}()
|
|
30
|
+
|
|
31
|
+
private let leadingView: UIView = {
|
|
32
|
+
let view = UIView()
|
|
33
|
+
view.layer.cornerRadius = 6
|
|
34
|
+
view.layer.cornerCurve = .continuous
|
|
35
|
+
view.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMinXMinYCorner]
|
|
36
|
+
view.translatesAutoresizingMaskIntoConstraints = false
|
|
37
|
+
return view
|
|
38
|
+
}()
|
|
39
|
+
|
|
40
|
+
private let trailingView: UIView = {
|
|
41
|
+
let view = UIView()
|
|
42
|
+
view.layer.cornerRadius = 6
|
|
43
|
+
view.layer.cornerCurve = .continuous
|
|
44
|
+
view.layer.maskedCorners = [.layerMaxXMaxYCorner, .layerMaxXMinYCorner]
|
|
45
|
+
view.translatesAutoresizingMaskIntoConstraints = false
|
|
46
|
+
return view
|
|
47
|
+
}()
|
|
48
|
+
|
|
49
|
+
private let topView: UIView = {
|
|
50
|
+
let view = UIView()
|
|
51
|
+
view.translatesAutoresizingMaskIntoConstraints = false
|
|
52
|
+
return view
|
|
53
|
+
}()
|
|
54
|
+
|
|
55
|
+
private let bottomView: UIView = {
|
|
56
|
+
let view = UIView()
|
|
57
|
+
view.translatesAutoresizingMaskIntoConstraints = false
|
|
58
|
+
return view
|
|
59
|
+
}()
|
|
60
|
+
|
|
61
|
+
let leadingGrabber: UIControl = {
|
|
62
|
+
let control = UIControl()
|
|
63
|
+
control.translatesAutoresizingMaskIntoConstraints = false
|
|
64
|
+
return control
|
|
65
|
+
}()
|
|
66
|
+
|
|
67
|
+
let trailingGrabber: UIControl = {
|
|
68
|
+
let control = UIControl()
|
|
69
|
+
control.translatesAutoresizingMaskIntoConstraints = false
|
|
70
|
+
return control
|
|
71
|
+
}()
|
|
72
|
+
|
|
73
|
+
let chevronWidth: CGFloat = 16
|
|
74
|
+
let edgeHeight: CGFloat = 4
|
|
31
75
|
|
|
76
|
+
override init(frame: CGRect) {
|
|
77
|
+
super.init(frame: frame)
|
|
78
|
+
setup()
|
|
32
79
|
}
|
|
33
80
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
leadingView.backgroundColor = color
|
|
38
|
-
trailingView.backgroundColor = color
|
|
39
|
-
topView.backgroundColor = color
|
|
40
|
-
bottomView.backgroundColor = color
|
|
81
|
+
required init?(coder: NSCoder) {
|
|
82
|
+
super.init(coder: coder)
|
|
83
|
+
setup()
|
|
41
84
|
}
|
|
42
85
|
|
|
43
86
|
private func setup() {
|
|
44
|
-
|
|
45
|
-
leadingChevronImageView.contentMode = .scaleAspectFill
|
|
46
|
-
trailingChevronView.contentMode = .scaleAspectFill
|
|
47
|
-
|
|
48
|
-
leadingChevronImageView.tintColor = .white
|
|
49
|
-
trailingChevronView.tintColor = .white
|
|
50
|
-
|
|
51
|
-
leadingChevronImageView.tintAdjustmentMode = .normal
|
|
52
|
-
trailingChevronView.tintAdjustmentMode = .normal
|
|
53
|
-
|
|
54
|
-
leadingView.layer.cornerRadius = 6
|
|
55
|
-
leadingView.layer.cornerCurve = .continuous
|
|
56
|
-
leadingView.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMinXMinYCorner]
|
|
57
|
-
|
|
58
|
-
trailingView.layer.cornerRadius = 6
|
|
59
|
-
trailingView.layer.cornerCurve = .continuous
|
|
60
|
-
trailingView.layer.maskedCorners = [.layerMaxXMaxYCorner, .layerMaxXMinYCorner]
|
|
61
|
-
|
|
62
87
|
leadingView.addSubview(leadingChevronImageView)
|
|
63
88
|
trailingView.addSubview(trailingChevronView)
|
|
64
89
|
|
|
65
|
-
// wrapperView.layer.shadowColor = UIColor.black.cgColor
|
|
66
|
-
// wrapperView.layer.shadowOffset = .zero
|
|
67
|
-
// wrapperView.layer.shadowRadius = 2
|
|
68
|
-
// wrapperView.layer.shadowOpacity = 0.25
|
|
69
|
-
|
|
70
90
|
wrapperView.addSubview(leadingView)
|
|
71
91
|
wrapperView.addSubview(trailingView)
|
|
72
92
|
wrapperView.addSubview(topView)
|
|
@@ -76,44 +96,73 @@ class VideoTrimmerThumb: UIView {
|
|
|
76
96
|
wrapperView.addSubview(leadingGrabber)
|
|
77
97
|
wrapperView.addSubview(trailingGrabber)
|
|
78
98
|
|
|
99
|
+
setupConstraints()
|
|
79
100
|
updateColor()
|
|
80
101
|
}
|
|
81
102
|
|
|
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
|
-
|
|
103
|
+
private func setupConstraints() {
|
|
104
|
+
NSLayoutConstraint.activate([
|
|
105
|
+
// Wrapper view constraints
|
|
106
|
+
wrapperView.topAnchor.constraint(equalTo: self.topAnchor),
|
|
107
|
+
wrapperView.bottomAnchor.constraint(equalTo: self.bottomAnchor),
|
|
108
|
+
wrapperView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
|
|
109
|
+
wrapperView.trailingAnchor.constraint(equalTo: self.trailingAnchor),
|
|
110
|
+
|
|
111
|
+
// Leading view constraints
|
|
112
|
+
leadingView.topAnchor.constraint(equalTo: wrapperView.topAnchor),
|
|
113
|
+
leadingView.bottomAnchor.constraint(equalTo: wrapperView.bottomAnchor),
|
|
114
|
+
leadingView.leadingAnchor.constraint(equalTo: wrapperView.leadingAnchor),
|
|
115
|
+
leadingView.widthAnchor.constraint(equalToConstant: chevronWidth),
|
|
116
|
+
|
|
117
|
+
// Trailing view constraints
|
|
118
|
+
trailingView.topAnchor.constraint(equalTo: wrapperView.topAnchor),
|
|
119
|
+
trailingView.bottomAnchor.constraint(equalTo: wrapperView.bottomAnchor),
|
|
120
|
+
trailingView.trailingAnchor.constraint(equalTo: wrapperView.trailingAnchor),
|
|
121
|
+
trailingView.widthAnchor.constraint(equalToConstant: chevronWidth),
|
|
122
|
+
|
|
123
|
+
// Top view constraints
|
|
124
|
+
topView.topAnchor.constraint(equalTo: wrapperView.topAnchor),
|
|
125
|
+
topView.leadingAnchor.constraint(equalTo: leadingView.trailingAnchor),
|
|
126
|
+
topView.trailingAnchor.constraint(equalTo: trailingView.leadingAnchor),
|
|
127
|
+
topView.heightAnchor.constraint(equalToConstant: edgeHeight),
|
|
128
|
+
|
|
129
|
+
// Bottom view constraints
|
|
130
|
+
bottomView.bottomAnchor.constraint(equalTo: wrapperView.bottomAnchor),
|
|
131
|
+
bottomView.leadingAnchor.constraint(equalTo: leadingView.trailingAnchor),
|
|
132
|
+
bottomView.trailingAnchor.constraint(equalTo: trailingView.leadingAnchor),
|
|
133
|
+
bottomView.heightAnchor.constraint(equalToConstant: edgeHeight),
|
|
134
|
+
|
|
135
|
+
// Leading Chevron ImageView constraints
|
|
136
|
+
leadingChevronImageView.topAnchor.constraint(equalTo: leadingView.topAnchor, constant: 8),
|
|
137
|
+
leadingChevronImageView.bottomAnchor.constraint(equalTo: leadingView.bottomAnchor, constant: -8),
|
|
138
|
+
leadingChevronImageView.leadingAnchor.constraint(equalTo: leadingView.leadingAnchor, constant: 2),
|
|
139
|
+
leadingChevronImageView.trailingAnchor.constraint(equalTo: leadingView.trailingAnchor, constant: -2),
|
|
140
|
+
|
|
141
|
+
// Trailing Chevron ImageView constraints
|
|
142
|
+
trailingChevronView.topAnchor.constraint(equalTo: trailingView.topAnchor, constant: 8),
|
|
143
|
+
trailingChevronView.bottomAnchor.constraint(equalTo: trailingView.bottomAnchor, constant: -8),
|
|
144
|
+
trailingChevronView.leadingAnchor.constraint(equalTo: trailingView.leadingAnchor, constant: 2),
|
|
145
|
+
trailingChevronView.trailingAnchor.constraint(equalTo: trailingView.trailingAnchor, constant: -2),
|
|
146
|
+
|
|
147
|
+
// Leading Grabber constraints
|
|
148
|
+
leadingGrabber.topAnchor.constraint(equalTo: leadingView.topAnchor),
|
|
149
|
+
leadingGrabber.bottomAnchor.constraint(equalTo: leadingView.bottomAnchor),
|
|
150
|
+
leadingGrabber.leadingAnchor.constraint(equalTo: leadingView.leadingAnchor),
|
|
151
|
+
leadingGrabber.trailingAnchor.constraint(equalTo: leadingView.trailingAnchor),
|
|
152
|
+
|
|
153
|
+
// Trailing Grabber constraints
|
|
154
|
+
trailingGrabber.topAnchor.constraint(equalTo: trailingView.topAnchor),
|
|
155
|
+
trailingGrabber.bottomAnchor.constraint(equalTo: trailingView.bottomAnchor),
|
|
156
|
+
trailingGrabber.leadingAnchor.constraint(equalTo: trailingView.leadingAnchor),
|
|
157
|
+
trailingGrabber.trailingAnchor.constraint(equalTo: trailingView.trailingAnchor)
|
|
158
|
+
])
|
|
112
159
|
}
|
|
113
160
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
161
|
+
private func updateColor() {
|
|
162
|
+
let color = UIColor.systemYellow
|
|
163
|
+
leadingView.backgroundColor = color
|
|
164
|
+
trailingView.backgroundColor = color
|
|
165
|
+
topView.backgroundColor = color
|
|
166
|
+
bottomView.backgroundColor = color
|
|
117
167
|
}
|
|
118
168
|
}
|
|
119
|
-
|