mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-26 03:58:45 +00:00
update left items
This commit is contained in:
parent
e7a0fa4e8f
commit
629884a396
@ -4,6 +4,8 @@
|
||||
|
||||
* `Versions`:
|
||||
* `Klock`: `1.12.1` -> `2.0.0`
|
||||
* `Commons`:
|
||||
* Update left items functionality to include work with `GridLayoutManager`
|
||||
* `Repos`:
|
||||
* Add interface `VersionsRepo`
|
||||
* Add default realization of `VersionsRepo` named `StandardVersionsRepo` which use `StandardVersionsRepoProxy`
|
||||
|
@ -1,14 +1,20 @@
|
||||
package dev.inmo.micro_utils.android.recyclerview
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
private inline fun RecyclerView.LayoutManager.findLastVisibleItemPositionGetter(): (() -> Int)? = when (this) {
|
||||
is LinearLayoutManager -> ::findLastVisibleItemPosition
|
||||
is GridLayoutManager -> ::findLastVisibleItemPosition
|
||||
else -> null
|
||||
}
|
||||
|
||||
fun RecyclerView.lastVisibleItemFlow(
|
||||
completingScope: CoroutineScope
|
||||
): Flow<Int> {
|
||||
val lastVisibleElementFun: () -> Int = (layoutManager as? LinearLayoutManager) ?.let { it::findLastVisibleItemPosition } ?: error("Currently supported only linear layout manager")
|
||||
val lastVisibleElementFun: () -> Int = layoutManager ?.findLastVisibleItemPositionGetter() ?: error("Currently supported only linear layout manager")
|
||||
val lastVisibleFlow = MutableStateFlow(lastVisibleElementFun())
|
||||
addOnScrollListener(
|
||||
object : RecyclerView.OnScrollListener() {
|
||||
|
Loading…
Reference in New Issue
Block a user