AutorÃa | Ultima modificación | Ver Log |
//
// GridSlideView.swift
// twogetskills
//
// Created by Efrain Yanez Recanatini on 2/17/22.
//
import SwiftUI
struct GridSlideView: View {
@Environment(\.presentationMode)
var presentationMode: Binding
private let capsuleDao : CapsuleDao = CapsuleDao()
private var capsuleModel : CapsuleModel = CapsuleModel()
private var viewModel : SlideGridViewModel = SlideGridViewModel()
private var capsuleTitle : String = ""
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)
private let config = [
GridItem(.fixed(Constants.CARD_WIDTH)),
GridItem(.fixed(Constants.CARD_WIDTH))
]
@State private var backToCapsules : Bool = false
init(capsuleUuid : String)
{
let preference = Preference.sharedInstance
self.capsuleModel = capsuleDao.selectByUuid(uuid: capsuleUuid)
viewModel.fetch(capsuleUuid: self.capsuleModel.uuid, userUuid: preference.userUuid)
if self.capsuleModel.name.count > Constants.APP_BAR_TITLE_MAX_LENGTH {
capsuleTitle = String(Array(self.capsuleModel.name)[0...Constants.APP_BAR_TITLE_MAX_LENGTH]) + "..."
} else {
capsuleTitle = self.capsuleModel.name
}
}
var body: some View {
VStack(spacing: 0.0) {
NavigationLink("", destination: GridCapsuleView(topicUuid: self.capsuleModel.topicUuid), isActive: self.$backToCapsules).frame( height: 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.slides.count) { i in
CardSlideView(slideUuid: self.viewModel.slides[i].uuid, position: i
).frame(
width: Constants.CARD_WIDTH,
height: Constants.CARD_HEIGHT,
alignment: .center
)
}
}).padding(.top, 10)
}
Spacer()
}
.background(Color(colorBackgroundTopic ?? .gray))
.navigationBarTitleDisplayMode(.inline)
.navigationTitle(capsuleTitle)
.navigationBarBackButtonHidden(true)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button(action: {
//self.presentationMode.wrappedValue.dismiss()
self.backToCapsules = true
}) {
HStack {
Image(systemName: "chevron.backward")
.aspectRatio(contentMode: .fit)
.foregroundColor(Color( colorAppTextView ?? .systemBlue))
.background(Color(colorAppBackground ?? .systemBlue))
}
}
}
} .onAppear {
print("GridSlideView")
}
}
}
struct GridSlideView_Previews: PreviewProvider {
static var previews: some View {
GridSlideView(capsuleUuid: "C123")
}
}