// // TextEditorWithPlaceholder.swift // WorkoutsPlus // // Created by Felix Förtsch on 01.10.24. // import SwiftUI struct TextEditorWithPlaceholder: View { @Binding var text: String var placeholder: String var body: some View { ZStack(alignment: .topLeading) { // TODO: If focused, hide placeholder. if text.isEmpty { Text(placeholder) .foregroundColor(Color(UIColor.placeholderText)) } TextEditor(text: $text) .frame(minHeight: 40, maxHeight: .infinity) .cornerRadius(8) } } } #Preview { @Previewable @State var text = "" Form { TextEditorWithPlaceholder(text: $text, placeholder: "Description (optional)") } }