Message Bubble Basic
Chat speech bubble with tail shape, dynamic color by sender, and timestamp.
SwiftUI Implementation
Pure Vanilla Swift • No DependenciesmessageBubbleBasic.swift
import SwiftUI
struct UseMessageBubbleBasic: View {
var body: some View {
VStack {
MessageBubbleBasic(msgDateTime: Date.now, msgText: "Ahoy, know Compot?", isMsgFromUser: false)
MessageBubbleBasic(msgDateTime: Date.now, msgText: "Yeah, crazy, right! What's your favorite component?", isMsgFromUser: true)
}
.padding()
}
}
#Preview {
UseMessageBubbleBasic()
}
struct MessageBubbleBasic: View {
var msgDateTime: Date?
var msgText: String
var isMsgFromUser: Bool
var body: some View {
VStack(alignment: .center, spacing: 8) {
dateTime()
HStack {
text
}
.frame(maxWidth: .infinity, alignment: isMsgFromUser ? .trailing : .leading)
}
.frame(maxWidth: .infinity, alignment: .center)
.padding(.vertical, 4)
}
@ViewBuilder
private func dateTime() -> some View {
if let dateTime = msgDateTime {
Text(dateTime, format: Date.FormatStyle(date: .complete, time: .shortened))
.font(.caption2)
.foregroundStyle(.secondary)
}
}
private var text: some View {
VStack {
Text(msgText)
.font(.system(size: 17))
.foregroundStyle(isMsgFromUser ? .white : .primary)
.multilineTextAlignment(.leading)
.padding(.horizontal, 12)
.padding(.vertical, 8)
.background(isMsgFromUser ? Color.blue : Color(uiColor: .secondarySystemFill))
.clipShape(RoundedRectangle(cornerRadius: 16, style: .continuous))
}
.frame(maxWidth: UIScreen.main.bounds.width * 0.75, alignment: isMsgFromUser ? .trailing : .leading)
}
}Ready to copy and paste directly into any Xcode project running iOS 16.0+.
Recommended Use Cases
- Dashboard overviews, stats tracking, and metric highlights
Component Details
- Category
- Shapes, Chat & Real-Time
- iOS Compatibility
- iOS 16.0+
- Xcode Version
- Xcode 15+
- Platform
- iOS
- License Tier
- Pro
- Themes & Contexts
- dashboard
- Keywords
- messagebubblechattext
C
Compot for iOS
Native SwiftUI playground app
Preview all 130+ components interactively on your device and copy code straight to Xcode with 1 tap.
Get Compot on the App StoreRelated SwiftUI Components
More components in Shapes, Chat & Real-Time and related app architectures.
ButtonsiOS 16.0+
Bouncy Button Icon
Interactive button featuring fluid spring animations and smooth scale feedback upon tap.
View Component & Code
ButtonsiOS 16.0+
Button with Repeat Behavior
Stepper-like button with continuous press-and-hold repeating action for counters and volume adjustment.
View Component & Code
ButtonsiOS 16.0+
Button for Copying
Smart copy button that temporarily switches icon and text to "Copied!" with tactile haptic feedback.
View Component & Code