feat: 更新CreateFeedFeature和FeedListFeature以增强发布和关闭功能

- 修改CreateFeedFeature中的发布逻辑,确保在发布成功时同时发送关闭通知。
- 更新FeedListFeature以在创建Feed成功时触发刷新并关闭编辑页面。
- 优化CreateFeedView中的键盘管理和通知处理,提升用户体验。
This commit is contained in:
edwinQQQ
2025-07-31 16:44:49 +08:00
parent 65c74db837
commit 57a8b833eb
4 changed files with 121 additions and 103 deletions

View File

@@ -83,9 +83,7 @@ struct CreateFeedFeature {
newImages.append(image)
}
}
await MainActor.run {
send(.updateProcessedImages(newImages))
}
await send(.updateProcessedImages(newImages))
}
case .updateProcessedImages(let images):
@@ -239,17 +237,26 @@ struct CreateFeedFeature {
return .none
case .dismissView:
guard isPresented else {
return .none
}
//
return .run { _ in
await dismiss()
await MainActor.run {
NotificationCenter.default.post(name: .init("CreateFeedDismiss"), object: nil)
}
}
case .publishSuccess:
//
return .run { _ in
NotificationCenter.default.post(name: .init("CreateFeedPublishSuccess"), object: nil)
}
//
return .merge(
.run { _ in
await MainActor.run {
NotificationCenter.default.post(name: .init("CreateFeedPublishSuccess"), object: nil)
}
},
.run { _ in
await MainActor.run {
NotificationCenter.default.post(name: .init("CreateFeedDismiss"), object: nil)
}
}
)
}
}
}

View File

