aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Views/ChatView.swift
blob: 532a89087f49f487483d56de3a49f348a1262c1b (plain)
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
import SwiftUI

struct ChatView: View {
//  @Binding private var input: String
  @State var input: String = ""
  @State private var scrollPos: Int?
  @State private var contentHeight: CGFloat = 0
  
  var body: some View {
    VStack(spacing: 0) {
      GeometryReader { geometry in
        ScrollView(.vertical) {
          ScrollViewReader { scrollReader in
            VStack(alignment: .leading) {
              Spacer()
              LazyVStack(alignment: .leading, spacing: 10) {
                HStack(alignment: .firstTextBaseline) {
                  Text("bolt:").bold().fontDesign(.monospaced).frame(minWidth: 60)
                  Text("hello!").fontDesign(.monospaced).textSelection(.enabled)
                }
                ForEach(0..<50) { i in
                  HStack(alignment: .firstTextBaseline) {
                    Text("mierau:").bold().fontDesign(.monospaced)
                    Text("g'day to you. what's going on this afternoon?")
                      .fontDesign(.monospaced)
                      .textSelection(.enabled)
                  }
                }
                Text("").font(.system(size: 0)).id("bottomScroll")
              }
              .padding()
            }
            //          .frame(width: geometry.size.width)
            .frame(minHeight: geometry.size.height)
//            .background(Color.red)
            .onAppear() {
              scrollReader.scrollTo("bottomScroll", anchor: .bottom)
            }
            //          .onChange() {
            //            scrollReader.scrollTo(10000, anchor: .bottomTrailing)
            //          }
          }
        }
      }
      
      Divider()
      
      HStack(alignment: .top) {
        Image(systemName: "chevron.right")
        TextField("This is a chat topic", text: $input, axis: .vertical)
          .lineLimit(1...5)
          .onSubmit {
            //        HotlineClient.shared.sendChat(message: self.input)
            self.input = ""
          }
      }.padding()
    }
  }
}

#Preview {
  ChatView()
}