Newer
Older
var actionPublisher: AnyPublisher<ScanDisplayShareView.Action, Never> {
shareSheetView.actionPublisher.eraseToAnyPublisher()
}
private let copyLabel = UILabel()
private let codeButton = ScanQRButton()
private let copyImageView = UIImageView()
private let copyContainerButton = UIControl()
private var cancellables = Set<AnyCancellable>()
private let shareSheetView = ScanDisplayShareView()
init() {
super.init(frame: .zero)
backgroundColor = Asset.neutralDark.color
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
copyImageView.image = Asset.scanCopy.image
copyLabel.text = Localized.Scan.Display.copy
copyLabel.textColor = Asset.neutralDisabled.color
copyLabel.font = Fonts.Mulish.semiBold.font(size: 13.0)
codeButton.publisher(for: .touchUpInside)
.merge(with: copyContainerButton.publisher(for: .touchUpInside))
.sink { [unowned self] in
UIGraphicsBeginImageContext(codeButton.frame.size)
codeButton.layer.render(in: UIGraphicsGetCurrentContext()!)
let output = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(output!, nil, nil, nil)
codeButton.blinkCopied()
}.store(in: &cancellables)
addSubview(codeButton)
addSubview(copyContainerButton)
copyContainerButton.addSubview(copyLabel)
copyContainerButton.addSubview(copyImageView)
addSubview(shareSheetView)
codeButton.snp.makeConstraints {
$0.centerX.equalTo(safeAreaLayoutGuide)
$0.centerY.equalTo(safeAreaLayoutGuide).multipliedBy(0.6)
$0.width.equalTo(safeAreaLayoutGuide).multipliedBy(0.6)
$0.height.equalTo(codeButton.snp.width)
}
copyContainerButton.snp.makeConstraints {
$0.top.equalTo(codeButton.snp.bottom).offset(33)
$0.centerX.equalTo(codeButton)
}
copyImageView.snp.makeConstraints {
$0.top.equalToSuperview()
$0.left.equalToSuperview()
$0.bottom.equalToSuperview()
}
copyLabel.snp.makeConstraints {
$0.top.equalToSuperview()
$0.left.equalTo(copyImageView.snp.right).offset(5)
$0.right.equalToSuperview()
$0.bottom.equalToSuperview()
shareSheetView.snp.makeConstraints {
$0.left.equalToSuperview()
$0.right.equalToSuperview()
$0.bottom.equalToSuperview()
func setup(code image: CIImage) {
codeButton.setup(code: image)
}
func setupAttributes(
email: String?,
phone: String?,
emailSharing: Bool,
phoneSharing: Bool
) {
if let email = email {
shareSheetView.setup(email: .init(content: email, isVisible: emailSharing))
} else {
shareSheetView.setup(email: nil)
}
if let phone = phone {
shareSheetView.setup(phone: .init(content: phone, isVisible: phoneSharing))
} else {
shareSheetView.setup(phone: nil)