1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- //
- // MessageView.swift
- // Chat
- //
- // Created by Sergey Tarasov on 24.07.2022.
- //
- import SwiftUI
- struct MessageView: View {
- let text: String
- let time: String
- let isSelf: Bool
- var body: some View {
- HStack {
- if isSelf {
- Spacer(minLength: 40)
- }
- HStack(alignment: .bottom) {
- Text(text)
- .foregroundColor(.primary)
- .padding(.vertical, 6)
- .padding(.horizontal, 12)
- Text(time)
- .font(.caption)
- .foregroundColor(.secondary)
- .padding(.vertical, 6)
- .padding(.trailing, 12)
- .padding(.leading, -12)
- }
- .background(
- RoundedRectangle(cornerRadius: 17)
- .foregroundColor(isSelf ? .mint.opacity(0.1) : .secondary.opacity(0.1))
- )
- if !isSelf {
- Spacer(minLength: 40)
- }
- }
- }
- }
- struct MessageView_Previews: PreviewProvider {
- static var previews: some View {
- MessageTestView()
- }
- struct MessageTestView: View {
- @State var messageText1: String = "Малое пробное сообщение"
- @State var messageText2: String = "Пробное сообщение на несколько строк для проверки того, как выглядит сообщение и его фон"
- var body: some View {
- VStack {
- ScrollView {
- VStack(spacing: 6) {
- MessageView(text: messageText1, time: "23:05", isSelf: true)
- MessageView(text: messageText2, time: "23:08", isSelf: false)
- }
- }
- TextField("Message", text: $messageText1)
- .textFieldStyle(.roundedBorder)
- TextField("Message", text: $messageText2)
- .textFieldStyle(.roundedBorder)
- }
- .padding()
- }
- }
- }
|