-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageTable.swift
81 lines (55 loc) · 2.24 KB
/
MessageTable.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// MessageTable.swift
// MiniSQL Client
//
// Created by Yuanlin Lin on 2021/6/14.
//
import SwiftUI
struct MessageTable: View {
@Binding var messages: [Message]
let taskDateFormat: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "hh:mm:ss"
return formatter
}()
var body: some View {
VStack {
HStack {
Text("Time")
.frame(width: 60,alignment: .leading)
.foregroundColor(Color.white)
Divider().frame(height: 12)
Text("Query")
.frame(width: 180, alignment: .leading)
.foregroundColor(Color.white)
Divider().frame(height: 12)
Text("Message").frame(width: 90, alignment: .leading)
.foregroundColor(Color.white)
Spacer()
}
.padding(4)
.background(Color.gray)
ScrollViewReader { scrollProxy in
ScrollView {
ForEach(messages, id: \.id) { i in
HStack {
Text("\(i.time, formatter: taskDateFormat)").frame(width: 60, alignment: .leading).foregroundColor(Color.gray)
Divider()
Text(i.query).lineLimit(1).frame(width: 180, alignment: .leading)
Divider()
Text(i.content)
Spacer()
}
.id(i.id)
}
}
.padding(4)
.onChange(of: messages.count) { id in
withAnimation {
scrollProxy.scrollTo(messages.last?.id)
}
}
}
}.background(Color.white)
}
}