Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 36 | Rev 61 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 36 Rev 37
Línea 9... Línea 9...
9
 
9
 
Línea 10... Línea 10...
10
import SwiftUI
10
import SwiftUI
-
 
11
 
11
 
12
 
-
 
13
struct GridGalleryView: View {
-
 
14
    let minDragTranslationForSwipe: CGFloat = 50
-
 
15
    
12
 
16
    @State var selectTab : Int = 0
13
struct GridGalleryView: View {
17
    @State private var positionVisible: Int = 0
14
 
18
    
15
    @EnvironmentObject private var networkMonitor : NetworkMonitor
-
 
-
 
19
    @EnvironmentObject private var networkMonitor : NetworkMonitor
Línea 16... Línea 20...
16
    @EnvironmentObject private var appNavigation : AppNavigation
20
    @EnvironmentObject private var appNavigation : AppNavigation
17
    @ObservedObject private var viewModel : GalleryGridViewModel = GalleryGridViewModel()
21
    @ObservedObject private var viewModel : GalleryGridViewModel = GalleryGridViewModel()
18
    @State private var positionVisible: Int = 0
-
 
19
 
-
 
20
 
-
 
21
    private var appData = AppData.sharedInstance
22
    
Línea 22... Línea 23...
22
    private var capsuleTitle : String = ""
23
 
23
    private let rows = [
24
 
Línea 47... Línea 48...
47
        GeometryReader { geometry in
48
        GeometryReader { geometry in
48
            ZStack {
49
            ZStack {
Línea 49... Línea 50...
49
                
50
                
50
                if self.viewModel.hasPrevious()  {
51
                if self.viewModel.hasPrevious()  {
51
                    Button(action: {
-
 
52
                        print("Button previouse")
52
                    Button(action: {
53
                        self.viewModel.previous()
-
 
54
                        print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")
53
                        self.viewModel.previous()
Línea 55... Línea 54...
55
                        self.completeSlide(position: self.viewModel.slideActiveIndex)
54
                        self.completeSlide(position: self.viewModel.slideActiveIndex)
56
                        
55
                        
Línea 57... Línea 56...
57
                        appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
56
                        appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
58
                        appData.save()
57
                        appData.save()
59
                        
58
                        
60
                        self.positionVisible = self.viewModel.slideActiveIndex
59
                        self.positionVisible = self.viewModel.slideActiveIndex
61
                    }, label: {
60
                    }, label: {
62
                        Image(systemName: "arrow.left")
-
 
63
                            .frame(width: 40.0, height: 40.0, alignment: .center)
-
 
64
                    })
61
                        Image(systemName: "arrow.left")
65
                    
62
                            .frame(width: 40.0, height: 40.0, alignment: .center)
66
 
63
                    })
67
                         .cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/)
64
                    .cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/)
68
                    .background(Color("color_button_gallery_background"))
65
                    .background(Color("color_button_gallery_background"))
Línea 69... Línea 66...
69
                    .foregroundColor(Color("color_button_gallery_foreground"))
66
                    .foregroundColor(Color("color_button_gallery_foreground"))
70
                        .offset(x: -1 * ((geometry.size.width / 2) - 30), y :  25).zIndex(10000)
67
                        .offset(x: -1 * ((geometry.size.width / 2) - 30), y :  25).zIndex(10000)
71
                }
-
 
72
                
68
                }
73
                if self.viewModel.hasNext() {
-
 
74
                    Button(action: {
69
                
Línea 75... Línea 70...
75
                        print("Button next")
70
                if self.viewModel.hasNext() {
76
                        self.viewModel.next()
71
                    Button(action: {
Línea 94... Línea 89...
94
                }
89
                }
Línea 95... Línea 90...
95
                
90
                
96
                VStack(spacing: 0) {
91
                VStack(spacing: 0) {
97
                    HStack {
92
                    HStack {
98
                        Button(action: {
-
 
99
                            
-
 
100
                           
93
                        Button(action: {
101
                            appNavigation.subpageActive = .slides
-
 
102
                            
-
 
103
                            
94
                            appNavigation.subpageActive = .slides
104
                        }, label: {
-
 
105
 
-
 
106
                            
95
                        }, label: {
107
                            Image(systemName: "chevron.backward")
96
                            Image(systemName: "chevron.backward")
108
                            .frame(width: 32, height: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
97
                            .frame(width: 32, height: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
109
                            .aspectRatio(contentMode: .fit)
98
                            .aspectRatio(contentMode: .fit)
110
                                .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
99
                                .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
Línea 123... Línea 112...
123
                    .background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
112
                    .background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
Línea 124... Línea 113...
124
            
113
            
Línea 125... Línea -...
125
            
-
 
-
 
114
            
126
                    Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
115
                    Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
127
                    
-
 
-
 
116
                    
128
                    VStack(spacing: 0)  {
117
                    
129
                        GeometryReader { geometry2 in
-
 
130
                    ScrollViewReader { scrollProxy in
118
                    GeometryReader { geometry2 in
131
                        ScrollView(.horizontal) {
119
                    
132
                            LazyHGrid(rows: rows, alignment: .center) {
120
                        TabView(selection: self.$selectTab ) {
133
                                ForEach(0..<self.viewModel.slides.count) { index in
121
                            ForEach(0..<self.viewModel.slides.count ) { index in
134
                                    CardGalleryView(
122
                                CardGalleryView(
135
                                        slideUuid:  self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
123
                                    slideUuid:  self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
136
                                    )
-
 
137
                                    .environmentObject(appNavigation)
-
 
138
                                    .frame(width: geometry2.size.width, height: geometry2.size.height)
-
 
139
                                    .id(index)
-
 
140
                                    //.border(Color.green, width: 1)
124
                                )
-
 
125
                                .environmentObject(appNavigation)
141
                                    .onAppear {
126
                                .frame(width: geometry2.size.width, height: geometry2.size.height)
142
                                        completeSlide(position: index)
127
                                .highPriorityGesture(DragGesture().onEnded({ self.handleSwipe(translation: $0.translation.width)}))
143
                                        self.viewModel.slideActiveIndex = index
-
 
144
                                    }
-
 
145
                                }
-
 
146
                            }//.border(Color.black, width: 1)
128
                                                            
147
                        }//.border(Color.red, width: 1)
-
 
148
                            .frame(width: geometry2.size.width, height: geometry2.size.height)
-
 
149
                        .onChange(of: self.positionVisible) { id in
129
                            }
150
                            guard id != nil else { return }
-
 
151
                            
-
 
152
                            print("positionVisible : \(positionVisible)")
130
                        }
-
 
131
                        .onChange(of: self.positionVisible) { id in
-
 
132
                            self.selectTab = positionVisible
-
 
133
                        }
-
 
134
                        .tabViewStyle(PageTabViewStyle())
153
                            scrollProxy.scrollTo(id)
135
                    }
154
 
136
 
155
                        }
137
                    
156
                        .onAppear {
138
                   .onAppear {
157
                            var position : Int = 0
139
                            var position : Int = 0
158
                            var i : Int = 0
140
                            var i : Int = 0
Línea 163... Línea 145...
163
                                i += 1
145
                                i += 1
164
                            }
146
                            }
Línea 165... Línea 147...
165
                            
147
                            
166
                            self.viewModel.slideActiveIndex = position
148
                            self.viewModel.slideActiveIndex = position
167
                            completeSlide(position: position)
-
 
168
                            scrollProxy.scrollTo(position)
-
 
169
                        }
-
 
170
                    }
-
 
-
 
149
                            completeSlide(position: position)
171
                        }
150
                            
172
                    }
151
                    }
173
                }
152
                }
174
            }
153
            }
175
        }
154
        }
Línea -... Línea 155...
-
 
155
    }
-
 
156
    
-
 
157
    
-
 
158
    func handleSwipe(translation: CGFloat) {
-
 
159
        if translation > minDragTranslationForSwipe  {
-
 
160
            if self.viewModel.hasPrevious() {
-
 
161
                self.viewModel.previous()
-
 
162
                self.completeSlide(position: self.viewModel.slideActiveIndex)
-
 
163
                
-
 
164
                appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
-
 
165
                appData.save()
-
 
166
                
-
 
167
                self.positionVisible = self.viewModel.slideActiveIndex
-
 
168
            }
-
 
169
        } else  if translation < -minDragTranslationForSwipe {
-
 
170
            if self.viewModel.hasNext() {
-
 
171
                self.viewModel.next()
-
 
172
                self.completeSlide(position: self.viewModel.slideActiveIndex)
-
 
173
                
-
 
174
                appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
-
 
175
                appData.save()
-
 
176
                
-
 
177
                self.positionVisible  = self.viewModel.slideActiveIndex
-
 
178
            }
-
 
179
        }
176
    }
180
    }
177
    
181
    
Línea 178... Línea 182...
178
    private func completeSlide(position: Int)
182
    private func completeSlide(position: Int)