forXifLess / LinkNavigator

🌊 Easy & Powerful navigation library in SwiftUI
Other
332 stars 23 forks source link

how to pass arguments from view presented using "sheet" to background Parent view #11

Closed hankyungs closed 1 year ago

hankyungs commented 1 year ago

Is there a way to pass the result or a specific value to the parent view when closing a view that has been entered using the navigator.sheet method? And can this be done without reloading the parent view?

(sheet 방식으로 진입한 자식 뷰에서 일을 처리한 뒤, 닫힐때 부모뷰를 replace 또는 reload 하지 않고 어떤 값을 전달할 수 있는 방법이 있을까요?)

interactord commented 1 year ago

초창기 개발할때, 핸들러(handler)나 클로저(closure)를 이용하여 코드 내에서 콜백(callback)을 호출하는 방식을 사용했습니다. 그러나 이를 구현하고 사용해 보니 해당 작업에 최적의 해결책으로 보이지 않아서 결국 이들을 제거했습니다. 실제 경험상 콜백이 필요할 때는 .sheet를 사용하여, 처리하였습니다.

좋은 아이디어가 있으실까요?

(In the early stages of development, I used handlers or closures to invoke callbacks within my code. However, when I attempted to implement and use them, they didn't seem like the optimal solution for the task at hand, so I ultimately removed them. In my practical experience, whenever a callback was necessary, I resorted to using .sheet to handle it.

Do you have any good ideas?)

interactord commented 1 year ago

캐시와 비슷한 공유 데이터를 이용해서 업데이트하고, 뷰의 루트에서 .onAppear를 이용해 데이터를 받아오는 방식으로 처리했습니다. 그러나 iPad에서는 fullSheet 이외에는 .onAppear가 호출되지 않는 문제가 있었습니다.

(I updated the data using shared data similar to cache, and implemented a method of retrieving the data using .onAppear in the view's root. However, there was an issue where .onAppear was not called except for fullSheet on iPad.)

hankyungs commented 1 year ago

답변 감사합니다. sheet 의 경우만 swiftui 의 .sheet modifier를 이용해서 진입하는 방식으로 해결하였습니다. 훌륭한 라이브러리를 만들어주셔서 감사합니다~

Thank you for your response. I have resolved the issue by using the .sheet modifier in SwiftUI only for the case of sheet. Thank you for creating a great library