I have quite a bit of material about SwiftUI Lists. However, I seem to be lacking information about how to respond to an item being "selected". I put "selected" into quotes because my idea of selecting an item is different from putting a list into selection mode.
For example, in the book "SwiftUI for Masterminds" discusses in Chapter 10 about presenting a selection tool when a List is initialized with the selection attribute. The selection tool presents checkboxes (circles actually) that allow the user to select one or more items in the list. This type of selection is not what I am thinking about.
When I refer to selecting an item I mean tapping or clicking (on a Mac) an item. This action fires an event that the application responds to. This is not necessarily a navigation event. It might be that the appropriate response is send a message to a remote site or to perform a calculation using the item that was tapped or clicked. Thus, the complexity of navigation views need not come into play.
At the moment I don't have satisfactory answers for implementing this kind of behavior. I have found that I can an onTapGesture modifier to each item in the list. However, this seems like a convoluted approach. I really want the behavior to be at the level of the List. The tap or click would be associated with the List rather than with each item in the List.
As I learn more I will update this post. Please feel free to add additional information here. I would like to see this post be a useful resource for everyone.
For example, in the book "SwiftUI for Masterminds" discusses in Chapter 10 about presenting a selection tool when a List is initialized with the selection attribute. The selection tool presents checkboxes (circles actually) that allow the user to select one or more items in the list. This type of selection is not what I am thinking about.
When I refer to selecting an item I mean tapping or clicking (on a Mac) an item. This action fires an event that the application responds to. This is not necessarily a navigation event. It might be that the appropriate response is send a message to a remote site or to perform a calculation using the item that was tapped or clicked. Thus, the complexity of navigation views need not come into play.
At the moment I don't have satisfactory answers for implementing this kind of behavior. I have found that I can an onTapGesture modifier to each item in the list. However, this seems like a convoluted approach. I really want the behavior to be at the level of the List. The tap or click would be associated with the List rather than with each item in the List.
As I learn more I will update this post. Please feel free to add additional information here. I would like to see this post be a useful resource for everyone.