Skip to content

Commit 7c69a31

Browse files
committed
feat: doing handle footer for preview controller
1 parent 451661e commit 7c69a31

File tree

5 files changed

+118
-22
lines changed

5 files changed

+118
-22
lines changed

example/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,12 @@ PODS:
330330
- React-jsinspector (0.71.5)
331331
- React-logger (0.71.5):
332332
- glog
333-
- react-native-multiple-image-picker (1.0.2):
333+
- react-native-multiple-image-picker (1.0.3):
334334
- CropViewController (= 2.6.1)
335335
- React-Core
336-
- react-native-multiple-image-picker/Viewer (= 1.0.2)
336+
- react-native-multiple-image-picker/Viewer (= 1.0.3)
337337
- TLPhotoPicker (= 2.1.9)
338-
- react-native-multiple-image-picker/Viewer (1.0.2):
338+
- react-native-multiple-image-picker/Viewer (1.0.3):
339339
- CropViewController (= 2.6.1)
340340
- React-Core
341341
- TLPhotoPicker (= 2.1.9)
@@ -618,7 +618,7 @@ SPEC CHECKSUMS:
618618
React-jsiexecutor: 1579bf3207afadc72ac3638a66a102d1bf5263e3
619619
React-jsinspector: 14a342151ab810862998dfc99e2720746734e9b3
620620
React-logger: 94ec392ae471683635e4bf874d4e82f675399d2d
621-
react-native-multiple-image-picker: bf07238dbbd6ba7928f01705d85584ac0d7b27a1
621+
react-native-multiple-image-picker: 83b0fe4a14eaa7ae6fd5e5af46d7706ce26b2c7b
622622
React-perflogger: 883a55a9a899535eaf06d0029108ef9ef22cce92
623623
React-RCTActionSheet: 1a3b8416688a3d291367be645022886f71d6842a
624624
React-RCTAnimation: e5560cb72d91ba35151d51e2eb0d467b42763f43

ios/CustomPhotoPicker/Cell.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class Cell: TLPhotoCollectionViewCell {
3131

3232
// Xử lý sự kiện Long Press
3333
@objc private func handleLongPress(_ gestureRecognizer: UILongPressGestureRecognizer) {
34-
guard gestureRecognizer.state == .began,
35-
let collectionView = superview as? UICollectionView
34+
guard gestureRecognizer.state == .began
3635
else {
3736
return
3837
}

ios/CustomPhotoPicker/CustomPhotoPickerViewController.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,18 @@ class CustomPhotoPickerViewController: TLPhotosPickerViewController, ViewerContr
5555

5656
self.viewerController!.dataSource = self
5757

58-
self.viewerController?.viewSafeAreaInsetsDidChange()
59-
6058
let headerView = PreviewHeaderView()
6159
headerView.viewDelegate = self
6260

6361
self.viewerController!.headerView = headerView
6462

63+
if config.singleSelectedMode != true {
64+
let footerView = PreviewFooterView()
65+
footerView.viewDelegate = self
66+
67+
self.viewerController!.footerView = footerView
68+
}
69+
6570
self.present(self.viewerController!, animated: true, completion: nil)
6671
}
6772
}
@@ -105,7 +110,7 @@ class CustomPhotoPickerViewController: TLPhotosPickerViewController, ViewerContr
105110
}
106111
}
107112

108-
extension CustomPhotoPickerViewController: PreviewHeaderViewDelegate {
113+
extension CustomPhotoPickerViewController: PreviewHeaderViewDelegate, PreviewFooterViewDelegate {
109114
func headerView(_: PreviewHeaderView, didPressClearButton _: UIButton) {
110115
self.viewerController?.dismiss(nil)
111116
}
@@ -117,4 +122,8 @@ extension CustomPhotoPickerViewController: PreviewHeaderViewDelegate {
117122
})
118123
}
119124
}
125+
126+
func footerView(_: PreviewFooterView, didPressSelectButton _: UIButton) {
127+
self.viewerController?.dismiss(nil)
128+
}
120129
}

