Rev 32 | Rev 34 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
//// GridGalleryView.swift// twogetskills//// Created by Efrain Yanez Recanatini on 3/7/22.//import Foundationimport SwiftUIstruct GridGalleryView: View {@EnvironmentObject private var networkMonitor : NetworkMonitor@EnvironmentObject private var appNavigation : AppNavigation@ObservedObject private var viewModel : GalleryGridViewModel = GalleryGridViewModel()private var appData = AppData.sharedInstanceprivate var capsuleTitle : String = ""init(){self.viewModel.fetch(capsuleUuid: appData.capsuleUuidActive, userUuid: appData.userUuid)let capsuleDao = CapsuleDao.sharedInstancelet capsule = capsuleDao.selectByUuid(uuid: appData.capsuleUuidActive)if capsule.name.count > Constants.APP_BAR_TITLE_MAX_LENGTH {capsuleTitle = String(Array(capsule.name)[0...Constants.APP_BAR_TITLE_MAX_LENGTH]) + "..."} else {capsuleTitle = capsule.name}}@ViewBuildervar body: some View {GeometryReader { geometry inZStack {if self.viewModel.hasPrevious() {Button(action: {print("Button previouse")self.viewModel.previous()print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")self.completeSlide(position: self.viewModel.slideActiveIndex)appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuidappData.save()}, label: {Image(systemName: "arrow.left")}).frame(width: 40.0, height: 40.0, alignment: .center).cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/).background(Color("color_button_gallery_background")).foregroundColor(Color("color_button_gallery_foreground")).offset(x: -1 * ((geometry.size.width / 2) - 30), y : 25).zIndex(10000)}if self.viewModel.hasNext() {Button(action: {print("Button next")self.viewModel.next()print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")self.completeSlide(position: self.viewModel.slideActiveIndex)appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuidappData.save()}, label: {Image(systemName: "arrow.right")}).frame(width: 40.0, height: 40.0, alignment: .center).background(Color("color_button_gallery_background")).foregroundColor(Color("color_button_gallery_foreground")).offset(x: ((geometry.size.width / 2) - 30), y : 25).zIndex(10000)}VStack(spacing: 0) {HStack {Button(action: {appNavigation.subpageActive = .slides}, label: {Image(systemName: "chevron.backward").frame(width: 32, height: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/).aspectRatio(contentMode: .fit).foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))}).padding(.leading, 16)Text(networkMonitor.status == .disconnected ? Config.LANG_ERROR_NETWORK_MESSAGE_SHORT : capsuleTitle).font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 )).foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground")).padding(.leading, 4)Spacer()}.edgesIgnoringSafeArea(.top).frame(height: 50).background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))CardGalleryView(slideUuid: self.viewModel.slides[self.viewModel.slideActiveIndex].uuid).environmentObject(appNavigation)Text("slideActive : \(viewModel.slideActiveIndex)").transition(.slide).gesture(DragGesture(minimumDistance: 60).onEnded {if $0.startLocation.x > $0.location.x {print("left")if self.viewModel.hasPrevious() {print("hasPrevious")self.viewModel.previous()print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")self.completeSlide(position: self.viewModel.slideActiveIndex)appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuidappData.save()}} else if $0.startLocation.x < $0.location.x {print("right")if self.viewModel.hasNext() {print("hasNext")self.viewModel.next()print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")self.completeSlide(position: self.viewModel.slideActiveIndex)appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuidappData.save()}} else {print("none")}})/*TabView(selection: self.$selectedTab) {ForEach(0..<self.viewModel.slides.count) { index inCardGalleryView(slideUuid: self.viewModel.slides[index].uuid).environmentObject(appNavigation).tag(index).transition(.slide)}}//.tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic)).tabViewStyle(PageTabViewStyle(indexDisplayMode: .never)).onChange(of: self.selectedTab) { selectedTab inappData.slideUuidActive = self.viewModel.slides[selectedTab].uuidappData.save()completeSlide(position: self.selectedTab)}.onAppear {var position : Int = 0var i : Int = 0while i < self.viewModel.slides.count {if appData.slideUuidActive == self.viewModel.slides[i].uuid {position = i}i += 1}self.selectedTab = positioncompleteSlide(position: self.selectedTab)}*/}.onAppear {var position : Int = 0var i : Int = 0while i < self.viewModel.slides.count {if appData.slideUuidActive == self.viewModel.slides[i].uuid {position = i}i += 1}self.viewModel.slideActiveIndex = position}}}}private func completeSlide(position: Int){if self.viewModel.slides[position].type == Constants.SLIDE_TYPE_IMAGE {let dataService = DataService()dataService.completeSlide(slide: self.viewModel.slides[position])}}}struct GridGalleryView_Previews: PreviewProvider {static var previews: some View {//GridGalleryView(capsuleUuid: "C123", position: 2)GridGalleryView()}}