Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using UIViewControllerRepresentable means view lifecycle functions do not properly work because of how views are now disabled and hidden but still shown #8

Open
bryan1anderson opened this issue Oct 9, 2023 · 1 comment

Comments

@bryan1anderson
Copy link

You recently implemented a change that made views no longer disappear so that the views were not completely deconstructed and reconstructed each time you switched tabs.

This has unforeseen consequences such as the fact that viewDidAppear does not get called when you switch to a tab. In my own project I implemented an EnvironmentKey that passed down "isViewVisible" that then manually called viewDidAppear on a UIViewControllerRepresentable.

However, viewDidAppear still gets called on all the view controllers on init of the tab bar, despite them not being shown.

@zijievv
Copy link
Owner

zijievv commented Oct 17, 2023

Yes, "disabled" views are simply hidden, and there will be problems when calling viewDidAppear. However, I haven't found a way to resolve the issue. View states cannot persist without hiding views using opacity(_:).

I just want to use pure SwiftUI to implement the TabBar. For now, the only way is to pass a willSelect action into tabItem(_:label:willSelect:) to manually call functions.

Do you have any solutions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants