feat: 完善机巢图传、拍摄阶段与任务交互
- 完善双路 RTC 接收、首帧切换及拍摄结束后的本地播放释放 - 对齐无人机状态枚举与正常拍完返航标记,新增到达后本地倒计时 - 补充准备页电量与前往回执,进入任务时移除准备页路由 - 对齐拍摄中和拍摄完成原型布局,移除详情按钮 - 补充隔离测试、接口记录与项目约定 验证:最近 157 项相关模拟器隔离测试通过,Release 无签名编译通过;未调用真实飞控或图传。
This commit is contained in:
@@ -6,7 +6,7 @@ import UIKit
|
||||
final class DroneDockTaskStatusView: UIView {
|
||||
/// 当前状态的主操作,由页面协调执行,不在组件中调用接口。
|
||||
var onPrimaryAction: (() -> Void)?
|
||||
/// 展开完整状态说明,由页面提供详情展示。
|
||||
/// 点击失败原因区域时展开完整说明,由页面协调展示。
|
||||
var onDetails: (() -> Void)?
|
||||
/// 当前内容采用的字号和间距参考比例,始终介于 0.8 与 1。
|
||||
private(set) var effectiveScale: CGFloat = 1
|
||||
@@ -18,12 +18,15 @@ final class DroneDockTaskStatusView: UIView {
|
||||
private let iconView = UIImageView()
|
||||
private let titleLabel = DroneDockStyle.label(size: 22, weight: .semibold)
|
||||
private let messageLabel = DroneDockStyle.label(size: 14, color: DroneDockStyle.secondary)
|
||||
private let countdownLabel = DroneDockStyle.label(size: 13, weight: .medium, color: DroneDockStyle.primary)
|
||||
private let deviceLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary)
|
||||
private let actionRow = UIView()
|
||||
private let primaryButton = UIButton(type: .system)
|
||||
private let detailsButton = UIButton(type: .system)
|
||||
private let failureView = DroneDockTaskFailureView()
|
||||
private let completedView = DroneDockTaskCompletedView()
|
||||
private let shootingView = DroneDockTaskShootingView()
|
||||
private var presentation: DroneDockTaskPresentation?
|
||||
private var countdownSeconds: Int?
|
||||
private var contentTop: Constraint?
|
||||
private var contentLeading: Constraint?
|
||||
private var contentTrailing: Constraint?
|
||||
@@ -33,7 +36,7 @@ final class DroneDockTaskStatusView: UIView {
|
||||
private var messageHeight: Constraint?
|
||||
private var deviceHeight: Constraint?
|
||||
|
||||
/// 创建稳定的标题、说明、设备摘要与操作槽,所有状态复用同一组视图。
|
||||
/// 创建固定状态槽,完成、失败与进行中使用各自的内容布局。
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
setupUI()
|
||||
@@ -51,9 +54,30 @@ final class DroneDockTaskStatusView: UIView {
|
||||
/// 更新真实状态与动作许可;刷新期间保留内容,只暂时禁用主操作。
|
||||
func apply(_ presentation: DroneDockTaskPresentation, isRefreshing: Bool = false) {
|
||||
self.presentation = presentation
|
||||
updateCountdown(seconds: presentation.countdownSeconds)
|
||||
let isFailure = presentation.phase == .failed
|
||||
contentStack.isHidden = isFailure
|
||||
let isCompleted = [.postShootUploading, .completed].contains(presentation.phase)
|
||||
let isShooting = presentation.phase == .shooting
|
||||
contentStack.isHidden = isFailure || isCompleted || isShooting
|
||||
failureView.isHidden = !isFailure
|
||||
completedView.isHidden = !isCompleted
|
||||
shootingView.isHidden = !isShooting
|
||||
completedView.setIdentifiersActive(isCompleted)
|
||||
shootingView.setIdentifiersActive(isShooting)
|
||||
titleLabel.accessibilityIdentifier = isCompleted || isShooting ? nil : "drone.task.remote.statusTitle"
|
||||
messageLabel.accessibilityIdentifier = isCompleted || isShooting ? nil : "drone.task.remote.statusMessage"
|
||||
if isShooting {
|
||||
primaryButton.accessibilityIdentifier = nil
|
||||
shootingView.apply(presentation)
|
||||
setNeedsLayout()
|
||||
return
|
||||
}
|
||||
if isCompleted {
|
||||
primaryButton.accessibilityIdentifier = nil
|
||||
completedView.apply(presentation, isRefreshing: isRefreshing)
|
||||
setNeedsLayout()
|
||||
return
|
||||
}
|
||||
if isFailure {
|
||||
failureView.apply(presentation, isRefreshing: isRefreshing)
|
||||
setNeedsLayout()
|
||||
@@ -76,8 +100,33 @@ final class DroneDockTaskStatusView: UIView {
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
/// 只刷新已到达阶段的剩余秒数,不变更主操作、服务端阶段或执行任何回调。
|
||||
func updateCountdown(seconds: Int?) {
|
||||
let value = presentation?.phase == .ready ? seconds.map { max(0, $0) } : nil
|
||||
guard value != countdownSeconds else { return }
|
||||
let visibilityChanged = (value == nil) != (countdownSeconds == nil)
|
||||
countdownSeconds = value
|
||||
countdownLabel.text = value.map { "自动开拍倒计时:\($0) 秒" }
|
||||
countdownLabel.isHidden = value == nil
|
||||
if visibilityChanged { setNeedsLayout() }
|
||||
}
|
||||
|
||||
/// 尺寸改变时仅重排内部内容,保留至少 44 点操作区域,不使用 transform 缩放。
|
||||
override func layoutSubviews() {
|
||||
if presentation?.phase == .shooting {
|
||||
super.layoutSubviews()
|
||||
shootingView.layoutIfNeeded()
|
||||
effectiveScale = shootingView.effectiveScale
|
||||
usesCompactLayout = shootingView.usesCompactLayout
|
||||
return
|
||||
}
|
||||
if let phase = presentation?.phase, [.postShootUploading, .completed].contains(phase) {
|
||||
super.layoutSubviews()
|
||||
completedView.layoutIfNeeded()
|
||||
effectiveScale = 1
|
||||
usesCompactLayout = completedView.usesCompactLayout
|
||||
return
|
||||
}
|
||||
if presentation?.phase == .failed {
|
||||
super.layoutSubviews()
|
||||
failureView.layoutIfNeeded()
|
||||
@@ -91,6 +140,11 @@ final class DroneDockTaskStatusView: UIView {
|
||||
|
||||
private func setupUI() {
|
||||
backgroundColor = .white
|
||||
addSubview(shootingView)
|
||||
shootingView.isHidden = true
|
||||
addSubview(completedView)
|
||||
completedView.isHidden = true
|
||||
completedView.onViewMaterials = { [weak self] in self?.onPrimaryAction?() }
|
||||
addSubview(failureView)
|
||||
failureView.isHidden = true
|
||||
failureView.onDetails = { [weak self] in self?.onDetails?() }
|
||||
@@ -101,6 +155,7 @@ final class DroneDockTaskStatusView: UIView {
|
||||
addSubview(contentStack)
|
||||
contentStack.addArrangedSubview(titleRow)
|
||||
contentStack.addArrangedSubview(messageLabel)
|
||||
contentStack.addArrangedSubview(countdownLabel)
|
||||
contentStack.addArrangedSubview(deviceLabel)
|
||||
contentStack.addArrangedSubview(actionRow)
|
||||
titleRow.addSubview(iconView)
|
||||
@@ -113,28 +168,25 @@ final class DroneDockTaskStatusView: UIView {
|
||||
messageLabel.numberOfLines = 3
|
||||
messageLabel.lineBreakMode = .byTruncatingTail
|
||||
messageLabel.accessibilityIdentifier = "drone.task.remote.statusMessage"
|
||||
countdownLabel.font = .monospacedDigitSystemFont(ofSize: 13, weight: .medium)
|
||||
countdownLabel.numberOfLines = 1
|
||||
countdownLabel.isHidden = true
|
||||
countdownLabel.accessibilityIdentifier = "drone.task.remote.countdown"
|
||||
deviceLabel.numberOfLines = 1
|
||||
deviceLabel.lineBreakMode = .byTruncatingTail
|
||||
deviceLabel.accessibilityIdentifier = "drone.task.remote.deviceStatus"
|
||||
actionRow.addSubview(primaryButton)
|
||||
actionRow.addSubview(detailsButton)
|
||||
primaryButton.layer.cornerRadius = 9
|
||||
primaryButton.titleLabel?.font = .systemFont(ofSize: 15, weight: .semibold)
|
||||
primaryButton.titleLabel?.lineBreakMode = .byTruncatingTail
|
||||
primaryButton.setTitleColor(.white, for: .normal)
|
||||
primaryButton.setTitleColor(.white.withAlphaComponent(0.9), for: .disabled)
|
||||
primaryButton.addTarget(self, action: #selector(primaryTapped), for: .touchUpInside)
|
||||
detailsButton.setTitle("详情", for: .normal)
|
||||
detailsButton.setTitleColor(DroneDockStyle.primary, for: .normal)
|
||||
detailsButton.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium)
|
||||
detailsButton.backgroundColor = DroneDockStyle.background
|
||||
detailsButton.layer.cornerRadius = 9
|
||||
detailsButton.accessibilityIdentifier = "drone.task.remote.details"
|
||||
detailsButton.accessibilityLabel = "查看完整任务状态"
|
||||
detailsButton.addTarget(self, action: #selector(detailsTapped), for: .touchUpInside)
|
||||
}
|
||||
|
||||
private func setupConstraints() {
|
||||
shootingView.snp.makeConstraints { $0.edges.equalToSuperview() }
|
||||
completedView.snp.makeConstraints { $0.edges.equalToSuperview() }
|
||||
failureView.snp.makeConstraints { make in make.edges.equalToSuperview() }
|
||||
contentStack.snp.makeConstraints { make in
|
||||
contentTop = make.top.equalToSuperview().offset(12).constraint
|
||||
@@ -151,23 +203,20 @@ final class DroneDockTaskStatusView: UIView {
|
||||
make.trailing.centerY.equalToSuperview()
|
||||
}
|
||||
messageLabel.snp.makeConstraints { make in messageHeight = make.height.equalTo(34).priority(999).constraint }
|
||||
countdownLabel.snp.makeConstraints { make in make.height.equalTo(ceil(countdownLabel.font.lineHeight)).priority(999) }
|
||||
deviceLabel.snp.makeConstraints { make in deviceHeight = make.height.equalTo(16).priority(999).constraint }
|
||||
actionRow.snp.makeConstraints { make in make.height.equalTo(44) }
|
||||
detailsButton.snp.makeConstraints { make in
|
||||
make.top.trailing.bottom.equalToSuperview()
|
||||
make.width.equalTo(64)
|
||||
}
|
||||
primaryButton.snp.makeConstraints { make in
|
||||
make.top.leading.bottom.equalToSuperview()
|
||||
make.trailing.equalTo(detailsButton.snp.leading).offset(-8)
|
||||
make.edges.equalToSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
private func updateContentLayout() {
|
||||
guard let presentation, bounds.width > 0, bounds.height > 0 else { return }
|
||||
let isExtreme = bounds.height < 120
|
||||
let hasCountdown = countdownSeconds != nil
|
||||
let horizontalInset: CGFloat = isExtreme ? 12 : 16
|
||||
let verticalInset: CGFloat = isExtreme ? 6 : 12
|
||||
let verticalInset: CGFloat = isExtreme ? (hasCountdown ? 4 : 6) : 12
|
||||
let width = max(1, bounds.width - horizontalInset * 2)
|
||||
let availableHeight = max(1, bounds.height - verticalInset * 2)
|
||||
let message = DroneDockHomeMetric.usableText(presentation.message)
|
||||
@@ -179,18 +228,20 @@ final class DroneDockTaskStatusView: UIView {
|
||||
width: width - 46, lines: 2))
|
||||
let naturalMessage = hasMessage ? Self.textHeight(message, font: .systemFont(ofSize: 14), width: width, lines: 3) : 0
|
||||
let naturalDevice = hasDevice ? UIFont.systemFont(ofSize: 12).lineHeight : 0
|
||||
let naturalGaps = CGFloat(1 + (hasMessage ? 1 : 0) + (hasDevice ? 1 : 0)) * 10
|
||||
let naturalHeight = naturalTitle + naturalMessage + naturalDevice + 44 + naturalGaps
|
||||
let countdownTextHeight = hasCountdown ? ceil(countdownLabel.font.lineHeight) : 0
|
||||
let naturalGaps = CGFloat(1 + (hasMessage ? 1 : 0) + (hasDevice ? 1 : 0) + (hasCountdown ? 1 : 0)) * 10
|
||||
let naturalHeight = naturalTitle + naturalMessage + countdownTextHeight + naturalDevice + 44 + naturalGaps
|
||||
effectiveScale = min(1, max(0.8, availableHeight / max(1, naturalHeight)))
|
||||
usesCompactLayout = bounds.height < 190 || naturalHeight * effectiveScale > availableHeight
|
||||
|
||||
// 先收紧图标和间距;只有不足九成空间时才缩小文字。
|
||||
let fontScale: CGFloat = effectiveScale >= 0.9 ? 1 : effectiveScale / 0.9
|
||||
titleLabel.font = .systemFont(ofSize: max(17, 22 * fontScale), weight: .semibold)
|
||||
titleLabel.font = .systemFont(ofSize: isExtreme && hasCountdown ? 17 : max(17, 22 * fontScale), weight: .semibold)
|
||||
messageLabel.font = .systemFont(ofSize: max(12, 14 * fontScale))
|
||||
deviceLabel.font = .systemFont(ofSize: 12)
|
||||
let icon: CGFloat = isExtreme ? 20 : usesCompactLayout ? 24 : 36 * effectiveScale
|
||||
let gap: CGFloat = isExtreme ? 4 : max(4, 10 * effectiveScale)
|
||||
let gap: CGFloat = isExtreme ? (hasCountdown ? 2 : 4)
|
||||
: hasCountdown && usesCompactLayout ? 6 : max(4, 10 * effectiveScale)
|
||||
let titleGap: CGFloat = usesCompactLayout ? 8 : 10 * effectiveScale
|
||||
titleLabel.numberOfLines = usesCompactLayout ? 1 : 2
|
||||
messageLabel.numberOfLines = usesCompactLayout ? 2 : 3
|
||||
@@ -204,8 +255,8 @@ final class DroneDockTaskStatusView: UIView {
|
||||
width: width, lines: messageLineCount)
|
||||
let deviceTextHeight = deviceLabel.isHidden ? 0 : ceil(deviceLabel.font.lineHeight)
|
||||
var contentHeight: CGFloat {
|
||||
titleHeight + bodyHeight + deviceTextHeight + 44
|
||||
+ CGFloat(1 + (messageLabel.isHidden ? 0 : 1) + (deviceLabel.isHidden ? 0 : 1)) * gap
|
||||
titleHeight + bodyHeight + countdownTextHeight + deviceTextHeight + 44
|
||||
+ CGFloat(1 + (messageLabel.isHidden ? 0 : 1) + (deviceLabel.isHidden ? 0 : 1) + (hasCountdown ? 1 : 0)) * gap
|
||||
}
|
||||
while contentHeight > availableHeight && messageLineCount > 1 && !messageLabel.isHidden {
|
||||
messageLineCount -= 1
|
||||
@@ -246,7 +297,8 @@ final class DroneDockTaskStatusView: UIView {
|
||||
case .navigating: ("paperplane.fill", DroneDockStyle.primary)
|
||||
case .ready: ("checkmark.circle.fill", DroneDockStyle.success)
|
||||
case .shooting: ("video.fill", DroneDockStyle.primary)
|
||||
case .postShootUploading: ("icloud.and.arrow.up", DroneDockStyle.primary)
|
||||
case .postShootUploading: ("checkmark.circle.fill", DroneDockStyle.success)
|
||||
case .postShootUploadFailed: ("exclamationmark.circle.fill", DroneDockStyle.warning)
|
||||
case .paused: ("pause.circle.fill", DroneDockStyle.warning)
|
||||
case .returning: ("arrow.uturn.backward.circle.fill", DroneDockStyle.warning)
|
||||
case .completed: ("checkmark.circle.fill", DroneDockStyle.success)
|
||||
@@ -261,5 +313,4 @@ final class DroneDockTaskStatusView: UIView {
|
||||
onPrimaryAction?()
|
||||
}
|
||||
|
||||
@objc private func detailsTapped() { onDetails?() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user