Rev 9 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
//// GridCapsuleView.swift// twogetskills//// Created by Efrain Yanez Recanatini on 2/17/22.//import SwiftUIstruct GridCapsuleView: View{@EnvironmentObject private var appNavigation : AppNavigation@State private var scrollToIndex : Int = 0@ObservedObject private var viewModel : CapsuleGridViewModel = CapsuleGridViewModel()private let itemPerRow: CGFloat = 2private let config = [GridItem(.flexible()),GridItem(.flexible())]private let appData = AppData.sharedInstanceprivate var topicTitle : String = ""init(preview : Bool = false){let topicDao = TopicDao.sharedInstancelet topicModel = topicDao.selectByUuid(uuid: appData.topicUuidActive)viewModel.fetch(topicUuid: appData.topicUuidActive, userUuid: appData.userUuid)if topicModel.name.count > Constants.APP_BAR_TITLE_MAX_LENGTH {topicTitle = String(Array(topicModel.name)[0...Constants.APP_BAR_TITLE_MAX_LENGTH]) + "..."} else {topicTitle = topicModel.name}}var body: some View {VStack(spacing: 0) {HStack {Button(action: {appData.capsuleUuidActive = ""appData.slideUuidActive = ""if appData.subPageSource == AppData.SUB_PAGE_SOURCE_MY_CAPSULES {appData.topicUuidActive = ""appData.subPageSource = 0appData.save()withAnimation {appNavigation.subpageActive = .mycapsules}} else {appData.subPageSource = 0appData.save()withAnimation {appNavigation.subpageActive = .topics}}}, label: {Image(systemName: "chevron.backward").frame(width: 32, height: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/).aspectRatio(contentMode: .fit).foregroundColor(Color("color_app_bar_foreground"))}).padding(.leading, 16)Text(topicTitle).font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 )).foregroundColor(Color("color_app_bar_foreground")).padding(.leading, 4)Spacer()}.background(Color("color_app_bar_background")).edgesIgnoringSafeArea(.top).frame(height: 50)Divider()ScrollView() {ScrollViewReader { proxy inLazyVGrid(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:{ForEach(0..<self.viewModel.capsules.count) { index inCardCapsuleView(capsuleUuid: self.viewModel.capsules[index].uuid).environmentObject(appNavigation).frame(width: Constants.CARD_WIDTH,height: Constants.CARD_HEIGHT,alignment: .center).id(index)}.onChange(of: scrollToIndex, perform: { value inproxy.scrollTo(value, anchor: nil)})})}}.padding(.top, 5)}.onAppear {var i : Int = 0while i < self.viewModel.capsules.count {if appData.capsuleUuidActive == self.viewModel.capsules[i].uuid {self.scrollToIndex = i}i += 1}}}}struct GridCapsuleView_Previews: PreviewProvider {static var previews: some View {GridCapsuleView( preview: true)}}