Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 11 | Rev 22 | Ir a la última revisión | | Comparar con el anterior | 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
 
8 efrain 11
 
1 efrain 12
struct CommentAndRatingPostCommentView: View {
13
 
8 efrain 14
    var capsuleModel : CapsuleModel
15
    @Binding var comment : String
16
    @Binding var rating : Double
17 efrain 17
 
18
    let onSend: () -> Void
8 efrain 19
 
17 efrain 20
 
1 efrain 21
    var body: some View {
8 efrain 22
        VStack(spacing: 0) {
1 efrain 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(minWidth: 0, maxWidth: UIScreen.main.bounds.width, minHeight: 0, maxHeight: 100)        .overlay(RoundedRectangle(cornerRadius: 5).stroke(
33
                            Color ("color_textfield_border" )
34
                        ))
35
 
36
                } .padding(.leading, 16)
37
                .padding(.trailing, 16)
38
                .padding(.top, comment.isEmpty ? 10 : 2)
39
 
8 efrain 40
            if   !capsuleModel.linkComments.trimingLeadingSpaces().isEmpty && comment.trimingLeadingSpaces().isEmpty {
1 efrain 41
                    HStack {
42
                        Spacer()
43
 
44
                        Text(Config.LANG_POST_COMMENT_ERROR_COMMENT_FIELD)
45
                        .foregroundColor(.red)
46
                            .font(Font.custom(Config.FONT_NAME_REGULAR, size: 11))
47
 
48
                    }
49
                    .padding(.top, 5)
50
                    .padding(.trailing, 16)
51
                }
52
 
53
                HStack {
54
                    Text(Config.LANG_POST_COMMENT_RATING_LABEL)
55
                        .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_SIGNIN_TEXTFIELD_LABEL))
56
                        Spacer()
57
                }.padding(.leading, 16)
58
                .padding(.top, 10)
59
 
60
                HStack {
11 efrain 61
                    Slider(value: self.$rating, in: 1...5, step: 1)
1 efrain 62
 
63
 
64
                    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@*/)
65
                        .padding(.leading, 8)
66
 
67
                    Spacer()
68
 
69
 
70
                } .padding(.leading, 16)
71
                .padding(.trailing, 16)
72
                .padding(.top, 10)
73
 
74
                HStack {
75
                    Spacer()
17 efrain 76
                    Button(action: onSend, label: {
1 efrain 77
                        Text(Config.LANG_COMMON_SEND)
78
                         .font(Font.custom(Config.FONT_NAME_REGULAR, size: 16))
79
                         .frame(width: UIScreen.main.bounds.width - 32, height: 35)
80
 
81
                            .foregroundColor(Color("color_button_dark_foreground"))
82
                            .background(Color("color_button_dark_background"))
83
                            .border(Color( "color_button_dark_border"), width: Config.BUTTON_BORDER_SIZE)
84
                            .cornerRadius(Config.BUTTON_BORDER_RADIUS)
85
 
86
                    })
87
 
88
                }                  .padding(.top, 16)
89
                .padding(.leading, 16)
90
                .padding(.trailing, 16)
91
 
92
                Spacer()
8 efrain 93
        }.background(Color("color_picker_background"))
94
 
95
    }
96
 
1 efrain 97
 
8 efrain 98
 
99
 
100
 
101
 
1 efrain 102
}
103
 
104
struct CommentAndRatingPostCommentView_Previews: PreviewProvider {
105
 
8 efrain 106
    @State static var comment : String = ""
107
    @State static var rating : Double = 3.6
108
    static let capsuleModel = CapsuleModel()
109
 
1 efrain 110
 
111
    static var previews: some View {
17 efrain 112
        CommentAndRatingPostCommentView(capsuleModel: capsuleModel, comment: self.$comment, rating: self.$rating) {
113
 
114
        }
1 efrain 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
}