I want to have a placeholder when there is no text in the texteditor, is working well, but the placeholder is not on the same line with the cursor of the TextEditor. I tried to replace the TextEditor with a textfield and it worked just fine, but I need a TextEditor. How can I put the TextEditor text and placeholder on the same line ? Thanks.
ZStack(alignment: .topLeading) {
VStack {
TextEditor(text: $currentText)
.rchFont(.rchBody, .primaryLighter)
.frame(maxWidth: .infinity, alignment: .leading)
.onChange(of: currentText) { value in
if value.count > 1000 {
currentText = oldText
return
}
oldText = currentText
currentCharCount = "\(value.count)"
}
Spacer()
Text("\(currentCharCount)/1000")
.rchFont(.rchBody, .primaryLighter)
.frame(maxWidth: .infinity, alignment: .trailing)
RCHButtonPrimary(title: messageButtonTitle) {
text = currentText
presentationMode.wrappedValue.dismiss()
}
}
if currentText.isEmpty {
Text(placeholder)
.rchFont(.rchBody, .textSupport)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
Hard to try and understand what you are trying to achieve as both views you present have .infinity but you seem to want to replace the TextEditor with the Text(placeholder). Ideally would need to see what is in the TextEditor view to understand what you say about the cursor not being on the same line.
Here is an example of what I referred to in my comment by swapping the field lower down in the view hierarchy which swaps just the base component, rather than a large view you are effectively covering up and hoping the positioning is the same.