Thanks to visit codestin.com
Credit goes to github.com

Skip to content

The screen content disappears when going back through navigator.back() IOS 17.0 and 17.4 (Swift 6) #60

@NotatNiiK

Description

@NotatNiiK
import NavigatorUI
import SwiftUI

struct ContentView: View {
    @Environment(\.colorScheme) var colorScheme

    var body: some View {
        ManagedNavigationStack {
            WelcomeScreen()
                .navigationDestination(LoginRoutesV2.self)
        }
    }
}

#Preview {
    ContentView()
}

==================  LoginRoutesV2 ==================

import NavigatorUI
import SwiftUI

enum LoginRoutesV2 {
    case login(Bool)
}

extension LoginRoutesV2: NavigationDestination {
    public var body: some View {
        switch self {
        case let .login(isLogin):
            LoginScreen(login: isLogin)
        }
    }

    public var method: NavigationMethod {
        .push
    }
}

==================  WelcomeScreen ==================

import SwiftUI

struct WelcomeScreen: View {
    @Environment(\.navigator) var navigator
    
    var body: some View {
        VStack {
            Text("Welcome")
                .onTapGesture {
                    navigator.navigate(to: LoginRoutesV2.login(false))
                }
        }
    }
    
}

#Preview {
    NavigationStack {
        WelcomeScreen()
    }
}

==================  LoginScreen ==================

import SwiftUI

struct LoginScreen: View {
    @Environment(\.navigator) var navigator
    
    let login: Bool
   
    var body: some View {
        VStack {
            HStack {
                Text("Go back")
                    .onTapGesture {
                        navigator.back()
                    }
            }
            .frame(maxWidth: .infinity, alignment: .leading)
            .padding(.bottom, 20)
            .padding(.leading, 20)
            
            VStack {
                Text("LoginScreen")
                Spacer()
            }
            .frame(maxWidth: .infinity)
            .background(.red)
            .navigationBarBackButtonHidden(true)
        }
        .frame(maxWidth: .infinity)
    }
}

#Preview {
    NavigationStack {
        LoginScreen(login: false)
    }
}

after going back using the navigator.back() button, the LoginScreen content instantly disappears

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions