ios – Knowledge not displayed correctly on navigation

ios – Knowledge not displayed correctly on navigation


I’ve a parentview CreateReportView, it include two subviews that are accessed on the idea of navigation. My knowledge is being correctly saved and fetched between baby view (create report element view) and parentview (create report view) however after I navigate to NewUploadGalleryView my knowledge vanishes, what may very well be the potential drawback? I even modified my states variable to StateObject and ObservedObject respectively to keep up knowledge consistency. My knowledge stays wonderful after I carry out navigation between create report element and create report element view however as quickly as I navigate to NewuploadGallery and return again to createReportView to navigate into createReportDetailView my knowledge resets

Right here is my CreateReportView,

struct CreateReportView: View {
    @Surroundings(.dismiss) var dismiss
    @State non-public var showingNotifications = false
    @State non-public var isDashboardView = true
    @State non-public var isNotificationView = true
    @State var navigateToSelection:Bool = false
    @State var navigateToSectionDetail: Bool = false
    @State var uploadButton:String?
    var isGallery = false
    var crTitle = ""
    var selectedCat: CatModel? = nil
    var selectedSubCat: CatModel? = nil
    var aiData: JSON? = nil
    @State non-public var loadingVC: LoadingVC?
    @State non-public var ImageGallary = [CRFileModel]()
    @State non-public var totalToUpload: Int?
    @State non-public var isDraft = false
    @State non-public var isEditSaveReport = false
    @State var AILabels: Bool = false
    @StateObject non-public var DashboardviewModel = NewDashBoardViewModel()
    @StateObject non-public var viewModel = ContentViewModel()
    @State non-public var selectedItems: [CRItemModel] = []
    @Binding var parentSection: CRSectionModel?
    @State non-public var toHide: Bool = false
    @State non-public var toRecordwithAI: Bool = false
    @StateObject non-public var createReportData = CreateReportData()

