feat: 更新CreateFeedFeature和CreateFeedView以增强发布功能

- 修改发布逻辑,允许在内容为空时仍可发布图片,提升用户灵活性。
- 更新错误提示信息,明确用户需要输入内容或选择图片。
- 调整发布按钮显示逻辑,仅在键盘隐藏时显示,优化界面布局。
- 增加工具栏标题,提升用户界面友好性。
- 优化发布按钮样式,增加圆角和渐变背景,提升视觉效果。
This commit is contained in:
edwinQQQ
2025-07-31 16:21:32 +08:00
parent d6b4f58825
commit 65c74db837
2 changed files with 29 additions and 12 deletions

View File

@@ -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

View File

@@ -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))
}