Redesign nearby transfer and cloud delivery screens

This commit is contained in:
2026-11-05 09:27:52 +08:00
parent 7d69a8ae7e
commit 477bf611e6
9 changed files with 1017 additions and 185 deletions
@@ -11,6 +11,7 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
var onClose: (() -> Void)?
private let customerTitle: String
private let orderNumber: String?
private let videoPicker: (@MainActor () async throws -> DroneDockDeliveryVideo?)?
private var operationTask: Task<Void, Never>?
private var metadataTask: Task<Void, Never>?
@@ -26,12 +27,19 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
private var previousGestureEnabled: Bool?
private let scrollView = UIScrollView()
private let content = UIStackView()
private let customerLabel = DroneDockStyle.label(size: 13, color: DroneDockStyle.secondary)
private let customerView = DroneDockDeliveryCustomerView()
private let thumbnail = DroneDockDeliveryVideoThumbnailView()
private let footerContent = UIStackView()
private let statusDot = UIView()
private let receiveTitle = DroneDockStyle.label("扫码接收视频", size: 25, weight: .bold)
private let emptyCodeView = UIImageView(image: UIImage(systemName: "qrcode.viewfinder"))
private let codeFrame = DroneDockNearbyQRCodeFrameView()
private var primaryHeight: Constraint?
private let fileLabel = DroneDockStyle.label("尚未选择视频", size: 16, weight: .semibold)
private let fileDetailLabel = DroneDockStyle.label("选择一段已在本机的视频", size: 12, color: DroneDockStyle.secondary)
private let chooseButton = UIButton(type: .system)
private let previewButton = UIButton(type: .system)
private let statusLabel = DroneDockStyle.label("准备闪传", size: 18, weight: .semibold)
private let statusLabel = DroneDockStyle.label("准备闪传", size: 14, weight: .semibold)
private let statusDetailLabel = DroneDockStyle.label(size: 13, color: DroneDockStyle.secondary)
private let qrContainer = UIView()
private let qrView = UIImageView()
@@ -41,12 +49,13 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
private let progressLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary)
private let footer = UIView()
private let primaryButton = UIButton(type: .system)
private let footerLabel = DroneDockStyle.label("无需互联网 · 请双方保持连接同一 Wi-Fi", size: 11, color: DroneDockStyle.secondary)
private let footerLabel = DroneDockStyle.label("仅发送所选视频,无需上传云端", size: 12, color: DroneDockStyle.secondary)
/// 注入本地服务和测试视频选择器;默认使用禁止云端取片的本地相册选择器。
init(customerTitle: String, viewModel: DroneDockNearbyTransferViewModel = DroneDockNearbyTransferViewModel(),
init(customerTitle: String, orderNumber: String? = nil, viewModel: DroneDockNearbyTransferViewModel = DroneDockNearbyTransferViewModel(),
videoPicker: (@MainActor () async throws -> DroneDockDeliveryVideo?)? = nil) {
self.customerTitle = customerTitle
self.orderNumber = orderNumber
self.viewModel = viewModel
self.videoPicker = videoPicker
super.init(nibName: nil, bundle: nil)
@@ -67,81 +76,81 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
override func setupNavigationBar() {
title = "面对面闪传"
let back = UIBarButtonItem(title: "交付方式", style: .plain, target: self, action: #selector(backTapped))
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = DroneDockDeliveryDesign.background
appearance.shadowColor = .clear
appearance.titleTextAttributes = [.foregroundColor: DroneDockDeliveryDesign.text,
.font: UIFont.systemFont(ofSize: 19, weight: .semibold)]
navigationItem.standardAppearance = appearance
navigationItem.scrollEdgeAppearance = appearance
navigationItem.compactAppearance = appearance
let back = UIBarButtonItem(image: UIImage(systemName: "chevron.left"), style: .plain, target: self, action: #selector(backTapped))
back.accessibilityLabel = "返回交付方式"
back.tintColor = DroneDockDeliveryDesign.text
back.accessibilityIdentifier = "drone.nearby.back"
navigationItem.leftBarButtonItem = back
let close = UIBarButtonItem(image: UIImage(systemName: "xmark"), style: .plain, target: self, action: #selector(closeTapped))
close.tintColor = DroneDockDeliveryDesign.text
close.accessibilityLabel = "关闭面对面闪传"
close.accessibilityIdentifier = "drone.nearby.close"
navigationItem.rightBarButtonItem = close
}
override func setupUI() {
view.backgroundColor = DroneDockStyle.background
view.backgroundColor = DroneDockDeliveryDesign.background
scrollView.alwaysBounceVertical = true
scrollView.showsVerticalScrollIndicator = false
scrollView.accessibilityIdentifier = "drone.nearby.content"
content.axis = .vertical
content.spacing = 14
customerLabel.text = customerTitle
customerLabel.numberOfLines = 0
content.addArrangedSubview(customerLabel)
let networkTitle = DroneDockStyle.label("1 连接同一 Wi-Fi", size: 15, weight: .semibold)
let networkDetail = DroneDockStyle.label("请商家和游客连接同一 Wi-Fi。没有现场 Wi-Fi 时,可手动连接同一手机热点。", size: 13, color: DroneDockStyle.secondary)
networkDetail.numberOfLines = 0
content.addArrangedSubview(card([networkTitle, networkDetail]))
let videoTitle = DroneDockStyle.label("2 选择本地视频", size: 15, weight: .semibold)
fileLabel.numberOfLines = 2
fileLabel.accessibilityIdentifier = "drone.nearby.fileName"
fileDetailLabel.numberOfLines = 0
fileDetailLabel.accessibilityIdentifier = "drone.nearby.fileDetail"
chooseButton.setTitle("选择视频", for: .normal)
chooseButton.titleLabel?.font = .systemFont(ofSize: 14, weight: .semibold)
chooseButton.accessibilityIdentifier = "drone.nearby.chooseVideo"
previewButton.setTitle("预览", for: .normal)
previewButton.setImage(UIImage(systemName: "play.circle"), for: .normal)
previewButton.accessibilityIdentifier = "drone.nearby.preview"
let videoActions = UIStackView(arrangedSubviews: [chooseButton, previewButton])
videoActions.spacing = 18
videoActions.distribution = .fillEqually
videoActions.snp.makeConstraints { $0.height.equalTo(44) }
content.addArrangedSubview(card([videoTitle, fileLabel, fileDetailLabel, videoActions]))
let sessionTitle = DroneDockStyle.label("3 游客扫码接收", size: 15, weight: .semibold)
statusLabel.textColor = DroneDockStyle.primary
statusLabel.accessibilityIdentifier = "drone.nearby.status"
statusDetailLabel.numberOfLines = 0
statusDetailLabel.accessibilityIdentifier = "drone.nearby.statusDetail"
qrView.contentMode = .scaleAspectFit
qrView.accessibilityIdentifier = "drone.nearby.qr"
qrView.isAccessibilityElement = true
qrView.accessibilityLabel = "请游客用系统相机扫描此二维码"
qrContainer.addSubview(qrView)
qrContainer.snp.makeConstraints { $0.height.equalTo(212) }
qrView.snp.makeConstraints { make in make.center.equalToSuperview(); make.size.equalTo(204) }
addressButton.titleLabel?.font = .monospacedSystemFont(ofSize: 11, weight: .regular)
addressButton.titleLabel?.numberOfLines = 2
addressButton.accessibilityIdentifier = "drone.nearby.copyAddress"
addressButton.setTitle("复制接收地址", for: .normal)
addressButton.snp.makeConstraints { $0.height.greaterThanOrEqualTo(44) }
expiryLabel.textAlignment = .center
expiryLabel.numberOfLines = 0
expiryLabel.accessibilityIdentifier = "drone.nearby.expiry"
progressView.progressTintColor = DroneDockStyle.primary
progressView.accessibilityIdentifier = "drone.nearby.progress"
progressLabel.textAlignment = .center
progressLabel.accessibilityIdentifier = "drone.nearby.progressText"
content.addArrangedSubview(card([sessionTitle, statusLabel, statusDetailLabel, qrContainer, addressButton, expiryLabel, progressView, progressLabel]))
content.spacing = 10
customerView.apply(title: customerTitle, orderNumber: orderNumber)
customerView.accessibilityIdentifier = "drone.nearby.customer"
DroneDockDeliveryDesign.card(to: customerView)
content.addArrangedSubview(customerView)
content.addArrangedSubview(makeNetworkHint())
content.addArrangedSubview(makeVideoCard())
content.addArrangedSubview(makeReceiveCard())
footer.backgroundColor = .white
footer.accessibilityIdentifier = "drone.nearby.footer"
let separator = UIView()
separator.backgroundColor = DroneDockDeliveryDesign.border
footer.addSubview(separator)
separator.snp.makeConstraints { make in make.top.leading.trailing.equalToSuperview(); make.height.equalTo(0.5) }
footerContent.axis = .vertical
footerContent.spacing = 6
footer.addSubview(footerContent)
[addressButton, primaryButton, footerLabel].forEach(footerContent.addArrangedSubview)
var configuration = UIButton.Configuration.filled()
configuration.title = "复制接收地址"
configuration.image = UIImage(systemName: "link")
configuration.imagePadding = 8
configuration.preferredSymbolConfigurationForImage = .init(pointSize: 20, weight: .medium)
configuration.baseForegroundColor = .white
configuration.background.backgroundColor = DroneDockDeliveryDesign.primary
configuration.background.cornerRadius = 12
configuration.cornerStyle = .fixed
configuration.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { attributes in
var result = attributes
result.font = .systemFont(ofSize: 17, weight: .semibold)
return result
}
addressButton.configuration = configuration
addressButton.accessibilityIdentifier = "drone.nearby.copyAddress"
addressButton.snp.makeConstraints { $0.height.equalTo(48).priority(999) }
primaryButton.layer.cornerRadius = 12
primaryButton.titleLabel?.font = .systemFont(ofSize: 16, weight: .semibold)
primaryButton.setTitleColor(.white, for: .normal)
primaryButton.setTitleColor(DroneDockStyle.secondary, for: .disabled)
primaryButton.setTitleColor(DroneDockDeliveryDesign.secondary, for: .disabled)
primaryButton.accessibilityIdentifier = "drone.nearby.primary"
primaryButton.snp.makeConstraints { primaryHeight = $0.height.equalTo(48).constraint }
footerLabel.textAlignment = .center
footerLabel.numberOfLines = 0
footerLabel.textColor = DroneDockDeliveryDesign.secondary
view.addSubview(scrollView)
scrollView.addSubview(content)
view.addSubview(footer)
[primaryButton, footerLabel].forEach(footer.addSubview)
render()
}
@@ -152,20 +161,134 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
make.bottom.equalTo(footer.snp.top)
}
content.snp.makeConstraints { make in
make.edges.equalTo(scrollView.contentLayoutGuide).inset(16)
make.width.equalTo(scrollView.frameLayoutGuide).offset(-32)
make.edges.equalTo(scrollView.contentLayoutGuide).inset(UIEdgeInsets(top: 12, left: 20, bottom: 12, right: 20))
make.width.equalTo(scrollView.frameLayoutGuide).offset(-40)
}
footer.snp.makeConstraints { $0.leading.trailing.bottom.equalToSuperview() }
primaryButton.snp.makeConstraints { make in
footerContent.snp.makeConstraints { make in
make.top.equalToSuperview().offset(12)
make.leading.trailing.equalToSuperview().inset(16)
make.height.equalTo(48)
make.leading.trailing.equalToSuperview().inset(20)
make.bottom.equalTo(footer.safeAreaLayoutGuide).offset(-8)
}
footerLabel.snp.makeConstraints { make in
make.top.equalTo(primaryButton.snp.bottom).offset(9)
make.leading.trailing.equalTo(primaryButton)
make.bottom.equalTo(footer.safeAreaLayoutGuide).offset(-10)
}
private func makeNetworkHint() -> UIView {
let hint = UIView()
hint.backgroundColor = DroneDockDeliveryDesign.primary.withAlphaComponent(0.08)
hint.layer.cornerRadius = 14
hint.accessibilityIdentifier = "drone.nearby.networkHint"
let icon = UIImageView(image: UIImage(systemName: "wifi"))
icon.tintColor = DroneDockDeliveryDesign.primary
icon.contentMode = .scaleAspectFit
let divider = UIView()
divider.backgroundColor = DroneDockDeliveryDesign.primary.withAlphaComponent(0.16)
let title = DroneDockStyle.label("双方连接同一 Wi-Fi 或手机热点", size: 14, weight: .semibold,
color: DroneDockDeliveryDesign.text)
title.numberOfLines = 0
let detail = DroneDockStyle.label("无需互联网,传输时请保持本页亮屏", size: 12, color: DroneDockDeliveryDesign.secondary)
detail.numberOfLines = 0
let labels = UIStackView(arrangedSubviews: [title, detail])
labels.axis = .vertical
labels.spacing = 4
[icon, divider, labels].forEach(hint.addSubview)
icon.snp.makeConstraints { make in make.leading.equalToSuperview().offset(16); make.centerY.equalToSuperview(); make.size.equalTo(30) }
divider.snp.makeConstraints { make in make.leading.equalTo(icon.snp.trailing).offset(12); make.centerY.equalToSuperview(); make.width.equalTo(1); make.height.equalTo(34) }
labels.snp.makeConstraints { make in
make.leading.equalTo(divider.snp.trailing).offset(12)
make.trailing.equalToSuperview().inset(14)
make.top.bottom.equalToSuperview().inset(10)
}
return hint
}
private func makeVideoCard() -> UIView {
let title = DroneDockStyle.label("本次发送", size: 16, weight: .semibold, color: DroneDockDeliveryDesign.text)
chooseButton.setTitle("选择视频", for: .normal)
chooseButton.titleLabel?.font = .systemFont(ofSize: 14, weight: .semibold)
chooseButton.tintColor = DroneDockDeliveryDesign.primary
chooseButton.accessibilityIdentifier = "drone.nearby.chooseVideo"
chooseButton.snp.makeConstraints { make in make.height.equalTo(44); make.width.greaterThanOrEqualTo(72).priority(999) }
let heading = UIStackView(arrangedSubviews: [title, UIView(), chooseButton])
heading.alignment = .center
heading.spacing = 6
fileLabel.numberOfLines = 2
fileLabel.textColor = DroneDockDeliveryDesign.text
fileLabel.accessibilityIdentifier = "drone.nearby.fileName"
fileDetailLabel.numberOfLines = 0
fileDetailLabel.textColor = DroneDockDeliveryDesign.secondary
fileDetailLabel.accessibilityIdentifier = "drone.nearby.fileDetail"
let labels = UIStackView(arrangedSubviews: [fileLabel, fileDetailLabel])
labels.axis = .vertical
labels.spacing = 5
let video = UIView()
thumbnail.accessibilityIdentifier = "drone.nearby.videoThumbnail"
video.addSubview(thumbnail)
video.addSubview(labels)
previewButton.setImage(UIImage(systemName: "play.circle.fill"), for: .normal)
previewButton.tintColor = .white
previewButton.setPreferredSymbolConfiguration(.init(pointSize: 28), forImageIn: .normal)
previewButton.accessibilityLabel = "预览本次发送的视频"
previewButton.accessibilityIdentifier = "drone.nearby.preview"
video.addSubview(previewButton)
thumbnail.snp.makeConstraints { make in make.leading.top.bottom.equalToSuperview(); make.width.equalTo(104); make.height.equalTo(62) }
previewButton.snp.makeConstraints { $0.edges.equalTo(thumbnail) }
labels.snp.makeConstraints { make in
make.leading.equalTo(thumbnail.snp.trailing).offset(12)
make.trailing.equalToSuperview()
make.centerY.equalTo(thumbnail)
make.top.greaterThanOrEqualToSuperview()
make.bottom.lessThanOrEqualToSuperview()
}
let result = card([heading, video], spacing: 8)
result.accessibilityIdentifier = "drone.nearby.videoCard"
return result
}
private func makeReceiveCard() -> UIView {
statusDot.backgroundColor = DroneDockDeliveryDesign.primary
statusDot.layer.cornerRadius = 4
statusDot.snp.makeConstraints { $0.size.equalTo(8) }
statusLabel.textColor = DroneDockDeliveryDesign.secondary
statusLabel.numberOfLines = 0
statusLabel.accessibilityIdentifier = "drone.nearby.status"
let status = UIStackView(arrangedSubviews: [statusDot, statusLabel])
status.spacing = 8
status.alignment = .center
let statusRow = UIView()
statusRow.addSubview(status)
status.snp.makeConstraints { make in make.centerX.top.bottom.equalToSuperview(); make.leading.greaterThanOrEqualToSuperview(); make.trailing.lessThanOrEqualToSuperview() }
receiveTitle.textColor = DroneDockDeliveryDesign.text
receiveTitle.textAlignment = .center
receiveTitle.accessibilityIdentifier = "drone.nearby.receiveTitle"
statusDetailLabel.numberOfLines = 0
statusDetailLabel.textAlignment = .center
statusDetailLabel.textColor = DroneDockDeliveryDesign.secondary
statusDetailLabel.accessibilityIdentifier = "drone.nearby.statusDetail"
qrView.contentMode = .scaleAspectFit
qrView.accessibilityIdentifier = "drone.nearby.qr"
qrView.isAccessibilityElement = true
qrView.accessibilityLabel = "请游客用系统相机扫描此二维码"
qrContainer.addSubview(codeFrame)
qrContainer.addSubview(qrView)
qrContainer.snp.makeConstraints { $0.height.equalTo(220).priority(999) }
codeFrame.snp.makeConstraints { make in make.center.equalToSuperview(); make.size.equalTo(220) }
qrView.snp.makeConstraints { make in make.center.equalToSuperview(); make.size.equalTo(196) }
emptyCodeView.contentMode = .scaleAspectFit
emptyCodeView.tintColor = DroneDockDeliveryDesign.primary.withAlphaComponent(0.4)
emptyCodeView.snp.makeConstraints { $0.height.equalTo(72).priority(999) }
emptyCodeView.accessibilityIdentifier = "drone.nearby.emptyCode"
expiryLabel.textAlignment = .center
expiryLabel.font = .systemFont(ofSize: 13)
expiryLabel.textColor = DroneDockDeliveryDesign.secondary
expiryLabel.numberOfLines = 0
expiryLabel.accessibilityIdentifier = "drone.nearby.expiry"
progressView.progressTintColor = DroneDockDeliveryDesign.primary
progressView.accessibilityIdentifier = "drone.nearby.progress"
progressLabel.textAlignment = .center
progressLabel.accessibilityIdentifier = "drone.nearby.progressText"
let result = card([statusRow, receiveTitle, statusDetailLabel, emptyCodeView, qrContainer, expiryLabel, progressView, progressLabel], spacing: 8)
result.accessibilityIdentifier = "drone.nearby.receiveCard"
return result
}
override func bindActions() {
@@ -221,20 +344,19 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
revealedSessionID = sessionID
// 只在新接收码生成后定位一次;下载进度和游客连接事件不抢走用户的滚动位置。
let target = qrContainer.convert(qrContainer.bounds, to: scrollView)
.union(addressButton.convert(addressButton.bounds, to: scrollView))
.union(expiryLabel.convert(expiryLabel.bounds, to: scrollView))
.insetBy(dx: 0, dy: -8)
scrollView.scrollRectToVisible(target, animated: !UIAccessibility.isReduceMotionEnabled)
}
private func card(_ views: [UIView]) -> UIView {
private func card(_ views: [UIView], spacing: CGFloat = 10) -> UIView {
let container = UIView()
DroneDockStyle.applyCard(to: container)
DroneDockDeliveryDesign.card(to: container)
let stack = UIStackView(arrangedSubviews: views)
stack.axis = .vertical
stack.spacing = 10
stack.spacing = spacing
container.addSubview(stack)
stack.snp.makeConstraints { $0.edges.equalToSuperview().inset(16) }
stack.snp.makeConstraints { $0.edges.equalToSuperview().inset(UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)) }
return container
}
@@ -251,8 +373,10 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
previousGestureEnabled = nil
}
chooseButton.isEnabled = state.canChooseVideo && !isPicking
chooseButton.setTitle(isPicking ? "正在准备视频…" : state.video == nil ? "选择视频" : "重新选择", for: .normal)
previewButton.isHidden = state.video == nil
chooseButton.isHidden = state.isActive
chooseButton.setTitle(isPicking ? "正在准备视频…" : state.video == nil ? "选择视频" : "更换", for: .normal)
previewButton.isHidden = state.video == nil || state.isActive
thumbnail.apply(video: state.video)
previewButton.isEnabled = !isPicking && !state.isActive
fileLabel.text = state.video?.fileName ?? "尚未选择视频"
if let video = state.video {
@@ -270,7 +394,7 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
statusDetailLabel.text = "请保持本页打开,正在检查本地连接。"
case .waiting:
statusLabel.text = "等待游客扫码"
statusDetailLabel.text = "请游客先连接同一 Wi-Fi,再用系统相机扫码。传输期间请保持本页亮屏。"
statusDetailLabel.text = "使用系统相机扫码,在浏览器中下载"
case .connected:
statusLabel.text = "游客已打开接收页"
statusDetailLabel.text = state.message ?? "请游客点击“下载视频”开始接收。"
@@ -291,10 +415,15 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
statusDetailLabel.text = state.message
}
}
statusLabel.textColor = state.phase == .sent ? DroneDockStyle.success : state.phase == .failed || state.phase == .interrupted || pickerError != nil ? DroneDockStyle.warning : DroneDockStyle.primary
let tone = state.phase == .sent ? DroneDockStyle.success : state.phase == .failed || state.phase == .interrupted || pickerError != nil ? DroneDockStyle.warning : DroneDockDeliveryDesign.primary
statusDot.backgroundColor = tone
statusLabel.textColor = state.phase == .failed || state.phase == .interrupted || pickerError != nil ? tone : DroneDockDeliveryDesign.secondary
let receiveURL = state.session?.url
qrContainer.isHidden = receiveURL == nil
emptyCodeView.isHidden = receiveURL != nil
receiveTitle.text = receiveURL != nil ? "扫码接收视频" : "面对面,轻松接收"
addressButton.isHidden = receiveURL == nil
addressButton.isEnabled = receiveURL != nil
expiryLabel.isHidden = receiveURL == nil
if let receiveURL {
if qrView.accessibilityValue != receiveURL.absoluteString {
@@ -317,7 +446,10 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
progressLabel.text = "已发送 \(ByteCountFormatter.string(fromByteCount: state.bytesSent, countStyle: .file)) / \(ByteCountFormatter.string(fromByteCount: state.totalBytes, countStyle: .file))"
primaryButton.setTitle(state.isActive ? "结束闪传" : state.phase == .ended || state.phase == .failed ? "重新生成接收码" : "生成接收二维码", for: .normal)
primaryButton.isEnabled = !isPicking && (state.isActive || state.canStart)
primaryButton.backgroundColor = primaryButton.isEnabled ? DroneDockStyle.primary : DroneDockStyle.border
primaryButton.setTitleColor(state.isActive ? .systemRed : .white, for: .normal)
primaryButton.backgroundColor = state.isActive ? .clear : primaryButton.isEnabled ? DroneDockDeliveryDesign.primary : DroneDockDeliveryDesign.border
primaryHeight?.update(offset: state.isActive ? 44 : 48)
footerLabel.isHidden = state.isActive
if let sessionID = state.session?.id, sessionID != revealedSessionID {
pendingRevealSessionID = sessionID
} else if state.session == nil { pendingRevealSessionID = nil }
@@ -462,3 +594,41 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
}
}
}
/// 二维码外围的蓝色取景角,不覆盖二维码或改变扫码内容。
@MainActor
private final class DroneDockNearbyQRCodeFrameView: UIView {
private let corners = CAShapeLayer()
override init(frame: CGRect) {
super.init(frame: frame)
isUserInteractionEnabled = false
corners.fillColor = UIColor.clear.cgColor
corners.strokeColor = DroneDockDeliveryDesign.primary.cgColor
corners.lineWidth = 3
corners.lineCap = .round
layer.addSublayer(corners)
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
override func layoutSubviews() {
super.layoutSubviews()
corners.frame = bounds
let path = UIBezierPath()
let length: CGFloat = 23
let radius: CGFloat = 10
let inset: CGFloat = 2
for (x, y, horizontal, vertical) in [(inset, inset, CGFloat(1), CGFloat(1)),
(bounds.width - inset, inset, -1, 1),
(inset, bounds.height - inset, 1, -1),
(bounds.width - inset, bounds.height - inset, -1, -1)] {
path.move(to: CGPoint(x: x, y: y + vertical * length))
path.addLine(to: CGPoint(x: x, y: y + vertical * radius))
path.addQuadCurve(to: CGPoint(x: x + horizontal * radius, y: y), controlPoint: CGPoint(x: x, y: y))
path.addLine(to: CGPoint(x: x + horizontal * length, y: y))
}
corners.path = path.cgPath
}
}