This is an example to demonstrate how we can use pagination with Jetpack Compose
when using Room
Database with Hilt
and MVVM
Architecture.
Major Components Highlight
- Jetpack Compose
- Android Paging for compose
- Hilt
- MVVM
-
PagingSource ( NotesDao.kt )
@Query("SELECT * FROM NoteEntity") fun getAllNotesPaginated(): PagingSource<Int, NoteEntity>
-
Pager ( MainActivityViewModel.kt )
val notePager = Pager(config = PagingConfig(10)) { repo.getNotePagingSource() }
-
Lazy Paging Items ( NoteListScreen.kt )
val pager = remember { notePager } val lazyPagingItems = pager.flow.collectAsLazyPagingItems()