Learn Courses My Dashboard

Navigation Link: Execute Code Before Transition

Hi

I Have 2 Views
View1 displays View 2 using navigation link
View1 pass a local array to View2 to be displayed

Upon Clicking Navigation Link
I need to populate the local array by fetching data from core data
the FetchPredicate (filter) depends on selection made in View 1

I manage to execute a fetch a procedure upon end of tap gesture using the following code:

NavigationLink {
                        TestCardView(words: wordsToCardView)
                        } label: {
                            Text("Flash Card")
                                .font(.title)
                        }.disabled(dB.collections.count <= 0 || dB.words.count <= 0 ? true : false)
                        .simultaneousGesture(TapGesture().onEnded({ _ in
                            if(memoType == .Collection)
                            { // populate wordsToCardView by fetching data from CoreData
                                wordsToCardView = dB.generateFlashQuiz(wc: settings.iCardNount, collection: dB.collections[memoCllectSelectIdx], filterHidden: settings.bBypassHidden)
                            } // TODO: add else if for other selection
                            else {
                                wordsToCardView = []
                            }
                            
                                
                        }))

the problem now is:
The view transition happens before the fetch procedure finish
so when it display View2 the data is not yet updated

I tried to search from google, there seem to be isActive flag for NavigationLink which can sync the procedure end and the destination view display
https://developer.apple.com/forums/thread/124345
but upon testing, it is no longer working and also deprecated

I could imagine how it was used to be done
If Tag and Selector is available, perhaps I can make the NavigationLink Hidden
Then I will create a button that will execute the fetch proc and finally toggle the selector

but currently is deprecated and can’t find alternative at this moment

I think I got solution from here:

using fullscreen cover