Rev 11 | 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 SwiftUIstruct CommentAndRatingPostCommentView: View {@Binding var comment: String@State var rating : Double = 3var 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: 0, maxWidth: UIScreen.main.bounds.width, minHeight: 0, maxHeight: 100) .overlay(RoundedRectangle(cornerRadius: 5).stroke(Color ("color_textfield_border" )))} .padding(.leading, 16).padding(.trailing, 16).padding(.top, comment.isEmpty ? 10 : 2)if comment.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: 0...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: {DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {withAnimation {}}}, 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 = "Welcome to SwiftlyRush's bank, you will be able to access your accounts in this application"@State static var isValidComment : Bool = falsestatic var previews: some View {CommentAndRatingPostCommentView(comment: self.$comment)}}struct MultilineTextView: UIViewRepresentable {@Binding var text: Stringfunc makeUIView(context: Context) -> UITextView {let view = UITextView()view.delegate = context.coordinatorview.backgroundColor =UIColor(Color("color_textfield_background"))view.textColor = UIColor(Color("color_textfield_foreground"))view.autocapitalizationType = .noneview.autocorrectionType = .noview.font = UIFont(name: Config.FONT_NAME_REGULAR, size: 12)view.isScrollEnabled = trueview.isEditable = trueview.isUserInteractionEnabled = truereturn view}func updateUIView(_ uiView: UITextView, context: Context) {uiView.text = text}func makeCoordinator() -> MultilineTextView.Coordinator {Coordinator(self)}class Coordinator : NSObject, UITextViewDelegate {var parent: MultilineTextViewinit(_ 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}}}