Expose boolean of whether an item is currently visible in the grid
sindresorhus opened this issue · comments
I have a large grid of NSImageView
's that play animated GIFs. This is very resource intensive, so I would like to pause playing the GIF animation for items that are outside the viewport. It would be useful if Grid could somehow expose this information.
It would also be useful with a method that runs a callback when an element enters/exits the viewport, since .onAppear()
triggers for all grid elements at load time and not when they enter the viewport. Maybe called .onVisibilityChange(isVisible:)
.
@victormihaita most likely this feature will not be implemented. Just like HStack and VStack, Grid is a lower level layout element. I imagine this can be done with the ViewModifier on the presented views directly but not as a part of this project.
@victormihaita I'm looking for a way to fix #81, do you know how to do it?
In this code, when calling onAppear, I expect that it should be called only for the elements visible on the screen, but instead is called for all the elements in the grid. is that correct? This causes also the issue #81 in my case.
Grid(viewModel.dataSource, id: \.id) {
CardView($0).onAppear {
//Do something
}
}