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

High CPU load even if hidden #3

Open
denis-obukhov opened this issue Nov 3, 2021 · 1 comment
Open

High CPU load even if hidden #3

denis-obukhov opened this issue Nov 3, 2021 · 1 comment

Comments

@denis-obukhov
Copy link

Hi. If I have a view like this:

	@ViewBuilder var listView: some View {
		if isLoading {
			skeletonView.shimmer()
		} else {
			listView
		}
	}

Then even if isLoading is false is still consumes CPU. The more cells the more consumption. I have about 36% on my iPhone 11 even if there's no shimmering view on screen. If remove shimmering then CPU load is 0%.

@MojtabaHs
Copy link

MojtabaHs commented Jan 9, 2022

The library uses branching for active and not active states. So first of all, you need to explicitly pass in the active argument:

.shimmering(active: shouldShim)

Also, you are using branching too! So the code will not call the false
state if you just put it in the way you write it!

So you need to extract the shimmer out like:

func listView(shouldShim: Bool) -> some View {

        var listView: some View {
            if shouldShim {
                return skeletonView
            } else {
                return listView // <- What is this by the way ? do you mean self.listView ? 🤔
            }
        }
        
        return listView
            .shimmering(active: shouldShim)
}

This is just a work around and I hope the library supports the branching and auto animation stop for reduce the CPU usage

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