From 08ea80e4d21a078632b16361a17b51e2c05a784c Mon Sep 17 00:00:00 2001 From: neoarz Date: Fri, 11 Apr 2025 11:57:01 -0400 Subject: [PATCH] fix scrolling --- StikJIT/Views/ConsoleLogsView.swift | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/StikJIT/Views/ConsoleLogsView.swift b/StikJIT/Views/ConsoleLogsView.swift index 695d6aa..3150419 100644 --- a/StikJIT/Views/ConsoleLogsView.swift +++ b/StikJIT/Views/ConsoleLogsView.swift @@ -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) } }