Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 8 | Ir a la última revisión | | Ultima modificación | Ver Log |

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