[TIL] ๐ŸŒผ24/05/02๐ŸŒผ#Paging ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

0

TIL

๋ชฉ๋ก ๋ณด๊ธฐ
94/104
post-thumbnail
post-custom-banner

[TIL] ๐ŸŒผ24/05/02๐ŸŒผ#Paging ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

Paging ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

๐Ÿ“Œ์ฐธ๊ณ ์ž๋ฃŒ

Paging ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

  • Paging ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์žฅ์ 
    • In-memory caching for paged data
    • Built-in request deduplication
    • Configurable RecyclerView adapters that automatically request data as the user scrolls toward the end of the loaded data
    • First-class support for Kotlin coroutines and flows
    • Built-in support for error handling (ex. refresh, retry)

  • Paging ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ component๋“ค์€ ์•ฑ์˜ 3 ๋ ˆ์ด์–ด(Repository, ViewModel, UI)์—์„œ ์ž‘๋™
  • Repository ๋ ˆ์ด์–ด
    • PagingSource: data source์™€ ์ด source์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋Š” ๋ฐฉ๋ฒ• ์ •์˜ (๋‹จ์ผ ๋ฐ์ดํ„ฐ ์†Œ์Šค)
    • RemoteMediator: ๊ณ„์ธตํ™”๋œ ๋ฐ์ดํ„ฐ ์†Œ์Šค ํŽ˜์ด์ง• ์ฒ˜๋ฆฌ
  • ViewModel ๋ ˆ์ด์–ด
    • Pager:
      • PagingSource ์˜ค๋ธŒ์ ํŠธ์™€ PageingConfig ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ PagingData์˜ ์ธ์Šคํ„ด์Šค๋ฅผ constructํ•˜๋Š” public API ์ œ๊ณต
      • PagingConfig: PageSource๋กœ๋ถ€ํ„ฐ content๋ฅผ load ํ•  ๋•Œ Pager์˜ behavior ์ •์˜
        PagingConfig(
      		pageSize: Int,
      		prefetchDistance: @IntRange(from = 0) Int,
      		enablePlaceholders: Boolean,
      		initialLoadSize: @IntRange(from = 1) Int,
      		maxSize: @IntRange(from = 2) Int,
      		jumpThreshold: Int
          )
    • PagingData:
      • ViewModel ๋ ˆ์ด์–ด์™€ UI ๋ ˆ์ด์–ด๋ฅผ ์—ฐ๊ฒฐํ•˜๋Š” ๊ตฌ์„ฑ ์š”์†Œ
      • container for a snapshot of paginated data
      • PagingSource ์˜ค๋ธŒ์ ํŠธ๋ฅผ queryํ•˜์—ฌ ๊ฒฐ๊ณผ ์ €์žฅ
  • UI ๋ ˆ์ด์–ด
    • PagingDataAdapter: paged data๋ฅผ handlingํ•˜๋Š” RecyclerView Adapter
    • Jetpack Compose๋กœ UI๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒฝ์šฐ, collectAsLazyPagingItems ์‚ฌ์šฉ
      @Composable
      fun <T : Any> Flow<PagingData<T>>.collectAsLazyPagingItems(
         context: CoroutineContext = EmptyCoroutineContext
      ): LazyPagingItems<T>
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€