|
Adding a dismiss() at the end of the function triggers a back action, but doesn't close the modal view. Lists are in different files. There is also a dismiss in the modal view, and it closes the view. It is necessary to send a request for a dismiss from one view to another. There must be some easy way, but I can't find it. |
|
Try to pass it via binding instead of using dismiss()
UPD: Using your logic this should look something like this.
|
|
Thank you @ygeras for the extended answer. I thought that I should use @Binding. But I have almost all the problems with the project related to misunderstanding the connection of the view files :) And this solution causes a lot of errors in the code. Since the structure of the views does not consist of two, but four files. ContentView() file > .sheet ModalView() file > ModalSectionView() file with NavigationLink to > DetailListView() file Perhaps I should rethink the structure of my application and use only one file per view until I gain more knowledge and understanding... |
|
Probably better idea to change the structure, but once again depends on the goal you want to achieve. But basically you can pass @Binding var to deeper views you don't necessarily use them in all the views. Like so: ContentView(@State var) file > .sheet ModalView(@Binding var) file > ModalSectionView(@Binding var) file with NavigationLink to > DetailListView(@Binding var) file <- and here you change it to false making it dismiss the ModalView in all subviews you bind(refer to) it to state var, and then you change it to false making it do dismiss the Modal View As an example you can have any number of views as you need. The issue in choosing this way, you have to pass binding all the way down. For example refering to ObservableObject and injecting one in environment you can use it without passing down but directly from the view in which it is required.
|
|
With injecting object in enviroment may look like this
|
|
SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.