-
Notifications
You must be signed in to change notification settings - Fork 47
feat: optimize FeedDetailPage list to reduce jumping #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -44,6 +44,7 @@ struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable { | |||||
| @State var isKeyboardVisiable = false | ||||||
| @State private var isLoadingMore = false | ||||||
| @State private var contentReady = false | ||||||
| @State private var repliesReady = false | ||||||
| @FocusState private var replyIsFocused: Bool | ||||||
| var initData: FeedInfo.Item? = nil | ||||||
| var id: String | ||||||
|
|
@@ -206,8 +207,12 @@ struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable { | |||||
| // Content Section | ||||||
| if !isContentEmpty { | ||||||
| NewsContentView(state.model.contentInfo) { | ||||||
| withAnimation { | ||||||
| contentReady = true | ||||||
| contentReady = true | ||||||
| // Show replies after a short delay for smoother transition | ||||||
| DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) { | ||||||
| withAnimation(.easeInOut(duration: 0.2)) { | ||||||
| repliesReady = true | ||||||
| } | ||||||
| } | ||||||
|
Comment on lines
+212
to
216
|
||||||
| } | ||||||
| .padding(.horizontal, 10) | ||||||
|
|
@@ -216,31 +221,31 @@ struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable { | |||||
| .listRowBackground(Color.itemBg) | ||||||
| } | ||||||
|
|
||||||
| // Show postscripts and replies only after content is ready | ||||||
| if contentReady || isContentEmpty { | ||||||
| // Postscripts Section (附言) | ||||||
| ForEach(state.model.postscripts) { postscript in | ||||||
| PostscriptItemView(postscript: postscript) | ||||||
| .listRowInsets(EdgeInsets()) | ||||||
| .listRowSeparator(.hidden) | ||||||
| .listRowBackground(Color.itemBg) | ||||||
| } | ||||||
| // Postscripts Section (附言) - always in layout, fade in when ready | ||||||
| ForEach(state.model.postscripts) { postscript in | ||||||
| PostscriptItemView(postscript: postscript) | ||||||
| .listRowInsets(EdgeInsets()) | ||||||
| .listRowSeparator(.hidden) | ||||||
| .listRowBackground(Color.itemBg) | ||||||
| .opacity(contentReady || isContentEmpty ? 1 : 0) | ||||||
| } | ||||||
|
|
||||||
| // Reply Section Header with Sort Toggle | ||||||
| if !state.model.replyInfo.items.isEmpty { | ||||||
| replySectionHeader | ||||||
| .listRowInsets(EdgeInsets()) | ||||||
| .listRowSeparator(.hidden) | ||||||
| .listRowBackground(Color.itemBg) | ||||||
| } | ||||||
| // Reply Section Header with Sort Toggle | ||||||
| if !state.model.replyInfo.items.isEmpty { | ||||||
| replySectionHeader | ||||||
| .listRowInsets(EdgeInsets()) | ||||||
| .listRowSeparator(.hidden) | ||||||
| .listRowBackground(Color.itemBg) | ||||||
| .opacity(repliesReady || isContentEmpty ? 1 : 0) | ||||||
| } | ||||||
|
|
||||||
| // Reply Section | ||||||
| ForEach(sortedReplies, id: \.floor) { item in | ||||||
| ReplyItemView(info: item, topicId: id) | ||||||
| .listRowInsets(EdgeInsets()) | ||||||
| .listRowSeparator(.hidden) | ||||||
| .listRowBackground(Color.itemBg) | ||||||
| } | ||||||
| // Reply Section - always in layout, fade in when ready | ||||||
| ForEach(sortedReplies, id: \.floor) { item in | ||||||
| ReplyItemView(info: item, topicId: id) | ||||||
| .listRowInsets(EdgeInsets()) | ||||||
| .listRowSeparator(.hidden) | ||||||
| .listRowBackground(Color.itemBg) | ||||||
| .opacity(repliesReady || isContentEmpty ? 1 : 0) | ||||||
| } | ||||||
|
|
||||||
| // Load More Indicator | ||||||
|
|
@@ -272,6 +277,8 @@ struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable { | |||||
| .scrollContentBackground(.hidden) | ||||||
| .background(Color.itemBg) | ||||||
| .environment(\.defaultMinListRowHeight, 1) | ||||||
| .animation(.easeIn(duration: 0.15), value: contentReady) | ||||||
| .animation(.easeIn(duration: 0.15), value: repliesReady) | ||||||
|
Comment on lines
+280
to
+281
|
||||||
| .animation(.easeIn(duration: 0.15), value: contentReady) | |
| .animation(.easeIn(duration: 0.15), value: repliesReady) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The state variables
contentReadyandrepliesReadyare not reset when new data is loaded. When a user pulls to refresh or when data is reloaded, these states remaintrue, preventing the staged appearance animation from running again. Consider adding anonChangehandler that resets these states whenstate.modelchanges or when a refresh begins.