I want to have a list in my watchOS app which allows user to select one row at a time. The row should maintain its selected state.
The List works well, but I am currently using my own tap gesture recogniser: .onTapGesture() to select a row from my list, I also have to manage selection flow myself. I think it should be possible to simplify my code.
I have found following List API in the Apple documentation, exactly what I need: init(selection: Binding<SelectionValue?>?, content: () -> Content).
Here's full code:
Thanks for reading.
The List works well, but I am currently using my own tap gesture recogniser: .onTapGesture() to select a row from my list, I also have to manage selection flow myself. I think it should be possible to simplify my code.
I have found following List API in the Apple documentation, exactly what I need: init(selection: Binding<SelectionValue?>?, content: () -> Content).
I face the compilation error trying to use this init:Creates a list with the given content that supports selecting a single row.
The method is marked as watchOS 6.0+ in the documentation. My deployment target is set to watchOS 6.2.'init(_:selection:rowContent:)' is unavailable in watchOS.
Here's full code:
Code Block swift @State var selectedItem: CustomIdentifiableHashableStruct? var body: some View { List(dataController.dataSource, selection: $selectedItem) { item in CustomHashableView(item: item) } }
Thanks for reading.
I'm facing the same problem ... do you find any solution?
Thanks.
Same issue on watchOS 10 beta. Any suggestions to solve this?
watchOS 10 supports selection but this is the error message shown if there are any mistakes in the type of the $selection binding. It must be an optional and conform to Identifiable.