mirror of
https://github.com/StikDebug/StikDebug.git
synced 2026-10-15 20:10:30 +00:00
fix scrolling
This commit is contained in:
parent
255f545fcb
commit
08ea80e4d2
1 changed files with 7 additions and 6 deletions
|
|
@ -96,21 +96,22 @@ struct ConsoleLogsView: View {
|
|||
GeometryReader { geometry in
|
||||
Color.clear.preference(
|
||||
key: ScrollOffsetPreferenceKey.self,
|
||||
value: geometry.frame(in: .named("scroll")).maxY
|
||||
value: geometry.frame(in: .named("scroll")).minY
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
.coordinateSpace(name: "scroll")
|
||||
.onPreferenceChange(ScrollOffsetPreferenceKey.self) { offset in
|
||||
let threshold: CGFloat = 50
|
||||
let scrollViewHeight = UIScreen.main.bounds.height
|
||||
isAtBottom = offset < (scrollViewHeight + threshold)
|
||||
// Consider user is at bottom if they're within 20 points of the bottom
|
||||
// This gives a small buffer for slight scroll movements
|
||||
isAtBottom = offset > -20
|
||||
}
|
||||
.onChange(of: logManager.logs.count) { _ in
|
||||
.onChange(of: logManager.logs) { newLogs in
|
||||
// Only auto-scroll if we're already at the bottom
|
||||
if isAtBottom {
|
||||
withAnimation {
|
||||
if let lastLog = logManager.logs.last {
|
||||
if let lastLog = newLogs.last {
|
||||
proxy.scrollTo(lastLog.id, anchor: .bottom)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue