import SwiftUI
import RiveRuntime
struct MenuCardView: View {
@State private var CardOne = false
@State private var CardTwo: Bool = false
@AppStorage("selectedCard") var selectedCard: SelectedCard = .CardOne
var body: some View {
ZStack {
ScrollView (.horizontal, showsIndicators: true ) {
VStack(spacing:0) {
TabView {
CardView
}
.tabViewStyle(.page)
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
}
}
if CardOne {
Moon_Event()
.frame(width: 400, height: 780)
.opacity(CardOne ? 1 : 0)
.offset(y: CardOne ? 20 : 0)
.overlay (
Button {
withAnimation(.spring()) {
CardOne.toggle()
}
} label: {
Image(systemName: "xmark")
.frame(width: 40, height: 40)
.foregroundStyle(.black)
.background(.white)
.mask(Circle())
.shadow(color: Color("Shadow").opacity(0.3) ,radius: 5, x: 0, y:3)
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
.offset(y: CardOne ? 15 : 200)
)
.transition(.opacity.combined(with: .move(edge: .top)))
.zIndex(1)
}
if CardTwo {
Sun_Event()
.frame(width: 400, height: 780)
.opacity(CardTwo ? 1 : 0)
.offset(y: CardTwo ? 20 : 0)
.overlay (
Button {
withAnimation(.spring()) {
CardTwo.toggle()
}
} label: {
Image(systemName: "xmark")
.frame(width: 40, height: 40)
.foregroundStyle(.black)
.background(.white)
.mask(Circle())
.shadow(color: Color("Shadow").opacity(0.3) ,radius: 5, x: 0, y:3)
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
.offset(y: CardTwo ? 15 : 200)
)
.transition(.opacity.combined(with: .move(edge: .top)))
.zIndex(1)
}
}
}
}
var CardView: some View {
ForEach(menuItems) { items in
GeometryReader { proxy in
items.rvm.view()
.padding(.vertical, 220)
.rotation3DEffect(.degrees(proxy.frame(in: .global).minX / -10),
axis: (x: 0, y: 1, z: 0))
.shadow(color: Color("Shadow").opacity(0.8), radius: 10, x: 0, y: 10)
.onTapGesture { location in
withAnimation(.spring()) {
print("Location: \(location)")
// items.message.toggle() nor selectedCard.toggle() seem to work. I'm just trying to create a simple .toggle() for which items is on the screen.//
}
}
Text("\(items.message)")
.padding(.top, 290)
}
}
.padding(20)
.frame(height: UIScreen.main.bounds.height)
}
struct MenuItems: Identifiable {
var id = UUID()
var rvm: RiveViewModel
var modal: SelectedCard
var message: String
}
var menuItems = [
MenuItems(rvm: RiveViewModel(fileName: "mooncard"), modal: .CardOne, message: "CardOne"),
MenuItems(rvm: RiveViewModel(fileName: "suncard"), modal: .CardTwo, message: "CardTwo"),
MenuItems(rvm: RiveViewModel(fileName: "mooncard"), modal: .CardThree, message: "CardThree"),
MenuItems(rvm: RiveViewModel(fileName: "suncard"), modal: .CardFour, message: "CardFour")
]
enum SelectedCard: String {
case CardOne
case CardTwo
case CardThree
case CardFour
}
#Preview {
MenuCardView()
}
Unable to trigger a .toggle() to a ForEach loop of items in an array.
ok figured it out.
Just needed to assign an item.tab == .timer or .star or .user to a .toggle() with an assigned @EnvironmentObject and @Published class variable to deliver the trigger to the desired target. Used an if else for the three desired targets. Mainly used this setup for a tab menu bar.