A Xamarin iOS library for keeping a UICollectionView in sync with a dynamic SQL data model.
Install-Package Dabble.DifferentialCollections
With a single line of code, initiate the synchronization between a UICollectionView and a highly dynamic data source of thousands of records, avoiding any complex, application-specific messaging - while supporting request pagination, animations, and persistent cell-selection.
void TxtSearch_TextChanged(object sender, UISearchBarTextChangedEventArgs e)
{
// Tell the Differential Collection to requery the SQL data-source, calculate and push all the changes
// to the collection view, in a non-destructive manner.
_cryptoCoinDataSource.RequeryWithCriteria(x =>
{
x.FilterString = txtSearch.Text;
});
}The result (see Milestone2 project in the Tutorials folder), is a collection-view update that
- Removes rows that have disappeared from the result-set.
- Adds rows that have appeared in the result-set.
- Moves the positions of rows that now fall in a different location in the result-set.
- Reloads rows that have changed in the database since they were last displayed.
- Retains selection as rows move about.
- Avoids any 'janky' visual experience!
Follow these steps - the example class names here are referencing the 'Milestone 2' example project.
-
Derive
DifferentialDataModel<TPrimaryKey, TTableModel, TTableCriteria>.
This class executes the appropriate queries to supply paginated results, and row meta-data to theDifferentialCollectionViewSource.
CryptoCoinDataSourcein the example.- Implement
GetCountto count the number of table records matching your criteria. - Implement
GetRowMetato return the row position and version of a set of records matching the supplied list of primary keys. - Implement
GetIdsto return a list of primary keys for a page of records. - Implement
GetPageto return a page of fully-populate records that will be passed into your cells for display.
- Implement
-
Implement
TTableCriteria.
This class encapsulates all query variation that you will want to perform, if the user will 'search' for example, this class needs needs a property to hold the search string.
CryptoCoinCriteriain the example. -
Derive
DifferentialCollectionViewSource<TPrimaryKey, TTableModel, TTableCriteria>.
This class receives the message that a model object has been pulled from the database, and lets you bind it into the widgets in a cell viaOnDataContextLoaded
CryptoCoinCollectionViewSourcein the example. -
Wire it up in your
ViewController.- Instantiate your
DifferentialCollectionViewDataSource - Instantiate your
DifferentialCollectionViewSource - Assign the
DifferentialCollectionViewDataSourceto theDataModelproperty of yourDifferentialCollectionViewSource - Assign the
DifferentialCollectionViewSourceto theSourceproperty of yourUICollectionView
- Instantiate your
Any time you change your underlying database, call your DifferentialCollectionViewDataSource.Requery() to refresh the collection view.
If you also want to change the criteria used to populate your view, pass it to the RequeryWithCriteria:
_cryptoCoinDataSource.RequeryWithCriteria(x =>
{
x.FilterString = txtSearch.Text;
});