ios/Preview/PreviewFooter.swift

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//
2+
// PreviewFooter.swift
3+
// react-native-multiple-image-picker
4+
//
5+
// Created by BẢO HÀ on 15/09/2023.
6+
//
7+
8+
import TLPhotoPicker
9+
import UIKit
10+
11+
protocol PreviewFooterViewDelegate: AnyObject {
12+
func footerView(_ headerView: PreviewFooterView, didPressSelectButton button: UIButton)
13+
}
14+
15+
class PreviewFooterView: TLPhotoCollectionViewCell {
16+
weak var viewDelegate: PreviewFooterViewDelegate?
17+
18+
lazy var selectButton: UIButton = {
19+
let button = UIButton(type: .system)
20+
21+
button.addTarget(self, action: #selector(PreviewFooterView.selectAction(button:)), for: .touchUpInside)
22+
button.frame = CGRect(x: 0, y: 0, width: 24, height: 24)
23+
//
24+
// button.layer.cornerRadius = 12
25+
// button.clipsToBounds = true
26+
27+
button.backgroundColor = config.selectedColor
28+
29+
button.layer.borderWidth = 1.5
30+
button.layer.borderColor = UIColor.white.cgColor
31+
32+
button.layer.cornerRadius = 16
33+
button.clipsToBounds = true
34+
button.contentEdgeInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)
35+
36+
button.setTitle("1", for: .normal)
37+
button.setTitleColor(.white, for: .normal)
38+
39+
button.translatesAutoresizingMaskIntoConstraints = false
40+
41+
// Tạo constraints để cố định vị trí của tiêu đề ở giữa tuyệt đối (absolute center)
42+
43+
// let label = UILabel()
44+
// label.text = "2"
45+
// label.textColor = UIColor.white // Tuỳ chỉnh màu văn bản theo ý muốn
46+
// label.textAlignment = .center
47+
// label.frame = button.bounds // Đặt kích thước và vị trí của UILabel bằng bằng với UIButton
48+
// button.addSubview(label)
49+
50+
return button
51+
}()
52+
53+
override init(frame: CGRect) {
54+
super.init(frame: frame)
55+
let stackView = UIStackView()
56+
stackView.translatesAutoresizingMaskIntoConstraints = false
57+
stackView.axis = .horizontal
58+
stackView.alignment = .trailing
59+
addSubview(stackView)
60+
61+
self.selectButton.translatesAutoresizingMaskIntoConstraints = false
62+
stackView.addArrangedSubview(self.selectButton)
63+
64+
self.selectButton.centerXAnchor.constraint(equalTo: stackView.centerXAnchor).isActive = true
65+
self.selectButton.centerYAnchor.constraint(equalTo: stackView.centerYAnchor).isActive = true
66+
67+
// (Tuỳ chọn) Đặt constraints cho chiều rộng và chiều cao của UIButton
68+
self.selectButton.widthAnchor.constraint(equalToConstant: 32).isActive = true
69+
self.selectButton.heightAnchor.constraint(equalToConstant: 32).isActive = true
70+
71+
NSLayoutConstraint.activate([
72+
stackView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20),
73+
])
74+
}
75+
76+
@available(*, unavailable)
77+
required init?(coder _: NSCoder) {
78+
fatalError("init(coder:) has not been implemented")
79+
}
80+
81+
override func layoutSubviews() {
82+
super.layoutSubviews()
83+
}
84+
85+
@objc func selectAction(button: UIButton) {
86+
self.viewDelegate?.footerView(self, didPressSelectButton: button)
87+
}
88+
}

ios/Preview/PreviewHeader.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class PreviewHeaderView: UIView {
99
weak var viewDelegate: PreviewHeaderViewDelegate?
1010

1111
lazy var clearButton: UIButton = {
12-
let image = UIImage.close.setTintColor(.black)?.resize(to: .init(width: 18, height: 18))
12+
let image = UIImage.close.resize(to: .init(width: 18, height: 18))
1313

1414
let button = UIButton(type: .custom)
1515

@@ -21,26 +21,27 @@ class PreviewHeaderView: UIView {
2121
}()
2222

2323
lazy var doneButton: UIButton = {
24-
let button = UIButton(type: .system) // Sử dụng type .system cho button với giao diện người dùng tiêu chuẩn
24+
let button = UIButton(type: .system)
2525

26-
// Đặt tiêu đề (text) cho button
2726
button.setTitle(config.doneTitle, for: .normal)
27+
button.setTitleColor(.white, for: .normal)
28+
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)
29+
button.addTarget(self, action: #selector(PreviewHeaderView.doneAction(button:)), for: .touchUpInside)
30+
button.backgroundColor = config.selectedColor
2831

29-
// Đặt màu chữ và màu nền cho button (tuỳ chọn)
30-
button.setTitleColor(config.selectedColor, for: .normal)
32+
button.contentEdgeInsets = UIEdgeInsets(top: 8, left: 14, bottom: 8, right: 14)
3133

32-
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: UIFont.labelFontSize)
34+
button.layer.cornerRadius = 6.0
3335

34-
button.addTarget(self, action: #selector(PreviewHeaderView.doneAction(button:)), for: .touchUpInside)
36+
button.setContentHuggingPriority(.required, for: .vertical)
37+
button.setContentCompressionResistancePriority(.required, for: .vertical)
3538

3639
return button
3740
}()
3841

3942
override init(frame: CGRect) {
4043
super.init(frame: frame)
4144

42-
self.backgroundColor = .white
43-
4445
let stackView = UIStackView()
4546
stackView.translatesAutoresizingMaskIntoConstraints = false
4647
stackView.axis = .horizontal
@@ -55,10 +56,9 @@ class PreviewHeaderView: UIView {
5556
stackView.addArrangedSubview(self.doneButton)
5657

5758
NSLayoutConstraint.activate([
58-
stackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 24),
59-
stackView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -24),
60-
stackView.topAnchor.constraint(equalTo: topAnchor),
61-
stackView.bottomAnchor.constraint(equalTo: bottomAnchor),
59+
stackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 20),
60+
stackView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20),
61+
stackView.topAnchor.constraint(equalTo: topAnchor, constant: 12),
6262
])
6363
}
6464

0 commit comments

Comments
 (0)