|
@@ -8,36 +8,61 @@
|
|
|
import SwiftUI
|
|
|
|
|
|
struct MessageView: View {
|
|
|
- let text: String
|
|
|
- let time: String
|
|
|
- let isSelf: Bool
|
|
|
- var body: some View {
|
|
|
- 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))
|
|
|
- )
|
|
|
- }
|
|
|
+ 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 {
|
|
|
- MessageView(text: "Малое пробное сообщение", time: "23:05", isSelf: true)
|
|
|
- .padding()
|
|
|
- .previewLayout(.sizeThatFits)
|
|
|
- MessageView(text: "Пробное сообщение на несколько строк для проверки того, как выглядит сообщение и его фон", time: "23:08", isSelf: false)
|
|
|
- .padding()
|
|
|
- .previewLayout(.sizeThatFits)
|
|
|
- }
|
|
|
+ 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()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|