| 1 |
efrain |
1 |
//
|
|
|
2 |
// CommentAndRatingPostCommentView.swift
|
|
|
3 |
// twogetskills
|
|
|
4 |
//
|
|
|
5 |
// Created by Efrain Yanez Recanatini on 7/28/22.
|
|
|
6 |
//
|
|
|
7 |
|
|
|
8 |
import SwiftUI
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
struct CommentAndRatingPostCommentView: View {
|
|
|
13 |
|
|
|
14 |
var capsuleModel : CapsuleModel
|
|
|
15 |
@Binding var comment : String
|
|
|
16 |
@Binding var rating : Double
|
|
|
17 |
|
|
|
18 |
let onSend: () -> Void
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
var body: some View {
|
|
|
22 |
VStack(spacing: 0) {
|
|
|
23 |
HStack {
|
|
|
24 |
Text(Config.LANG_POST_COMMENT_COMMENT_LABEL)
|
| 17 |
efrain |
25 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_TEXTFIELD_LABEL))
|
| 1 |
efrain |
26 |
Spacer()
|
| 17 |
efrain |
27 |
}
|
|
|
28 |
.padding(.leading, 16)
|
|
|
29 |
|
|
|
30 |
HStack {
|
| 1 |
efrain |
31 |
|
|
|
32 |
MultilineTextView(text: $comment)
|
|
|
33 |
.frame(
|
| 17 |
efrain |
34 |
minWidth: UIScreen.main.bounds.width - 32,
|
|
|
35 |
maxWidth: UIScreen.main.bounds.width - 32,
|
| 1 |
efrain |
36 |
minHeight: 100,
|
| 17 |
efrain |
37 |
maxHeight: 100)
|
|
|
38 |
.overlay(RoundedRectangle(cornerRadius: 5).stroke(
|
| 1 |
efrain |
39 |
Color ("color_textfield_border" )
|
|
|
40 |
))
|
|
|
41 |
|
| 17 |
efrain |
42 |
}
|
|
|
43 |
.padding(.leading, 16)
|
| 1 |
efrain |
44 |
.padding(.trailing, 16)
|
|
|
45 |
.padding(.top, comment.isEmpty ? 10 : 2)
|
| 17 |
efrain |
46 |
|
| 1 |
efrain |
47 |
|
| 17 |
efrain |
48 |
|
| 1 |
efrain |
49 |
if !capsuleModel.linkComments.trimingLeadingSpaces().isEmpty && comment.trimingLeadingSpaces().isEmpty {
|
|
|
50 |
HStack {
|
|
|
51 |
Spacer()
|
|
|
52 |
|
|
|
53 |
Text(Config.LANG_POST_COMMENT_ERROR_COMMENT_FIELD)
|
|
|
54 |
.foregroundColor(.red)
|
| 17 |
efrain |
55 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_TEXTFIELD_ERROR))
|
| 1 |
efrain |
56 |
|
|
|
57 |
}
|
|
|
58 |
.padding(.top, 5)
|
|
|
59 |
.padding(.trailing, 16)
|
|
|
60 |
}
|
| 17 |
efrain |
61 |
|
|
|
62 |
|
| 1 |
efrain |
63 |
|
|
|
64 |
HStack {
|
|
|
65 |
Text(Config.LANG_POST_COMMENT_RATING_LABEL)
|
| 17 |
efrain |
66 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_TEXTFIELD_LABEL))
|
| 1 |
efrain |
67 |
Spacer()
|
| 17 |
efrain |
68 |
}
|
|
|
69 |
.padding(.leading, 16)
|
| 1 |
efrain |
70 |
.padding(.top, 10)
|
| 17 |
efrain |
71 |
|
| 1 |
efrain |
72 |
|
| 17 |
efrain |
73 |
|
| 1 |
efrain |
74 |
HStack {
|
|
|
75 |
Slider(value: self.$rating, in: 1...5, step: 1)
|
|
|
76 |
|
|
|
77 |
|
| 17 |
efrain |
78 |
FiveStarView(rating: Decimal(rating), color: Color("color_capsule_list_item_star_foreground"), backgroundColor: Color("color_capsule_list_item_star_background"))
|
|
|
79 |
.frame(width: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/, height: 16, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
|
| 1 |
efrain |
80 |
.padding(.leading, 8)
|
| 17 |
efrain |
81 |
.padding(.trailing, 8)
|
| 1 |
efrain |
82 |
|
| 17 |
efrain |
83 |
|
| 1 |
efrain |
84 |
|
|
|
85 |
|
| 17 |
efrain |
86 |
}
|
|
|
87 |
.padding(.leading, 16)
|
| 1 |
efrain |
88 |
.padding(.trailing, 16)
|
|
|
89 |
.padding(.top, 10)
|
| 17 |
efrain |
90 |
|
| 1 |
efrain |
91 |
|
|
|
92 |
HStack {
|
| 17 |
efrain |
93 |
|
| 1 |
efrain |
94 |
Button(action: onSend, label: {
|
|
|
95 |
Text(Config.LANG_COMMON_SEND)
|
|
|
96 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: 16))
|
|
|
97 |
.frame(width: UIScreen.main.bounds.width - 32, height: 35)
|
|
|
98 |
|
|
|
99 |
.foregroundColor(Color("color_button_dark_foreground"))
|
|
|
100 |
.background(Color("color_button_dark_background"))
|
|
|
101 |
.border(Color( "color_button_dark_border"), width: Config.BUTTON_BORDER_SIZE)
|
|
|
102 |
.cornerRadius(Config.BUTTON_BORDER_RADIUS)
|
|
|
103 |
|
|
|
104 |
})
|
|
|
105 |
|
| 17 |
efrain |
106 |
}
|
|
|
107 |
.padding(.top, 16)
|
|
|
108 |
/*.padding(.leading, 16)
|
|
|
109 |
.padding(.trailing, 16)*/
|
|
|
110 |
|
| 1 |
efrain |
111 |
|
|
|
112 |
Spacer()
|
|
|
113 |
}.background(Color("color_picker_background"))
|
|
|
114 |
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
struct CommentAndRatingPostCommentView_Previews: PreviewProvider {
|
|
|
125 |
|
|
|
126 |
@State static var comment : String = ""
|
|
|
127 |
@State static var rating : Double = 3.6
|
|
|
128 |
static let capsuleModel = CapsuleModel()
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
static var previews: some View {
|
|
|
132 |
CommentAndRatingPostCommentView(capsuleModel: capsuleModel, comment: self.$comment, rating: self.$rating) {
|
|
|
133 |
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
struct MultilineTextView: UIViewRepresentable {
|
|
|
141 |
@Binding var text: String
|
|
|
142 |
|
|
|
143 |
func makeUIView(context: Context) -> UITextView {
|
|
|
144 |
let view = UITextView()
|
|
|
145 |
view.delegate = context.coordinator
|
|
|
146 |
view.backgroundColor =
|
|
|
147 |
UIColor(Color("color_textfield_background"))
|
|
|
148 |
|
|
|
149 |
view.textColor = UIColor(Color("color_textfield_foreground"))
|
|
|
150 |
view.autocapitalizationType = .none
|
|
|
151 |
view.autocorrectionType = .no
|
| 17 |
efrain |
152 |
view.keyboardType = .alphabet
|
|
|
153 |
view.keyboardAppearance = .default
|
|
|
154 |
view.returnKeyType = .done
|
|
|
155 |
view.font = UIFont(name: Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_TEXTFIELD)
|
| 1 |
efrain |
156 |
|
|
|
157 |
|
|
|
158 |
view.isScrollEnabled = true
|
|
|
159 |
view.isEditable = true
|
|
|
160 |
view.isUserInteractionEnabled = true
|
| 17 |
efrain |
161 |
view
|
| 1 |
efrain |
162 |
|
|
|
163 |
return view
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
func updateUIView(_ uiView: UITextView, context: Context) {
|
|
|
167 |
uiView.text = text
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
func makeCoordinator() -> MultilineTextView.Coordinator {
|
|
|
171 |
Coordinator(self)
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
class Coordinator : NSObject, UITextViewDelegate {
|
|
|
175 |
var parent: MultilineTextView
|
|
|
176 |
|
|
|
177 |
init(_ uiTextView: MultilineTextView) {
|
|
|
178 |
self.parent = uiTextView
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
|
| 17 |
efrain |
182 |
|
|
|
183 |
if("\n" == text) {
|
|
|
184 |
textView.resignFirstResponder()
|
|
|
185 |
return false
|
|
|
186 |
}
|
|
|
187 |
|
| 1 |
efrain |
188 |
return true
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
func textViewDidChange(_ textView: UITextView) {
|
|
|
192 |
self.parent.text = textView.text
|
|
|
193 |
}
|
| 17 |
efrain |
194 |
|
| 1 |
efrain |
195 |
}
|
|
|
196 |
}
|