У меня настроен NavigationView
, и я пытаюсь определить, какое представление отправить пользователю, в зависимости от того, что они выбрали. У меня есть четыре разных файла, которые мы можем назвать ClassicLiftsView.swift, SFF1.swift, SFF2.swift и SFF3.swift. В настоящее время у меня в качестве места назначения установлен один файл.
struct ProgramList: View {
@State var showUpdate = true
var body: some View {
VStack {
NavigationView {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(programData) { program in
GeometryReader { geometry in
NavigationLink(destination:
ClassicLiftsView()) {
ProgramsView(program: program)
.rotation3DEffect(Angle(degrees:
Double(geometry.frame(in: .global).minX - 50) / -30
), axis: (x: 0, y: 10.0, z: 0))
}
}
.frame(width: 275, height: 375)
}
.onMove{ (source: IndexSet, destination: Int) in
programData.move(fromOffsets: source, toOffset: destination)
}
.padding(10)
.padding(.bottom, 30)
}
Spacer()
}
.navigationBarTitle(Text("Weida Programs"))
}
}
}
}
struct ProgramList_Previews: PreviewProvider {
static var previews: some View {
ProgramList()
}
}
struct ProgramsView: View {
var program: Program
var body: some View {
VStack {
HStack {
Text(program.title)
.font(.system(size: 24, weight: .bold))
.frame(width: 160, alignment: .leading)
.foregroundColor(.white)
Spacer()
Image(program.logo)
.renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 36, height: 36)
}
Text(program.text.uppercased())
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundColor(.black)
Image(program.image)
.renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 210)
.cornerRadius(5)
.shadow(color: Color.black.opacity(0.2), radius: 20, x: 0, y: 20)
Spacer()
}
.padding(.top, 20)
.padding(.horizontal, 20)
.frame(width: 275, height: 350)
.background(program.color)
.cornerRadius(30)
.shadow(color: Color.black.opacity(0.4), radius: 20, x: 0, y: 20)
}
}
struct Program: Identifiable {
var id = UUID()
var title: String
var text: String
var logo: String
var image: String
var color: LinearGradient
}
var programData = [
Program(title: "So Fit 1.0", text: "12 Week Program", logo: "Weida", image: "program1", color: LinearGradient(gradient: Gradient(colors: [Color(#colorLiteral(red: 0.7540688515, green: 0.7540867925, blue: 0.7540771365, alpha: 1)), Color(#colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1))]), startPoint: .top, endPoint: .bottom)),
Program(title: "So Fit 2.0", text: "12 Week Program", logo: "Weida", image: "program2", color: LinearGradient(gradient: Gradient(colors: [Color(#colorLiteral(red: 0.7540688515, green: 0.7540867925, blue: 0.7540771365, alpha: 1)), Color(#colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1))]), startPoint: .top, endPoint: .bottom)),
Program(title: "Classic Lifts", text: "Classic Training Program", logo: "Weida", image: "program3", color: LinearGradient(gradient: Gradient(colors: [Color(#colorLiteral(red: 0.7540688515, green: 0.7540867925, blue: 0.7540771365, alpha: 1)), Color(#colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1))]), startPoint: .top, endPoint: .bottom)),
Program(title: "The Weida Way", text: "Classic Training Program", logo: "Weida", image: "program4", color: LinearGradient(gradient: Gradient(colors: [Color(#colorLiteral(red: 0.7540688515, green: 0.7540867925, blue: 0.7540771365, alpha: 1)), Color(#colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1))]), startPoint: .top, endPoint: .bottom)),
]