ENH: ScrollViewReader with full-space background colour

This commit is contained in:
Etienne Roesch 2025-04-05 22:02:22 +01:00
parent 4abda00033
commit 2b61760d94

View file

@ -41,50 +41,56 @@ struct ContentView: View {
self.imageHeight = height self.imageHeight = height
} }
// ScrollView fills remaining height ZStack {
ScrollViewReader { proxy in Color.black
ScrollView { .ignoresSafeArea()
LazyVStack(alignment: .leading, spacing: 0) {
let lines = appState.output.components(separatedBy: .newlines)
ForEach(lines.indices, id: \.self) { index in // ScrollView fills remaining height
Text(lines[index]) ScrollViewReader { proxy in
.font(.system(.body, design: .monospaced)) ScrollView {
.frame(maxWidth: .infinity, alignment: .leading) LazyVStack(alignment: .leading, spacing: 0) {
let lines = appState.output.components(separatedBy: .newlines)
ForEach(lines.indices, id: \.self) { index in
Text(lines[index])
.font(.system(.body, design: .monospaced))
.frame(maxWidth: .infinity, alignment: .leading)
}
Color.clear.frame(height: 1).id("bottom")
} }
.padding()
Color.clear.frame(height: 1).id("bottom")
} }
.padding() .onChange(of: appState.output) { _, _ in
} trimLinesIfNeeded()
.onChange(of: appState.output) { _, _ in withAnimation {
trimLinesIfNeeded() proxy.scrollTo("bottom", anchor: .bottom)
withAnimation { }
proxy.scrollTo("bottom", anchor: .bottom)
} }
}
// ScrollView { // ScrollView {
// VStack(alignment: .leading) { // VStack(alignment: .leading) {
// TextEditor(text: $appState.output) // TextEditor(text: $appState.output)
// .font(.system(.body, design: .monospaced)) // .font(.system(.body, design: .monospaced))
// .frame( // .frame(
// width: geometry.size.width - 60, // width: geometry.size.width - 60,
// height: max(0, geometry.size.height - imageHeight - 120) // - rough height of button row and padding // height: max(0, geometry.size.height - imageHeight - 120) // - rough height of button row and padding
// ) // )
// .padding() // .padding()
// .disabled(true) // .disabled(true)
// //
// Text("") // Text("")
// .id("bottom") // .id("bottom")
// } // }
// } // }
// .onChange(of: appState.output) { _, _ in // .onChange(of: appState.output) { _, _ in
// trimLinesIfNeeded() // trimLinesIfNeeded()
// withAnimation { // withAnimation {
// proxy.scrollTo("bottom", anchor: .bottom) // proxy.scrollTo("bottom", anchor: .bottom)
// } // }
// } // }
}
} }
// Buttons // Buttons