Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

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