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).
Creates a list with the given content that supports selecting a single row. I face the compilation error trying to use this init:
'init(:selection:rowContent:)' is unavailable in watchOS. The method is marked as watchOS 6.0+_ in the documentation. My deployment target is set to watchOS 6.2.
Here's full code:
@State var selectedItem: CustomIdentifiableHashableStruct?
var body: some View {
	List(dataController.dataSource, selection: $selectedItem) { item in
		CustomHashableView(item: item)
	}
}
Thanks for reading.
5
0
3.1k