If you want to create a chat feature with messages that take up multiple lines, this project might be useful for you.
SwiftUI doesn’t have a built-in text box like UITextView
, so you need to create a custom one.
Also, UITextView
doesn’t support placeholders. This component solves both problems by allowing placeholders and
automatically expanding up to a set height.
- Custom
TextViewWrapper
to integrateUITextView
into SwiftUI. MultilineTextInputView
that supports placeholders and dynamic height adjustment.ChatView
to display messages in a chat-like interface.
- TextViewWrapper: A
UIViewRepresentable
that wrapsUITextView
for use in SwiftUI. - MultilineTextInputView: A SwiftUI view that uses
TextViewWrapper
to provide a text input field with placeholder support and dynamic height adjustment. - ChatView: A SwiftUI view that displays a list of messages and includes the
MultilineTextInputView
for message input.
Ensure that you have the necessary components (TextViewWrapper
, MultilineTextInputView
, and ChatView
) included in your project.
This project is inspired by the need to implement multiline text input in SwiftUI and aims to provide a reusable solution for the community.