0

I have problem because on appear modifier doesn't call every time when I enter the screen and it calls randomly (when on appear is applied to navigation view). When I put it on some view inside navigation view it never calls. What is the problem, I can't solve it, this is very strange behaviour. This is the view:

struct CheckListView: View {

@EnvironmentObject var appState: AppState
@StateObject var checkListViewModel = CheckListViewModel()
//@State var didSelectCreateNewList = false
@State var didSelectShareList = false

var body: some View {
    NavigationView {
        GeometryReader { reader in
            VStack {
                Spacer()
                    .frame(height: 30)
                
                Text("\(appState.hikingTypeModel.name)/\(appState.lengthOfStayType.name)")
                    .foregroundColor(Color("rectBackground"))
                    .multilineTextAlignment(.center)
                    .font(.largeTitle)
                
                Spacer()
                    .frame(height: 40)
                
                List {
                    ForEach(checkListViewModel.checkListModel.sections) { section in
                        CheckListSection(model: section)
                            .listRowBackground(Color("background"))
                    }
                }
                .listStyle(.plain)
                .clearListBackground()
                .clipped()
                
                Spacer()
                    .frame(height: 40)
                
                HStack {
                    FilledRectangleBorderButtonView(titleLabel: "Share", backgroundColor: Color("rectBackground"),foregroundColor: .white, height: 55, didActionOnButtonHappened: $didSelectShareList)
                    
                    Spacer()
                    
                    FilledRectangleBorderButtonView(titleLabel: "Create new list", backgroundColor: .clear, foregroundColor: Color("rectBackground"), height: 55, didActionOnButtonHappened: $checkListViewModel.didSelectNewList)
                        .onChange(of: checkListViewModel.didSelectNewList) { _ in
                            UserDefaultsHelper().emptyUserDefaults()
                            appState.moveToRootView = .createNewList
                        }
                }
                .padding([.leading, .trailing], 20)
                .frame(width: reader.size.width)
                
                Spacer()
                    
            }
            .frame(width: reader.size.width, height: reader.size.height)
            .background(Color("background"))
            .navigationBarStyle()
        }
    }
    .onAppear {
        self.checkListViewModel.loadJSON(hikingTypeId: appState.hikingTypeModel.id, lengthStayId: appState.lengthOfStayType.id)
    }
}

}

0 Answers0