Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

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