Post

Replies

Boosts

Views

Created

Passing a variable from tabView(LazyHStack) to separate view
I have a tabview inside of a scrollview in a LazyHStack. As the new tabview loads a secondary view needs to update with the new value. Here is the code. I have multiple values I'd like to pass to the second view that need to update on the swipe with the new values. struct TopCardPager:   View {   var body: some View {     ScrollView{       LazyHStack{         PageView()       }//: LAZYHSTACK     }//: SCROLLVIEW   } } The Page view is a foreach loop pulling from an array inside a model. struct PageView: View {       var body: some View {     TabView {             ForEach(pipelines) { cont in         VStack{           HStack {             Image("ray")               .resizable()               .frame(width: 120, height: 120)               .clipShape(Circle())               .shadow(radius: 10)               .overlay(Circle().stroke(Color.white, lineWidth: 5))               .padding(.horizontal)             Spacer()             VStack {               Text("Last Contact")                 .font(.title)                 .fontWeight(.bold)               Text(cont.mobile)               Text(cont.email)             }             .font(.title)             .padding(.horizontal)           }           ZStack{             Capsule()               .fill(Color.red)               .frame(width: 275.0, height: 50.0, alignment: .center)             HStack{               Text(cont.firstname)               Text(cont.lastname)                             }             .font(.largeTitle)             .foregroundColor(Color.white)                         }           .clipShape(RoundedRectangle(cornerRadius: 10.0, style: .continuous))           .padding(.all)         }       }     }     .frame(width: UIScreen.main.bounds.width, height: 200)     .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never)) Would like to pull this into a separate view that updates when the tabview/scroll view is swiped to the next item. Here is one example ZStack{           RoundedRectangle(cornerRadius: 15)             .fill(Color.black)                       Button(action: { let tel = "tel://"             let formattedString = tel + passed info goes here             guard let url = URL(string: formattedString) else { return }             UIApplication.shared.open(url)           }
1
0
534
Mar ’21