Open zarag13 opened 4 weeks ago
Hey @zarag13, thanks for taking the time to review the code and provide your feedback. I’m aware of this issue with the spotlight system, and it’s something I had considered during the initial implementation. The reason it wasn’t tackled at the time is that SwiftUI
didn’t provide a way to programmatically reference and control ScrollView
components. Without that capability, the spotlight system wasn’t able to manage the scroll views in the app.
When I first wrote the spotlight system, I hadn’t yet come across the ScrollViewProxy
component. This proxy seems like a potential solution, allowing us to programmatically scroll to specific components. However, we’d need to explore exactly how the proxy works and figure out the best way to integrate it into the spotlight system.
One possible approach could be adding an optional ScrollViewProxy
parameter to the spotlightElement(_:,_:)
modifier. This way, users can provide the scroll view proxy for elements that might need to be scrolled into view. The SpotlightViewModifier
or SpotlightViewModel
could then reference that proxy and scroll elements into frame when needed.
I’d be happy to create an enhancement for this functionality. Let me know what you think!
thanks, yes, I figured out the scrolling, my app just supports iOS 15
I also wanted to know if your system allows you to select multiple objects for highlighting? by linking them to one key, or does this require some other approach? for example: a list of cells, and out of 10, two of them are immediately highlighted
Got it. If you don't mind, would you be willing to share how you handled the scrolling? Did you utilize ScrollViewProxy
?
No, there is currently no support for multiple elements at once. Although, we can adjust that by making the Spotlight.elements
array a 2D array, making the SpotlightViewModel.target
an array, and changing FocusOverlay.init
to take in an array of focus rects. I may take that on as an enhancement.
hello, I found your solution, I liked the implementation, but there is a problem when the view is too high - it does not scroll to the desired object, tell me how it could be better done? for example, you highlight 1 cell, but what if you make 15 of them and display the highlighting at the last one ThatSection() -> ForEach(1 ..< 15) -> last.cell.spotlightElement