feat: 优化OptimizedDynamicCardView以增强用户交互体验
- 移除不必要的卡片点击手势逻辑,简化代码结构。 - 在内容层和互动按钮中添加allowsHitTesting(false)以确保不拦截点击事件,提升用户交互流畅性。 - 重新添加卡片点击手势逻辑,确保在非详情页模式下的交互功能正常工作。
This commit is contained in:
@@ -42,15 +42,6 @@ struct OptimizedDynamicCardView: View {
|
||||
.shadow(color: Color(red: 0.43, green: 0.43, blue: 0.43, opacity: 0.34), radius: 10.7, x: 0, y: 1.9)
|
||||
}
|
||||
|
||||
// 卡片点击手势 - 仅在非详情页模式且有回调时显示
|
||||
if !isDetailMode, let onCardTap = onCardTap {
|
||||
Color.clear
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
onCardTap()
|
||||
}
|
||||
}
|
||||
|
||||
// 内容层
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
// 用户信息
|
||||
@@ -71,14 +62,17 @@ struct OptimizedDynamicCardView: View {
|
||||
}
|
||||
.frame(width: 40, height: 40)
|
||||
.clipShape(Circle())
|
||||
.allowsHitTesting(false) // 不拦截点击事件
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(moment.nick)
|
||||
.font(.system(size: 16, weight: .medium))
|
||||
.foregroundColor(.white)
|
||||
.allowsHitTesting(false) // 不拦截点击事件
|
||||
Text("ID: \(moment.uid)")
|
||||
.font(.system(size: 12))
|
||||
.foregroundColor(.white.opacity(0.6))
|
||||
.allowsHitTesting(false) // 不拦截点击事件
|
||||
}
|
||||
Spacer()
|
||||
// 时间(原VIP位置)
|
||||
@@ -89,6 +83,7 @@ struct OptimizedDynamicCardView: View {
|
||||
.padding(.vertical, 2)
|
||||
.background(Color.white.opacity(0.15))
|
||||
.cornerRadius(4)
|
||||
.allowsHitTesting(false) // 不拦截点击事件
|
||||
}
|
||||
|
||||
// 动态内容
|
||||
@@ -98,6 +93,7 @@ struct OptimizedDynamicCardView: View {
|
||||
.foregroundColor(.white.opacity(0.9))
|
||||
.multilineTextAlignment(.leading)
|
||||
.padding(.leading, 40 + 8) // 与用户名左边对齐
|
||||
.allowsHitTesting(false) // 不拦截点击事件
|
||||
}
|
||||
|
||||
// 优化的图片网格
|
||||
@@ -107,6 +103,7 @@ struct OptimizedDynamicCardView: View {
|
||||
onImageTap(urls, tappedIndex)
|
||||
}
|
||||
.padding(.bottom, images.count == 2 ? 46 : 0) // 两张图片时增加底部间距
|
||||
.allowsHitTesting(true) // 图片网格需要响应点击事件
|
||||
}
|
||||
|
||||
// 互动按钮
|
||||
@@ -133,11 +130,19 @@ struct OptimizedDynamicCardView: View {
|
||||
}
|
||||
.disabled(isLikeLoading)
|
||||
.padding(.leading, 40 + 8) // 与用户名左侧对齐(头像宽度 + 间距)
|
||||
.allowsHitTesting(true) // Like 按钮需要响应点击事件
|
||||
Spacer()
|
||||
}
|
||||
.padding(.top, 8)
|
||||
}
|
||||
.padding(16)
|
||||
// 卡片点击手势 - 仅在非详情页模式且有回调时显示
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
if !isDetailMode, let onCardTap = onCardTap {
|
||||
onCardTap()
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
preloadNearbyImages()
|
||||
|
Reference in New Issue
Block a user