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)
|
|
|
25 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_SIGNIN_TEXTFIELD_LABEL))
|
|
|
26 |
Spacer()
|
|
|
27 |
}.padding(.leading, 16)
|
|
|
28 |
|
|
|
29 |
HStack {
|
|
|
30 |
|
|
|
31 |
MultilineTextView(text: $comment)
|
|
|
32 |
.frame(
|
|
|
33 |
minWidth: UIScreen.main.bounds.width,
|
|
|
34 |
maxWidth: UIScreen.main.bounds.width,
|
|
|
35 |
minHeight: 100,
|
|
|
36 |
maxHeight: 100) .overlay(RoundedRectangle(cornerRadius: 5).stroke(
|
|
|
37 |
Color ("color_textfield_border" )
|
|
|
38 |
))
|
|
|
39 |
|
|
|
40 |
} .padding(.leading, 16)
|
|
|
41 |
.padding(.trailing, 16)
|
|
|
42 |
.padding(.top, comment.isEmpty ? 10 : 2)
|
|
|
43 |
|
|
|
44 |
if !capsuleModel.linkComments.trimingLeadingSpaces().isEmpty && comment.trimingLeadingSpaces().isEmpty {
|
|
|
45 |
HStack {
|
|
|
46 |
Spacer()
|
|
|
47 |
|
|
|
48 |
Text(Config.LANG_POST_COMMENT_ERROR_COMMENT_FIELD)
|
|
|
49 |
.foregroundColor(.red)
|
|
|
50 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: 11))
|
|
|
51 |
|
|
|
52 |
}
|
|
|
53 |
.padding(.top, 5)
|
|
|
54 |
.padding(.trailing, 16)
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
HStack {
|
|
|
58 |
Text(Config.LANG_POST_COMMENT_RATING_LABEL)
|
|
|
59 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_SIGNIN_TEXTFIELD_LABEL))
|
|
|
60 |
Spacer()
|
|
|
61 |
}.padding(.leading, 16)
|
|
|
62 |
.padding(.top, 10)
|
|
|
63 |
|
|
|
64 |
HStack {
|
|
|
65 |
Slider(value: self.$rating, in: 1...5, step: 1)
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
FiveStarView(rating: Decimal(rating), color: Color("color_capsule_list_item_star_foreground"), backgroundColor: Color("color_capsule_list_item_star_background")) .frame(width: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/, height: 16, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
|
|
|
69 |
.padding(.leading, 8)
|
|
|
70 |
|
|
|
71 |
Spacer()
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
} .padding(.leading, 16)
|
|
|
75 |
.padding(.trailing, 16)
|
|
|
76 |
.padding(.top, 10)
|
|
|
77 |
|
|
|
78 |
HStack {
|
|
|
79 |
Spacer()
|
|
|
80 |
Button(action: onSend, label: {
|
|
|
81 |
Text(Config.LANG_COMMON_SEND)
|
|
|
82 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: 16))
|
|
|
83 |
.frame(width: UIScreen.main.bounds.width - 32, height: 35)
|
|
|
84 |
|
|
|
85 |
.foregroundColor(Color("color_button_dark_foreground"))
|
|
|
86 |
.background(Color("color_button_dark_background"))
|
|
|
87 |
.border(Color( "color_button_dark_border"), width: Config.BUTTON_BORDER_SIZE)
|
|
|
88 |
.cornerRadius(Config.BUTTON_BORDER_RADIUS)
|
|
|
89 |
|
|
|
90 |
})
|
|
|
91 |
|
|
|
92 |
} .padding(.top, 16)
|
|
|
93 |
.padding(.leading, 16)
|
|
|
94 |
.padding(.trailing, 16)
|
|
|
95 |
|
|
|
96 |
Spacer()
|
|
|
97 |
}.background(Color("color_picker_background"))
|
|
|
98 |
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
struct CommentAndRatingPostCommentView_Previews: PreviewProvider {
|
|
|
109 |
|
|
|
110 |
@State static var comment : String = ""
|
|
|
111 |
@State static var rating : Double = 3.6
|
|
|
112 |
static let capsuleModel = CapsuleModel()
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
static var previews: some View {
|
|
|
116 |
CommentAndRatingPostCommentView(capsuleModel: capsuleModel, comment: self.$comment, rating: self.$rating) {
|
|
|
117 |
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
struct MultilineTextView: UIViewRepresentable {
|
|
|
126 |
@Binding var text: String
|
|
|
127 |
|
|
|
128 |
func makeUIView(context: Context) -> UITextView {
|
|
|
129 |
let view = UITextView()
|
|
|
130 |
view.delegate = context.coordinator
|
|
|
131 |
view.backgroundColor =
|
|
|
132 |
UIColor(Color("color_textfield_background"))
|
|
|
133 |
|
|
|
134 |
view.textColor = UIColor(Color("color_textfield_foreground"))
|
|
|
135 |
view.autocapitalizationType = .none
|
|
|
136 |
view.autocorrectionType = .no
|
|
|
137 |
view.font = UIFont(name: Config.FONT_NAME_REGULAR, size: 12)
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
view.isScrollEnabled = true
|
|
|
141 |
view.isEditable = true
|
|
|
142 |
view.isUserInteractionEnabled = true
|
|
|
143 |
|
|
|
144 |
return view
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
func updateUIView(_ uiView: UITextView, context: Context) {
|
|
|
148 |
uiView.text = text
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
func makeCoordinator() -> MultilineTextView.Coordinator {
|
|
|
152 |
Coordinator(self)
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
class Coordinator : NSObject, UITextViewDelegate {
|
|
|
156 |
var parent: MultilineTextView
|
|
|
157 |
|
|
|
158 |
init(_ uiTextView: MultilineTextView) {
|
|
|
159 |
self.parent = uiTextView
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
|
|
|
163 |
return true
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
func textViewDidChange(_ textView: UITextView) {
|
|
|
167 |
self.parent.text = textView.text
|
|
|
168 |
}
|
|
|
169 |
}
|
|
|
170 |
}
|