1

I am currently using a tabview to allow my app to scroll horizontally. At the end of the tabview the user ends up on a register page where they can either click login or sign up. When they click either I want to direct them to a new view where they can't scroll back to register page. Currently after they click login or sign up a new view pops up, but you can still scroll back to the previous pages in the tabview. Any help would be greatly appreciated.

Code:

struct ContentView: View {

var body: some View {
    HStack {
        TabView {
            ForEach(0..<5) {i in
                if(i == 0) {
                    FirstPageView()
                } else if(i == 1) {
                    SecondPageView()
                } else if(i == 2) {
                    ThirdPageView()
                } else {
                    RegisterView()
                }
            }
        }.tabViewStyle(PageTabViewStyle())
        
    }
    
}

}

Register View:

struct RegisterView: View {

var body: some View {
    let screen = UIScreen.main.bounds
    
    let screen_width = screen.size.width
    
    let screen_height = screen.size.height
    
    let theme_color =
        Color(hue: 0.636, saturation: 0.646, brightness: 0.994)
    
    NavigationView{
        VStack(alignment: .leading){
            
            Text("Investing App.")
                .foregroundColor(theme_color)
                .fontWeight(.bold)
                .font(.system(size:screen_width/8))
                .padding(.leading)
            
            
            Text("Start investing")
                .fontWeight(.bold)
                .font(.system(size:screen_width/8))
                .padding(.leading)
            
            
            Text("today.")
                .fontWeight(.bold)
                .font(.system(size:screen_width/8))
                .padding(.leading)
            
            NavigationLink(
                destination: SignUpView(),
                label: {
                    Text("Login")
                        .fontWeight(.bold)
                        .font(.system(size:screen_width/25))
                        .frame(width: screen_width/5, height: screen_width/9, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
                        
                        .padding(.horizontal, screen_width/3)
                        .overlay(
                            RoundedRectangle(cornerRadius: 100)
                                .stroke(lineWidth: 1)
                        )
                })
            
            
            .frame(maxWidth: .infinity, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
            
            
            .offset(y:screen_height/2.5)
                NavigationLink(
                    destination: SignUpView(),
                    label: {
                        Text("Sign Up")
                            .fontWeight(.bold)
                            .font(.system(size:screen_width/25))
                            .frame(width: screen_width/5, height: screen_width/9, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
                            
                            .padding(.horizontal, screen_width/3)
                            .overlay(
                                RoundedRectangle(cornerRadius: 100)
                                    .stroke(lineWidth: 1)
                            )
                    })
                    .frame(maxWidth: .infinity, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
                    
                    
                    .offset(y:screen_height/5)
            
                
                
            
        }
        .padding()
        .offset(y: -screen_height/4+42.4)
        .frame(width: screen_width, height: screen_height/2, alignment: .leading)
        .navigationBarHidden(true)
    }
    .navigationViewStyle(StackNavigationViewStyle())
   
}

}

Thank you!

Evan Moore
  • 31
  • 2
  • 2
    I would ask whether a tab view was the correct architecture for this. – matt Jul 22 '21 at 17:02
  • I agree, but I'm not sure what architecture I should use – Evan Moore Jul 22 '21 at 17:09
  • Well maybe that's what your question should have been about, then. I mean, I think what you've learned so far is that a tab view isn't it, because it allows the user to see any of the tabs at any time. That isn't what you want so that isn't what you should use. – matt Jul 22 '21 at 17:24
  • Do you have any recommendations? – Evan Moore Jul 22 '21 at 18:16
  • You can use a NavigationView instead of TabView in your ContentView. Then you can push the correct view using a NavigationLink – Stanislav Ageev Jul 22 '21 at 18:22
  • Does this answer your question https://stackoverflow.com/a/63500070/12299030? – Asperi Jul 22 '21 at 18:28
  • I'm trying to do the opposite, after swiping through the first views the user will end up on the register view where they will either click signup/login and be redirected to a new view. Currently after they are redirected they can still swipe back to the previous pages. – Evan Moore Jul 22 '21 at 19:58

0 Answers0