Shopify / FunctionalTableData

Declarative UITableViewDataSource implementation
MIT License
365 stars 30 forks source link

Selection fix #210

Closed mikegarfinkle closed 2 years ago

mikegarfinkle commented 2 years ago

The Problem

Multi selection list view had a bug whereby some cells could be selected despite the maximum allowed number of selected cells being reached. See video:

https://user-images.githubusercontent.com/103146151/168328554-1c1c3078-dc60-4064-8e46-936d74fcd791.mov

Why Was this Happening?

The problem was within the FunctionalTableData package. It seems that some cells were being selected with native UIKit functionality, but these selections were never updating the FunctionalTableData state as the cell was null in the call to this function.

The Solution

A cell null check was placed at the top of willSelectRowAt method. If null cells are checked here and, if so, the function is returned at the top of the method, no native UIKit selection takes place.

https://user-images.githubusercontent.com/103146151/168328603-c837b931-0910-4618-8513-8c3a76921b77.mov

Other Secondary Changes

Because FunctionalTableData was written years ago, certain tests were failing on iOS 15. These tests had to do with calling visible cells. The visible cells method on UITable used to return cells in iOS 14, even in unmounted tables (which is what was being used). However, this function now returns nil in iOS 15. The fix was to create a UITable that is mounted to a UIWindow for testing.