    var physique: some View {
        
        VStack{
            NewCustomNavBar(
                title: "Create Report",
                showBackButton: true,
                onBack: {dismiss()},
                onProfileTap: {},
                showingNotifications: $showingNotifications,
                notificationCount: DashboardviewModel.dashBoardModel?.unreadNotificationCount ?? 0,
                isDashboardView: isDashboardView,
                isNotificationView: isNotificationView
            )
            Record{
                VStack(spacing: 20) {
                    // Media Gallery Part
                    if isGallery{
                        NewMediaGallerysView(uploadButton: $uploadButton, minGalleryLimit: selectedSubCat?.galleryMin ?? 0, maxGalleryLimit: selectedSubCat?.galleryMax ?? 20, imageGalleryCount: CRModel.shared.imageGallery.rely, selectedSubCat: selectedSubCat)
                            .onChange(of: uploadButton) { newValue in
                                if let new = newValue{
                                    print("Button tapped with motion: (new)")
                                    print("---------------",CRModel.shared.imageGallery.rely)
                                    navigateToSelection = true
                                    uploadButton = nil
                                }
                                
                            }
                            .background(
                                Group{
                                    NavigationLink(
                                        vacation spot: NewUploadGalleryView(imageGallary: viewModel.imageGallary ?? [CRFileModel](), selectedSubCat: selectedSubCat ?? CatModel(knowledge: JSON()), createReportData: createReportData, parentSection: parentSection).environmentObject(createReportData)
                                            .onDisappear {
                                                // Refresh the rely or knowledge within the dad or mum view
                                                viewModel.getData(
                                                    selectedSubCat: selectedSubCat,
                                                    crTitle: crTitle,
                                                    selectedCat: selectedCat,
                                                    imageGallary: CRModel.shared.imageGallery
                                                )
                                                print("ON UPLOAD GALLERY DISMISS PARENT SECTION VALUE :(parentSection?.gadgets.first?.textValue)")
                                                print("paraaaaams: (CRModel.shared.getParams())")
                                            },
                                        isActive: $navigateToSelection,
                                        label: { EmptyViewDesign() }
                                    )
                                    .hidden()
                                    
                                }
                                
                            )
                    }
                    if aiData != nil {
                        if toHide == false {
                            PrimaryButton(title: "I'm pleased with it!")
                                .onTapGesture {
                                    toHide = true
                                }
                            SecondaryButton(title: "Re Report with AI")
                                .onTapGesture {
                                    toRecordwithAI = true
                                }
                        }
                    }
                    ForEach(viewModel.sections, id: .id) { merchandise in
                        
                        CreateReportListingView(sectionModel:merchandise, aiData: AILabels)
                            .onTapGesture {
                                parentSection = merchandise
                                navigateToSectionDetail = true
                                createReportData.gadgets = merchandise.gadgets
                            }
                        
                    }
                    
                    
                    
                    
                    
                } .listRowSeparator(.hidden) //.padding(.horizontal,20)
                //   .padding()
                    .background(Colour(.systemBackground))
            }.environmentObject(createReportData)
            .listStyle(PlainListStyle())
            .background(
                NavigationLink(vacation spot: CreateReportWithAIView(selectedCat: selectedCat ?? CatModel(knowledge: JSON()), selectedSubCat: selectedSubCat ?? CatModel(knowledge: JSON()), crTitle: crTitle), isActive: $toRecordwithAI){
                    EmptyViewDesign()
                }.hidden()
            )
            .onAppear {
                //                    for i in parentSection?.gadgets ?? [CRItemModel](){
                //                            print("gadgets values onAppear = (i.textValue)")
                //
                //                        }
                //                if viewModel.createRport == nil {
                viewModel.aiData = aiData
                if viewModel.sections.isEmpty{
                    viewModel.getData(selectedSubCat: selectedSubCat, crTitle: crTitle, selectedCat: selectedCat, imageGallary: CRModel.shared.imageGallery) // Fetch knowledge when the view seems
                    if aiData != nil{
                        AILabels = true
                    }
                }
                //                } else {
                //                    viewModel.populateCRModel(crModel: viewModel.createRport)
                //                }
                print("paraaaaams: (CRModel.shared.getParams())")
                print("ON CREATE REPORT APPEAR PARENT SECTION VALUE: (parentSection?.gadgets.first?.textValue)")

            }
            .onDisappear{
                for i in parentSection?.gadgets ?? [CRItemModel]() {
                    print("CR_items values onDisappear = (i.textValue) (i.fieldValue) (i.information)")
                    print("FILESS ARE HERE: (i.information.incorporates(the place: {$0.isLocalURL()}))")
                    print("ON CREATE REPORT DISAPPEAR PARENT SECTION VALUE: (parentSection?.gadgets.first?.textValue)")

                    
                }
                print("ON DISAPPEAR GALLERY COUNT: (CRModel.shared.imageGallery.rely)")
            }
            HStack{
                if viewModel.sections.rely != 0{
                    Button(motion: {
                        saveAsDraftReport()
                    }) {
                        CreateReportDraftButton(title: "Save as Draft")
                    }
                    Button(motion: {
                        //createReport()
                    }){
                        let param = CRModel.shared.getParams()
                        if let params = param.params {
                            CreateReportCreateButton(title: "Create Report")
                                .onTapGesture {
                                    print("Prepared for create report")
                                }
                        }else if let error = param.error {
                            CreateReportCreateButtonGray(title: "Create Report")
                                .onTapGesture {
                                    print("Not Prepared for create report")
                                }
                                .disabled(true)
                        }
                    }
                    
                }
            }.padding(.horizontal, 10)
            
            //        }.navigate(to: CreateReportDetailView(itemModel: selectedItems.first, gadgets: selectedItems), when: $navigateToSectionDetail)
            
        }.navigate(to: CreateReportDetailView(parentSection: $parentSection, createReportData: createReportData)
            .environmentObject(createReportData),
                   when: $navigateToSectionDetail)
            .navigate(to: NotificationsViews(showingNotifications: $showingNotifications), when: $showingNotifications)
            .navigationBarBackButtonHidden()

Right here is my CreateReportDetailView

struct CreateReportDetailView: View {
    @Surroundings(.dismiss) var dismiss
    @State non-public var showingNotifications = false
    @State non-public var isDashboardView = true
    @State non-public var isNotificationView = true
    @StateObject non-public var DashboardviewModel = NewDashBoardViewModel()
    //@State var gadgets: [CRItemModel]
   @Binding var parentSection: CRSectionModel!
    @StateObject non-public var viewModel = ContentViewModel()
    @State non-public var show360: Bool = false
    @State non-public var selectedItem: CRItemModel? = nil
    @State non-public var updatedText: String = "360 View"
    @ObservedObject var createReportData: CreateReportData
    
    
    var physique: some View {
        VStack {
            NewCustomNavBar(
                title: "Create Report Element",
                showBackButton: true,
                onBack: { CRModel.shared.addModifiedSections()
                    dismiss() },
                onProfileTap: {},
                showingNotifications: $showingNotifications,
                notificationCount: DashboardviewModel.dashBoardModel?.unreadNotificationCount ?? 0,
                isDashboardView: isDashboardView,
                isNotificationView: isNotificationView
            )
            ScrollView {
                ForEach(Array(createReportData.gadgets.enumerated()), id: .ingredient.id) { index, merchandise in
                    swap merchandise.getType().rawValue {
                    case "TEXT":
                        let limitString = merchandise.getFieldLimitString()
                        DescriptionInputView(merchandise: $createReportData.gadgets[index],
                            title:"(merchandise.title) (merchandise.matricSymbol != nil ? "((merchandise.matricSymbol!))" : "")",
                            limitString: limitString, characterLimit: merchandise.fieldLimits?.textLimit, necessary: merchandise.necessary,
                            requiredDocument: merchandise.documentRequired, requiredAudio: merchandise.audioRequired,
                                             requiredVideo: merchandise.videoRequired, requiredImage: merchandise.imageRequired, description: merchandise.textValue ?? "", attachment: merchandise.information, parentSection: parentSection
                        ) .....

Right here is my NewUploadGalleryView

struct NewUploadGalleryView: View {
    @FocusState non-public var activeTextField: UUID?
    
    @State var imageGallary: [CRFileModel]
    @State var selectedSubCat: CatModel
    @State non-public var showingNotifications = false
    @State non-public var isDashboardView = true
    @State non-public var isNotificationView = true
    @StateObject non-public var DashboardviewModel = NewDashBoardViewModel()
    @Surroundings(.dismiss) var dismiss
    @State var uploadButton: Bool = false
    @State non-public var showToast = false
    @State non-public var toastMessage = ""
    @State non-public var uploadState: UploadState = .chooseFiles
    @State var reload: Bool? = false
    @State non-public var showingFullScreenImage: Bool = false
    @State non-public var selectedImageUrl: String? // Retailer the URL of the tapped picture
    @State non-public var isProcessingTap = false
    @State non-public var deletingItemID: UUID?
    @ObservedObject var createReportData: CreateReportData
    @StateObject non-public var viewModel = ContentViewModel()
    let parentSection: CRSectionModel?

    @EnvironmentObject non-public var networkMonitorUpdated: NetworkMonitorUpdated

....

Leave a Reply

Your email address will not be published. Required fields are marked *