title: UITextView - adjust size based on the content in SwiftUI
body: <p>I am trying to figure out how to make UITextView size dependent on it's contents in SwiftUI. I wrapped the UITextView in <code>UIViewRepresentable</code> as following:</p>
  
  <pre><code>struct TextView: UIViewRepresentable {
  
      @Binding var showActionSheet: Bool
  
      func makeCoordinator() -&gt; Coordinator {
          Coordinator(self)
      }
  
      func makeUIView(context: Context) -&gt; UITextView {
  
          let uiTextView = UITextView()
          uiTextView.delegate = context.coordinator
  
          uiTextView.font = UIFont(name: "HelveticaNeue", size: 15)
          uiTextView.isScrollEnabled = true
          uiTextView.isEditable = true
          uiTextView.isUserInteractionEnabled = true
          uiTextView.backgroundColor = UIColor(white: 0.0, alpha: 0.05)
          uiTextView.isEditable = false
  
          return uiTextView
      }
  
      func updateUIView(_ uiView: UITextView, context: Context) {
          uiView.attributedText = prepareText(question: question)
  
          var frame = uiView.frame
          frame.size.height = uiView.contentSize.height
          uiView.frame = frame
      }
  
      func prepareText(text: string) -&gt; NSMutableAttributedString {
          ...................
          return attributedText
      }
  
      class Coordinator : NSObject, UITextViewDelegate {
  
          var parent: TextView
  
          init(_ view: TextView) {
              self.parent = view
          }
  
          func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -&gt; Bool {
              parent.showActionSheet = true
              return false
          }
      }
  }
  </code></pre>
  
  <p>Further, I tried to change the frame size in updateUIView based on it's content size, but it did not have any effect. I suppose that at this stage, the view is not even layout and its frame is being overridden somewhere else. I would really appreciate if someone could point me in a correct direction.</p>