In this code, the TextEditor uses .constant(...), which makes the text read-only. This means users can’t type or change the text. If you want to make the text editable, you should use a @State variable instead. This way, the text inside the editor can be updated by the user.
Also i think, some of the paddings can be adjusted.
here is fixed code:
struct TextPageView: View {
@State private var text: String
var page: Page
init(page: Page) {
self.page = page
// Provide an initial value for the @State variable,
// so the TextEditor is editable instead of read-only
_text = State(initialValue: page.content.string ?? "no text")
}
var body: some View {
ScrollView {
Text(text)
VStack(alignment: .leading) {
TextEditor(text: $text)
.font(.system(.body, design: .serif))
.lineLimit(nil)
.fixedSize(horizontal: false, vertical: true)
.multilineTextAlignment(.leading)
.padding(.trailing, 12)
.padding(.bottom, 40)
.background(Color.red) // add background for visibility
}
}
.padding([.leading, .top], 12)
.navigationTitle(page.content.title ?? "(No Title)")
}
}
when your string is nil now you can see "no text"