Slow performance scrolling the list, when come back from a destination with a NavigationItem - SwiftUI

691 views Asked by At

I've been looking for a long time, until I found the problem. When one of my destination views has a NavigationItem, when I go back to the initial list, I notice a strange behavior and an increase in CPU usage, just by scrolling the list.

My first view is a list with a foreach inside (list - foreach), with some elements of an array. I use a NavigationLink for each item, to my detail view

Initially, scrolling the list you can see that the percentage of CPU usage is minimal

When you select a row, navigate to the detail view that will contain a NavigationItem. Up to this point I think everything is normal. When you go back to the initial view and scroll the list, the percentage of CPU usage is very high. You start noticing a latency in the animation of the list. In this example you can see less because the list only contains strings, but when the row is more complex, you can see much more strange behavior.

The solution would not be to stop using a NavigationItem in my detail view.

I don't know if something is missing, but in such a basic example I can't find the solution to the problem, or the reason for this strange behavior.

This code is using Xcode 11.5 with iOS 13.4.1 and the tests were performed on the device

The complete code is in GitHub, I made a small example illustrating the problem. I thought I'd show only the results and avoid a very big post.

0

There are 0 answers