Fixed a bug with no view due to the SwiftUI view lifecycle. - #184
Open
HanweeeeLee wants to merge 3 commits into
Open
Fixed a bug with no view due to the SwiftUI view lifecycle.#184HanweeeeLee wants to merge 3 commits into
HanweeeeLee wants to merge 3 commits into
Conversation
정적인 뷰에서는 문제가 없지만, 구현상의 문제로 동적으로 데이터가 변하는 경우는 뷰가 사라짐. 이유는 Source of truth를 뷰의 생성자에서 생성하기 때문임. 우선 임시로 Source of truth를 주입 받을 수 있게 수정해놓았음.
외부에서 PSManager(Source of truth)를 주입받기 위해서는 해당 클래스의 인스턴스를 직접 생성, 관리해야함. public으로 변경
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem 1
as-is)
The Partial Sheet does not work in the following code:
The reason it doesn’t work can be identified in this code:
Since 'updateContent()' only triggers when the value of 'isPresented' changes, if the initial value is true, the screen does not update.
to-be)
Modifying the code as below allows the initial value to be reflected correctly:
Problem 2
as-is)
The view disappears when the “Source of Truth” value changes, as shown below:
We can see why the view disappears by looking at the following code:
The PSManager class has its own @published property, isPresented. The Partial Sheet operates based on this isPresented value. When attachPartialSheetToRoot() is called, a new instance of PSManager is created:
Each time the “Source of Truth” changes, the view seems to be redrawn, causing a new PSManager to be created.
to-be)
To solve this, I modified attachPartialSheetToRoot() to allow an externally managed PSManager instance. Although this is not ideal, it provides a temporary solution:
This requires making PSManager public to manage its instances externally.
Then, the ContentView is updated as follows:
If you apply the above modifications, it should work as intended. Let me know if you have suggestions for a better approach!