AutorÃa | Ultima modificación | Ver Log |
//// GridCapsuleView.swift// twogetskills//// Created by Efrain Yanez Recanatini on 2/17/22.//import SwiftUIstruct GridCapsuleView: View{@Environment(\.presentationMode)var presentationMode: Bindingprivate var viewModel : CapsuleGridViewModel = CapsuleGridViewModel()let topicDao : TopicDao = TopicDao()let topicModel : TopicModelvar topicTitle : String = ""init(topicUuid : String){let preference = Preference.sharedInstanceself.topicModel = topicDao.selectByUuid(uuid: topicUuid)viewModel.fetch(topicUuid: self.topicModel.uuid, userUuid: preference.userUuid)if self.topicModel.name.count > Constants.APP_BAR_TITLE_MAX_LENGTH {topicTitle = String(Array(self.topicModel.name)[0...Constants.APP_BAR_TITLE_MAX_LENGTH]) + "..."} else {topicTitle = self.topicModel.name}}private let colorBackgroundTopic = UIColor(hex: Config.COLOR_BACKGROUND_TOPIC)private let colorAppTextView = UIColor(hex: Config.COLOR_APP_TEXT_VIEW_TITLE)private let colorAppBackground = UIColor(hex: Config.COLOR_APP_BAR)@State private var backToMain : Bool = falselet itemPerRow: CGFloat = 2let config = [GridItem(.flexible()),GridItem(.flexible())]var body: some View {NavigationLink("", destination: MainView(), isActive: self.$backToMain).frame(height: 0)VStack(spacing: 0.0) {ScrollView() {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: {ForEach(0..<self.viewModel.capsules.count) { i inCardCapsuleView(capsuleModel: self.viewModel.capsules[i]).frame(width: Constants.CARD_WIDTH,height: Constants.CARD_HEIGHT,alignment: .center)}}).padding(.top, 10)}Spacer()}.background(Color(colorBackgroundTopic ?? .gray)).navigationBarBackButtonHidden(true).navigationBarTitleDisplayMode(.inline).navigationTitle(topicTitle).toolbar {ToolbarItem(placement: .navigationBarLeading) {Button(action: {//self.presentationMode.wrappedValue.dismiss()self.backToMain = true}) {HStack {Image(systemName: "chevron.backward").aspectRatio(contentMode: .fit).foregroundColor(Color( colorAppTextView ?? .systemBlue)).background(Color(colorAppBackground ?? .systemBlue))}}}} .onAppear {print("GridCapsuleView")}}}struct GridCapsuleView_Previews: PreviewProvider {static var previews: some View {GridCapsuleView(topicUuid: "T123")}}