This is about the architecture of SwiftUI.
Objective: I want to open and close little overlay message box.
When closed, I don't want to use system resource, and additionally I'll be happy if I can use onAppear and onDisappear.
Also, I want my closing animation work properly.
Implementation:
1. Use complete object destruction by defining
if view == nil{
In this way, when I started closing animation by withAnimation{overlayView = nil}, the screen shows preview of the main view, so I see all the blinks and glitches.
2. opacity -> 0
By this method, I am worried that I cannot achieve the objective. It is wasting my resources and I think I cannot use onDisappear.
3. hidden(_ bool: Bool)
Define this function for View. This worked perfectly so I did not tested 2nd option. I think this is supposed to do, designed by Apple developers.
In this way, onAppear is called *when the mainview.overlay() is called * when overlay is unhidden *but not when overlay is not completely hidden but new appearance is called. onDisappear is called *when overlay is completely hidden (end of animation) *but not when overlay hiding animation is over but new overlay unhiding is called.
No comments:
Post a Comment