Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
//
// CommentAndRatingPostCommentView.swift
// twogetskills
//
// Created by Efrain Yanez Recanatini on 7/28/22.
//
import SwiftUI
struct CommentAndRatingPostCommentView: View {
var capsuleModel : CapsuleModel
@Binding var comment : String
@Binding var rating : Double
let onSend: () -> Void
var body: some View {
VStack(spacing: 0) {
HStack {
Text(Config.LANG_POST_COMMENT_COMMENT_LABEL)
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_SIGNIN_TEXTFIELD_LABEL))
Spacer()
}.padding(.leading, 16)
HStack {
MultilineTextView(text: $comment)
.frame(
minWidth: UIScreen.main.bounds.width,
maxWidth: UIScreen.main.bounds.width,
minHeight: 100,
maxHeight: 100) .overlay(RoundedRectangle(cornerRadius: 5).stroke(
Color ("color_textfield_border" )
))
} .padding(.leading, 16)
.padding(.trailing, 16)
.padding(.top, comment.isEmpty ? 10 : 2)
if !capsuleModel.linkComments.trimingLeadingSpaces().isEmpty && comment.trimingLeadingSpaces().isEmpty {
HStack {
Spacer()
Text(Config.LANG_POST_COMMENT_ERROR_COMMENT_FIELD)
.foregroundColor(.red)
.font(Font.custom(Config.FONT_NAME_REGULAR, size: 11))
}
.padding(.top, 5)
.padding(.trailing, 16)
}
HStack {
Text(Config.LANG_POST_COMMENT_RATING_LABEL)
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_SIGNIN_TEXTFIELD_LABEL))
Spacer()
}.padding(.leading, 16)
.padding(.top, 10)
HStack {
Slider(value: self.$rating, in: 1...5, step: 1)
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@*/)
.padding(.leading, 8)
Spacer()
} .padding(.leading, 16)
.padding(.trailing, 16)
.padding(.top, 10)
HStack {
Spacer()
Button(action: onSend, label: {
Text(Config.LANG_COMMON_SEND)
.font(Font.custom(Config.FONT_NAME_REGULAR, size: 16))
.frame(width: UIScreen.main.bounds.width - 32, height: 35)
.foregroundColor(Color("color_button_dark_foreground"))
.background(Color("color_button_dark_background"))
.border(Color( "color_button_dark_border"), width: Config.BUTTON_BORDER_SIZE)
.cornerRadius(Config.BUTTON_BORDER_RADIUS)
})
} .padding(.top, 16)
.padding(.leading, 16)
.padding(.trailing, 16)
Spacer()
}.background(Color("color_picker_background"))
}
}
struct CommentAndRatingPostCommentView_Previews: PreviewProvider {
@State static var comment : String = ""
@State static var rating : Double = 3.6
static let capsuleModel = CapsuleModel()
static var previews: some View {
CommentAndRatingPostCommentView(capsuleModel: capsuleModel, comment: self.$comment, rating: self.$rating) {
}
}
}
struct MultilineTextView: UIViewRepresentable {
@Binding var text: String
func makeUIView(context: Context) -> UITextView {
let view = UITextView()
view.delegate = context.coordinator
view.backgroundColor =
UIColor(Color("color_textfield_background"))
view.textColor = UIColor(Color("color_textfield_foreground"))
view.autocapitalizationType = .none
view.autocorrectionType = .no
view.font = UIFont(name: Config.FONT_NAME_REGULAR, size: 12)
view.isScrollEnabled = true
view.isEditable = true
view.isUserInteractionEnabled = true
return view
}
func updateUIView(_ uiView: UITextView, context: Context) {
uiView.text = text
}
func makeCoordinator() -> MultilineTextView.Coordinator {
Coordinator(self)
}
class Coordinator : NSObject, UITextViewDelegate {
var parent: MultilineTextView
init(_ uiTextView: MultilineTextView) {
self.parent = uiTextView
}
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
return true
}
func textViewDidChange(_ textView: UITextView) {
self.parent.text = textView.text
}
}
}