So I have made a successful dynamic TextEditor but when I try to combine views, it overlaps the other elements and no longer expands as you type. I am pretty sure this has to do with Geometry Reader but I am not sure how to do it without that. Thanks!
ScrollView {
GeometryReader { geometry in
VStack{
ZStack(alignment: .leading) {
Text(text).foregroundColor(.clear)
.padding(14)
.font(.custom("Times", size: 14))
.background(GeometryReader {
Color.clear.preference(key: viewheightkey3.self, value: $0.frame(in: .local).size.height)
})
.frame(width: geometry.size.width * 0.9)
TextEditor(text: $text)
.padding(6)
.foregroundColor(.white)
.frame(width: geometry.size.width * 0.9)
.frame(height: height)
.frame(minHeight: 100)
.background(Color.black)
}
.padding(20)
.onPreferenceChange(viewheightkey3.self) { height = $0 }
}
}
struct viewheightkey3: PreferenceKey {
static var defaultValue: CGFloat { 0 }
static func reduce(value: inout Value, nextValue: () -> Value) {
value = value + nextValue()
}
}