@@ -145,8 +145,11 @@ struct FeedListFeature {
state.isEditFeedPresented = false
return .none
case .createFeedPublishSuccess:
// CreateFeed
return .send(.reload)
// CreateFeed
return .merge(
.send(.reload),
.send(.editFeedDismissed)
)
case .testButtonTapped:
debugInfoSync("[LOG] FeedListFeature testButtonTapped")
return .none

View File

@@ -8,106 +8,111 @@ struct CreateFeedView: View {
@FocusState private var isTextEditorFocused: Bool
var body: some View {
WithPerceptionTracking {
NavigationStack {
GeometryReader { geometry in
VStack(spacing: 0) {
ZStack {
//
Color(hex: 0x0C0527)
.ignoresSafeArea()
//
VStack(spacing: 20) {
ContentInputSection(store: store, isFocused: $isTextEditorFocused)
ImageSelectionSection(store: store)
LoadingAndErrorSection(store: store)
Spacer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
.ignoresSafeArea(.keyboard, edges: .bottom)
.background(Color(hex: 0x0C0527))
}
NavigationStack {
GeometryReader { geometry in
VStack(spacing: 0) {
ZStack {
//
Color(hex: 0x0C0527)
.ignoresSafeArea()
// -
if !isKeyboardVisible {
PublishButtonSection(store: store, geometry: geometry, isFocused: $isTextEditorFocused)
}
}
.onTapGesture {
isTextEditorFocused = false //
}
}
.navigationTitle(NSLocalizedString("createFeed.title", comment: "Image & Text Publish"))
.navigationBarTitleDisplayMode(.inline)
.toolbarBackground(.hidden, for: .navigationBar)
.navigationBarBackButtonHidden(true)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button(action: {
store.send(.dismissView)
}) {
Image(systemName: "xmark")
.font(.system(size: 18, weight: .medium))
.foregroundColor(.white)
//
VStack(spacing: 20) {
ContentInputSection(store: store, isFocused: $isTextEditorFocused)
ImageSelectionSection(store: store)
LoadingAndErrorSection(store: store)
Spacer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
.ignoresSafeArea(.keyboard, edges: .bottom)
.background(Color(hex: 0x0C0527))
}
ToolbarItem(placement: .principal) {
Text(NSLocalizedString("createFeed.title", comment: "Image & Text Publish"))
// -
if !isKeyboardVisible {
PublishButtonSection(store: store, geometry: geometry, isFocused: $isTextEditorFocused)
}
}
.onTapGesture {
isTextEditorFocused = false //
}
}
.navigationTitle(NSLocalizedString("createFeed.title", comment: "Image & Text Publish"))
.navigationBarTitleDisplayMode(.inline)
.toolbarBackground(.hidden, for: .navigationBar)
.navigationBarBackButtonHidden(true)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button(action: {
store.send(.dismissView)
}) {
Image(systemName: "xmark")
.font(.system(size: 18, weight: .medium))
.foregroundColor(.white)
}
// -
ToolbarItem(placement: .navigationBarTrailing) {
if isKeyboardVisible {
Button(action: {
isTextEditorFocused = false //
store.send(.publishButtonTapped)
}) {
HStack(spacing: 4) {
if store.isLoading || store.isUploadingImages {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .white))
.scaleEffect(0.7)
}
Text(toolbarButtonText)
.font(.system(size: 14, weight: .medium))
.foregroundColor(.white)
}
ToolbarItem(placement: .principal) {
Text(NSLocalizedString("createFeed.title", comment: "Image & Text Publish"))
.font(.system(size: 18, weight: .medium))
.foregroundColor(.white)
}
// -
ToolbarItem(placement: .navigationBarTrailing) {
if isKeyboardVisible {
Button(action: {
isTextEditorFocused = false //
store.send(.publishButtonTapped)
}) {
HStack(spacing: 4) {
if store.isLoading || store.isUploadingImages {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .white))
.scaleEffect(0.7)
}
.padding(.horizontal, 12)
.padding(.vertical, 8)
.background(
LinearGradient(
gradient: Gradient(colors: [
Color(hex: 0xF854FC),
Color(hex: 0x500FFF)
]),
startPoint: .leading,
endPoint: .trailing
)
)
.cornerRadius(16)
Text(toolbarButtonText)
.font(.system(size: 14, weight: .medium))
.foregroundColor(.white)
}
.disabled(store.isLoading || store.isUploadingImages || !store.canPublish)
.opacity(toolbarButtonOpacity)
.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)
}
}
}
.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification)) { notification in
if let _ = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect {
}
.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification)) { notification in
if let _ = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect {
DispatchQueue.main.async {
isKeyboardVisible = true
}
}
.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardWillHideNotification)) { _ in
isKeyboardVisible = false
}
.onDisappear {
}
.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardWillHideNotification)) { _ in
DispatchQueue.main.async {
isKeyboardVisible = false
}
}
.onReceive(NotificationCenter.default.publisher(for: .init("CreateFeedDismiss"))) { _ in
store.send(.dismissView)
}
.onDisappear {
isKeyboardVisible = false
}
}
// MARK: -

View File

@@ -255,16 +255,19 @@ struct FeedListView: View {
}
//
.sheet(isPresented: viewStore.binding(get: \.isEditFeedPresented, send: { _ in .editFeedDismissed })) {
CreateFeedView(
store: Store(
initialState: CreateFeedFeature.State()
) {
CreateFeedFeature()
}
)
.onReceive(NotificationCenter.default.publisher(for: .init("CreateFeedPublishSuccess"))) { _ in
store.send(.createFeedPublishSuccess)
let createFeedStore = Store(
initialState: CreateFeedFeature.State()
) {
CreateFeedFeature()
}
CreateFeedView(store: createFeedStore)
.onReceive(NotificationCenter.default.publisher(for: .init("CreateFeedPublishSuccess"))) { _ in
store.send(.createFeedPublishSuccess)
}
.onReceive(NotificationCenter.default.publisher(for: .init("CreateFeedDismiss"))) { _ in
store.send(.editFeedDismissed)
}
}
//
.navigationDestination(isPresented: viewStore.binding(get: \.showDetail, send: { _ in .detailDismissed })) {