Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 1 | Rev 9 | 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
//  GridSlideView.swift
3
//  twogetskills
4
//
5
//  Created by Efrain Yanez Recanatini on 2/17/22.
6
//
7
 
8
import SwiftUI
9
 
10
 
11
struct GridSlideView: View {
12
 
8 efrain 13
    @EnvironmentObject private var networkMonitor : NetworkMonitor
1 efrain 14
    @EnvironmentObject private var appNavigation : AppNavigation
15
    @State private var scrollToIndex : Int = 0
16
 
17
    private let appData = AppData.sharedInstance
18
    private let capsuleDao : CapsuleDao = CapsuleDao.sharedInstance
19
 
20
    private var capsuleModel : CapsuleModel = CapsuleModel()
21
    private var viewModel : SlideGridViewModel = SlideGridViewModel()
22
    private var capsuleTitle : String = ""
23
 
24
    private let config = [
25
        GridItem(.fixed(Constants.CARD_WIDTH)),
26
        GridItem(.fixed(Constants.CARD_WIDTH))
27
    ]
28
 
29
 
30
 
31
    //init(capsuleUuid : String)
32
    init()
33
    {
34
 
35
        self.capsuleModel = capsuleDao.selectByUuid(uuid: appData.capsuleUuidActive)
36
        viewModel.fetch(capsuleUuid: self.capsuleModel.uuid, userUuid: appData.userUuid)
37
 
38
        if self.capsuleModel.name.count > Constants.APP_BAR_TITLE_MAX_LENGTH {
39
            capsuleTitle = String(Array(self.capsuleModel.name)[0...Constants.APP_BAR_TITLE_MAX_LENGTH]) + "..."
40
        } else {
41
            capsuleTitle = self.capsuleModel.name
42
        }
43
    }
44
 
45
    var body: some View {
46
 
47
            VStack(spacing: 0) {
48
                HStack {
49
                    Button(action: {
8 efrain 50
 
1 efrain 51
 
52
                        appNavigation.subpageActive = .capsules
53
 
8 efrain 54
                        if appData.subPageSource == AppData.SUB_PAGE_SOURCE_MY_CAPSULES {
55
                            appData.topicUuidActive = ""
56
                            appData.capsuleUuidActive = ""
57
                            appData.subPageSource = 0
58
                            appData.save()
59
 
60
                            withAnimation {
61
                                appNavigation.subpageActive = .mycapsules
62
                            }
63
                        } else {
64
                            appData.slideUuidActive = ""
65
                            appData.save()
66
 
67
                            withAnimation {
68
                                appNavigation.subpageActive = .capsules
69
                            }
70
                        }
1 efrain 71
 
8 efrain 72
 
1 efrain 73
                    }, label: {
74
 
75
 
76
                        Image(systemName: "chevron.backward")
77
                        .frame(width: 32, height: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
78
                        .aspectRatio(contentMode: .fit)
8 efrain 79
                            .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
1 efrain 80
                    })
81
                    .padding(.leading, 16)
82
 
8 efrain 83
                    Text(networkMonitor.status == .disconnected ? Config.LANG_ERROR_NETWORK_MESSAGE_SHORT : capsuleTitle)
1 efrain 84
                    .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 ))
8 efrain 85
                     .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
1 efrain 86
                        .padding(.leading, 4)
87
 
88
                    Spacer()
89
                }
90
                .edgesIgnoringSafeArea(.top)
91
                .frame(height: 50)
8 efrain 92
                .background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
93
 
94
 
95
                Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
96
 
1 efrain 97
 
98
                Divider()
99
 
100
                ScrollView() {
101
                    ScrollViewReader { proxy in
102
                        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: {
103
 
104
                            ForEach(0..<self.viewModel.slides.count) { index in
105
                                CardSlideView(
106
                                    slideUuid: self.viewModel.slides[index].uuid,
107
                                    position: index
108
                                )
109
                                .environmentObject(appNavigation)
110
                                .frame(
111
                                    width: Constants.CARD_WIDTH,
112
                                    height: Constants.CARD_HEIGHT,
113
                                    alignment: .center
114
                                )
115
                                .id(index)
116
 
117
                            }
118
                            /*}.onChange(of:  scrollToIndex, perform: { value in
119
                                print("onChange")
120
                                proxy.scrollTo(value, anchor: nil)
121
                            })*/
122
                        })
123
                    }
124
 
125
                }
126
                /*.onAppear {
127
                    var i : Int = 0
128
                    while i < self.viewModel.slides.count {
129
                        if appData.slideUuidActive == self.viewModel.slides[i].uuid {
130
                            self.scrollToIndex = i
131
                        }
132
                        i += 1
133
                    }
134
 
135
                }*/
136
                .padding(.top, 5)
137
 
138
 
139
 
140
 
141
        }
142
    }
143
}
144
 
145
struct GridSlideView_Previews: PreviewProvider {
146
    static var previews: some View {
147
        //GridSlideView(capsuleUuid: "C123")
148
        GridSlideView()
149
    }
150
}
151
 
152