Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
//
2
//  GridCapsuleView.swift
3
//  twogetskills
4
//
5
//  Created by Efrain Yanez Recanatini on 2/17/22.
6
//
7
 
8
import SwiftUI
9
 
10
struct GridCapsuleView: View
11
{
12
    @Environment(\.presentationMode)
13
       var presentationMode: Binding
14
 
15
    private var viewModel : CapsuleGridViewModel = CapsuleGridViewModel()
16
 
17
 
18
    let topicDao : TopicDao = TopicDao()
19
    let topicModel : TopicModel
20
 
21
    var topicTitle : String = ""
22
 
23
 
24
    init(topicUuid : String)
25
    {
26
        let preference = Preference.sharedInstance
27
        self.topicModel = topicDao.selectByUuid(uuid: topicUuid)
28
        viewModel.fetch(topicUuid: self.topicModel.uuid, userUuid: preference.userUuid)
29
 
30
        if self.topicModel.name.count > Constants.APP_BAR_TITLE_MAX_LENGTH {
31
            topicTitle = String(Array(self.topicModel.name)[0...Constants.APP_BAR_TITLE_MAX_LENGTH]) + "..."
32
        } else {
33
            topicTitle = self.topicModel.name
34
        }
35
    }
36
 
37
 
38
    private let colorBackgroundTopic = UIColor(hex: Config.COLOR_BACKGROUND_TOPIC)
39
 
40
    private let colorAppTextView = UIColor(hex: Config.COLOR_APP_TEXT_VIEW_TITLE)
41
 
42
    private let colorAppBackground = UIColor(hex: Config.COLOR_APP_BAR)
43
 
44
 
45
    @State private var backToMain : Bool = false
46
 
47
    let itemPerRow: CGFloat = 2
48
 
49
 
50
    let config = [
51
        GridItem(.flexible()),
52
        GridItem(.flexible())
53
    ]
54
 
55
 
56
 
57
 
58
    var body: some View {
59
        NavigationLink("", destination: MainView(), isActive: self.$backToMain).frame(height: 0)
60
 
61
 
62
        VStack(spacing: 0.0) {
63
 
64
 
65
            ScrollView() {
66
                LazyVGrid(columns: config, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/, spacing: /*@START_MENU_TOKEN@*/nil/*@END_MENU_TOKEN@*/, pinnedViews: /*@START_MENU_TOKEN@*/[]/*@END_MENU_TOKEN@*/, content: {
67
 
68
                    ForEach(0..<self.viewModel.capsules.count) { i in
69
                        CardCapsuleView(capsuleModel: self.viewModel.capsules[i]
70
                        ).frame(
71
                            width: Constants.CARD_WIDTH,
72
                            height: Constants.CARD_HEIGHT,
73
                            alignment: .center
74
                        )
75
                    }
76
                }).padding(.top, 10)
77
            }
78
            Spacer()
79
        }
80
 
81
        .background(Color(colorBackgroundTopic ?? .gray))
82
        .navigationBarBackButtonHidden(true)
83
        .navigationBarTitleDisplayMode(.inline)
84
        .navigationTitle(topicTitle)
85
        .toolbar {
86
            ToolbarItem(placement: .navigationBarLeading) {
87
                Button(action: {
88
                    //self.presentationMode.wrappedValue.dismiss()
89
                    self.backToMain = true
90
                }) {
91
                    HStack {
92
                        Image(systemName: "chevron.backward")
93
                            .aspectRatio(contentMode: .fit)
94
                            .foregroundColor(Color( colorAppTextView ?? .systemBlue))
95
                            .background(Color(colorAppBackground ?? .systemBlue))
96
                    }
97
                }
98
 
99
            }
100
        } .onAppear {
101
            print("GridCapsuleView")
102
        }
103
    }
104
}
105
 
106
 
107
struct GridCapsuleView_Previews: PreviewProvider {
108
    static var previews: some View {
109
       GridCapsuleView(topicUuid: "T123")
110
    }
111
}
112
 
113