I'm working with a wrapped UITextView
via UIViewRepresentable
. This textView is supposed to be as high es required, based on its content, i.e. the (attributed)string.
struct TextView: UIViewRepresentable {
@Binding var text: String
func makeUIView(context: Context) -> UITextView {
let textView = UITextView()
textView.isScrollEnabled = false
textView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
return textView
}
func updateUIView(_ uiView: UITextView, context: Context) {
uiView.text = text
}
}
This works fine:
struct TextView_Previews: PreviewProvider {
static var previews: some View {
TextView(text: .constant("some multiline\na\nb\nc\nd\nlorem ipsum"))
}
}
Doesn't work
struct TextView_Previews: PreviewProvider {
static var previews: some View {
ScrollView { // <- when placed inside ScrollView the height is reduced to one line
TextView(text: .constant("some multiline\na\nb\nc\nd\nlorem ipsum"))
}
}
}
How can this be fixed?