feat: 更新CreateFeedFeature和CreateFeedView以增强发布功能
- 修改发布逻辑,允许在内容为空时仍可发布图片,提升用户灵活性。 - 更新错误提示信息,明确用户需要输入内容或选择图片。 - 调整发布按钮显示逻辑,仅在键盘隐藏时显示,优化界面布局。 - 增加工具栏标题,提升用户界面友好性。 - 优化发布按钮样式,增加圆角和渐变背景,提升视觉效果。
This commit is contained in:
@@ -16,7 +16,7 @@ struct CreateFeedFeature {
|
||||
processedImages.count < 9
|
||||
}
|
||||
var canPublish: Bool {
|
||||
!content.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty && !isLoading
|
||||
(!content.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || !processedImages.isEmpty) && !isLoading
|
||||
}
|
||||
var isLoading: Bool = false
|
||||
|
||||
@@ -108,7 +108,7 @@ struct CreateFeedFeature {
|
||||
|
||||
case .publishButtonTapped:
|
||||
guard state.canPublish else {
|
||||
state.errorMessage = "请输入内容"
|
||||
state.errorMessage = "请输入内容或选择图片"
|
||||
return .none
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ struct CreateFeedFeature {
|
||||
let userId = await UserInfoManager.getCurrentUserId() ?? ""
|
||||
let type = resList.isEmpty ? "0" : "2" // 0: 纯文字, 2: 图片
|
||||
let request = await PublishFeedRequest.make(
|
||||
content: content,
|
||||
content: content.isEmpty ? "" : content,
|
||||
uid: userId,
|
||||
type: type,
|
||||
resList: resList.isEmpty ? nil : resList
|
||||
|
@@ -22,9 +22,6 @@ struct CreateFeedView: View {
|
||||
ContentInputSection(store: store, isFocused: $isTextEditorFocused)
|
||||
ImageSelectionSection(store: store)
|
||||
LoadingAndErrorSection(store: store)
|
||||
|
||||
// 底部间距
|
||||
// Color.clear.frame(height: geometry.safeAreaInsets.bottom + 100)
|
||||
Spacer()
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
|
||||
@@ -32,9 +29,10 @@ struct CreateFeedView: View {
|
||||
.background(Color(hex: 0x0C0527))
|
||||
}
|
||||
|
||||
// 底部发布按钮 - 始终显示
|
||||
PublishButtonSection(store: store, geometry: geometry, isFocused: $isTextEditorFocused)
|
||||
|
||||
// 底部发布按钮 - 只在键盘隐藏时显示
|
||||
if !isKeyboardVisible {
|
||||
PublishButtonSection(store: store, geometry: geometry, isFocused: $isTextEditorFocused)
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
isTextEditorFocused = false // 点击空白处收起键盘
|
||||
@@ -55,6 +53,12 @@ struct CreateFeedView: View {
|
||||
}
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .principal) {
|
||||
Text(NSLocalizedString("createFeed.title", comment: "Image & Text Publish"))
|
||||
.font(.system(size: 18, weight: .medium))
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
|
||||
// 右上角发布按钮 - 只在键盘显示时出现
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
if isKeyboardVisible {
|
||||
@@ -69,9 +73,22 @@ struct CreateFeedView: View {
|
||||
.scaleEffect(0.7)
|
||||
}
|
||||
Text(toolbarButtonText)
|
||||
.font(.system(size: 16, weight: .medium))
|
||||
.font(.system(size: 14, weight: .medium))
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
.padding(.horizontal, 12)
|
||||
.padding(.vertical, 8)
|
||||
.background(
|
||||
LinearGradient(
|
||||
gradient: Gradient(colors: [
|
||||
Color(hex: 0xF854FC),
|
||||
Color(hex: 0x500FFF)
|
||||
]),
|
||||
startPoint: .leading,
|
||||
endPoint: .trailing
|
||||
)
|
||||
)
|
||||
.cornerRadius(16)
|
||||
}
|
||||
.disabled(store.isLoading || store.isUploadingImages || !store.canPublish)
|
||||
.opacity(toolbarButtonOpacity)
|
||||
@@ -250,7 +267,7 @@ struct PublishButtonSection: View {
|
||||
@FocusState.Binding var isFocused: Bool
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
VStack(spacing: 0) {
|
||||
Button(action: {
|
||||
isFocused = false // 收起键盘
|
||||
store.send(.publishButtonTapped)
|
||||
@@ -286,7 +303,7 @@ struct PublishButtonSection: View {
|
||||
.opacity(buttonOpacity)
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.bottom, geometry.safeAreaInsets.bottom + 20)
|
||||
.padding(.bottom, 20) // 使用固定间距,不受键盘影响
|
||||
}
|
||||
.background(Color(hex: 0x0C0527))
|
||||
}
|
||||
|
Reference in New Issue
Block a user