Thursday, July 18, 2024
HomeiOS Developmentios - Utilizing dismiss with NavigationStack inflicting infinite loop

ios – Utilizing dismiss with NavigationStack inflicting infinite loop


I’ve a SwiftUI view utilizing NavigationStack as follows. I see that having atmosphere variable dismiss is inflicting an infinite loop of subview VideoEditorView creation/deletion/recreation WHEN the app is moved to background and introduced again to the foreground. The problem occurs solely when performing backgrounding/foregrounding of app AND having dismiss var within the View. If I remark out dismiss var from this view, the problem goes away. _PrintChanges additionally prints to @self, _dismiss modified

The problem is most probably a bug in iOS and many individuals have reported the identical on SO and Apple developer boards in numerous context. The primary perpetrator is NavigationStack and dismiss do not go effectively collectively.

So my query is what’s the workaround? Is there some other option to dismiss SwiftUI view aside from utilizing dismiss?

 @out there(iOS 17.0, *)
 struct VideoLibrarySUI: View {
   @Atmosphere (.dismiss) personal var dismiss
   @State var editMode: EditMode = .inactive
  
  @State personal var navigationPath = NavigationPath()
  @State personal var pathList:[String] = []
  @State personal var selectedPaths = Set<String>()

  @State personal var dismissNavigationStack = false

   var physique: some View {
     Self._printChanges()
    
     return NavigationStack(path:$navigationPath) {
        ScrollViewReader { proxy in
            Listing($pathList, id: .self, choice: $selectedPaths) { path in
                VideoListCell(path: path, videoPathToPreview: $videoPathForPreview, videoPreviewAction: $videoPreviewAction, participant: $participant)
                    .id(path.wrappedValue)
                    .onTapGesture {
                        if editMode != .energetic {
                            videoPathForVideoEditing = path.wrappedValue
                        }
                    }
            }
            .listStyle(.grouped)
            .listRowSpacing(0)
            .atmosphere(.defaultMinListRowHeight, 120)
            .atmosphere(.editMode, $editMode)
            .onChange(of: scrollTarget) { goal in
                if let goal = goal {
                    scrollTarget = nil
                    
                    withAnimation {
                        proxy.scrollTo(goal, anchor: .middle)
                    }
                }
            }
        }
        .navigationTitle($contentTitle)
        .onChange(of: videoPathForVideoEditing, carry out: { newValue in
            if videoPathForVideoEditing != nil {
                self.timelineModel = buildModel(URL(fileURLWithPath: videoPathForVideoEditing.unsafelyUnwrapped))
                NSLog("Timeline mannequin (timelineModel.id)")
                openVideoEditor.toggle()
            }
        })
     }
   .fullScreenCover(isPresented: $openVideoEditor, onDismiss: {
        videoPathForVideoEditing = nil
    }, content material: {
        VideoEditorView(timelineModel: $timelineModel)
            .background {
                Colour.secondary
            }
    })



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments