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

How to fix pre-loading? I want to disable it #698

Open
ruofeilyu opened this issue Feb 11, 2024 · 3 comments
Open

How to fix pre-loading? I want to disable it #698

ruofeilyu opened this issue Feb 11, 2024 · 3 comments

Comments

@ruofeilyu
Copy link

For example, If I have 3 pages, I found that each page's neighbors will also called viewDidload? how can I disable it to make it only load when I am showing(the first page)

@rechsteiner
Copy link
Owner

Hi @ruofeilyu! What's the motivation for disabling pre-loading? If you have some operation you only want to be called when showing the view I would recommend moving it into viewWillAppear/viewDidAppear. The problem with removing preloading is that you could potentially allocate a lot of instances, and they will all be allocated while scrolling. Imagine if a user is swiping slightly back-and-forth on the current page. Each time you hit the edge (which could happen a lot), you would need to allocate a whole new view controller.

@ruofeilyu
Copy link
Author

My case is that I use parchment as a navigation tab, so you can think its tab's tab. I have already cache every controller so it will not be recreated,

My implementation is that I need to add my swiftUI in each viewcontroller viewdidLoad (the reason that I don't use parchment swiftUI is that it will reset my previous view if I have multiple page because every page is a struct, I don't want to reset every page, i wanna to maintain its original position, same reason if you switch the tab, you don't want your previous tab got reset), Ok, now my networking got triggered at each swiftUI onTask(), this will got triggered immediately on viewDidLoad, so here is that problem,I don't want to trigger networking if this page is not shown yet and I know I can trigger networking in viewWillAppear, but it's kinda break my design, I want my swiftUI doing everything rather than delegate some action to its wrapper view controller.

So that's the reason I want to disable preloading. I know it's a little complicated case....

@aiKrice
Copy link
Contributor

aiKrice commented Mar 14, 2024

@ruofeilyu My opinion on your usecase is that it's very special and maybe you are going wrong on either:

  • Product side: Is the UX of your product is really optimized
  • Tech side: maybe consider going custom rather than use a lib if this part is a core feature with such a request

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

3 participants