Fixed a bug with no view due to the SwiftUI view lifecycle. #184
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!