FeatureView.swift 2.7 KB
Newer Older
 Joel  Oksanen's avatar
Joel Oksanen committed
1
2
3
4
5
6
7
8
9
10
11
//
//  FeatureBubble.swift
//  ADAbot
//
//  Created by Joel Oksanen on 24.2.2020.
//  Copyright © 2020 Joel Oksanen. All rights reserved.
//

import SwiftUI

struct FeatureView: View {
12
  @ObservedObject var chatManager: ChatManager
 Joel  Oksanen's avatar
Joel Oksanen committed
13

14
  static let bubbleColor = Color(red: 75/255, green: 90/255, blue: 116/255)
15
  let arguments: [Argument]
16
  @State var showingQueryOptionsForArgument: Argument?
 Joel  Oksanen's avatar
Joel Oksanen committed
17
18
  
  var body: some View {
19
20
    VStack(spacing: 0) {
      if (!chatManager.sent) {
 Joel  Oksanen's avatar
Joel Oksanen committed
21
22
        HStack(spacing: 0) {
          Spacer()
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
          
          Text("ASK ABOUT")
            .foregroundColor(FeatureView.bubbleColor)
            .font(Font.custom("Gill Sans", size: 11))
            .fixedSize(horizontal: true, vertical: false)
            .padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 10))
            
          Capsule()
            .foregroundColor(FeatureView.bubbleColor)
            .frame(width: 1, height: 38)
          
          ScrollView(.horizontal, showsIndicators: false) {
            HStack(spacing: 0) {
              Spacer()
                .frame(width: 10)
              ForEach(self.arguments, id: \.id) { argument in
                FeatureBubble(argument: argument,
                              showingQueryOptionsForArgument: self.$showingQueryOptionsForArgument)
 Joel  Oksanen's avatar
Joel Oksanen committed
41
42
43
44
45
                  .onTapGesture {
                    withAnimation(.easeInOut(duration: 0.3)) {
                      self.showingQueryOptionsForArgument = argument
                    }
                  }
46
47
48
49
              }
              Spacer()
                .frame(width: 10)
            }
 Joel  Oksanen's avatar
Joel Oksanen committed
50
          }
51
52
          .frame(maxWidth: 280)
          .fixedSize(horizontal: true, vertical: false)
 Joel  Oksanen's avatar
Joel Oksanen committed
53
        }
54
55
56
57
58
        .padding(EdgeInsets(top: 0, leading: 0, bottom: 15, trailing: 0))
      }
      
      if showingQueryOptionsForArgument != nil {
        QueryOptionView(chatManager: chatManager, queries: showingQueryOptionsForArgument!.queries)
 Joel  Oksanen's avatar
Joel Oksanen committed
59
60
      }
    }
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
    .frame(width: UIScreen.main.bounds.width)
  }
}

struct FeatureBubble: View {
  let argument: Argument
  @Binding var showingQueryOptionsForArgument: Argument?
  
  var body: some View {
    Text(argument.name)
      .foregroundColor(self.showingQueryOptionsForArgument == argument ? Color.white : FeatureView.bubbleColor)
      .font(Font.custom("Helvetica Neue", size: 12))
      .fixedSize(horizontal: true, vertical: true)
      .padding(EdgeInsets(top: 10, leading: 20, bottom: 10, trailing: 20))
      .background(self.showingQueryOptionsForArgument == argument ?
        AnyView(Capsule().foregroundColor(FeatureView.bubbleColor)) :
        AnyView(Capsule().strokeBorder(FeatureView.bubbleColor))
      )
      .padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 10))
 Joel  Oksanen's avatar
Joel Oksanen committed
80
81
  }
}