The message field is a UI component for sending messages.
When creating a MessageField
, you can provide an action for how to handle a new MessageStyle
information in the onSend
parameter. MessageStyle
can contain different types of messages, such as text, media (photo, video, document, contact), and voice.
MessageField { messageStyle in
viewModel.sendMessage($0)
}
- text
- voice
- photo library
- giphy
- location
- camera (coming soon)
- document (coming soon)
- contacts (coming soon)
MessageField(isMenuItemPresented: $isMenuItemPresented) { ... }
if isMenuItemPresented {
MyMenuItemList()
}
To send a location, you can use the LocationSelector
component, which presents a UI for the user to select a location. When the user taps the send location button, the onSend
action of the MessageField
is called.
NOTE:
If you want to use
sendMessagePublisher
insteadonSend
, please refer to Sending a new message by using publisher
@State private var showsLocationSelector: Bool = false
var body: some View {
LocationSelector(isPresented: $showsLocationSelector)
}
public var sendMessagePublisher: PassthroughSubject<MessageStyle, Never>
sendMessagePublisher
is a Combine Publisher
that passes MessageStyle
object.
To publish a new message, you can create a new MessageStyle
object and send it using send(_:)
.
let _ = Empty<Void, Never>()
.sink(
receiveCompletion: { _ in
// Create `MessageStyle` object
let style = MessageStyle.text("{TEXT}")
// Publish the created style object via `send(_:)`
sendMessagePublisher.send(style)
},
receiveValue: { _ in }
)
You can subscribe to sendMessagePublisher
to handle new messages.
.onReceive(sendMessagePublisher) { messageStyle in
// Handle `messageStyle` here (e.g., sending message with the style)
}
- rating system
- answering by defined message