mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
update left items
This commit is contained in:
parent
e7a0fa4e8f
commit
629884a396
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
* `Klock`: `1.12.1` -> `2.0.0`
|
* `Klock`: `1.12.1` -> `2.0.0`
|
||||||
|
* `Commons`:
|
||||||
|
* Update left items functionality to include work with `GridLayoutManager`
|
||||||
* `Repos`:
|
* `Repos`:
|
||||||
* Add interface `VersionsRepo`
|
* Add interface `VersionsRepo`
|
||||||
* Add default realization of `VersionsRepo` named `StandardVersionsRepo` which use `StandardVersionsRepoProxy`
|
* Add default realization of `VersionsRepo` named `StandardVersionsRepo` which use `StandardVersionsRepoProxy`
|
||||||
|
@ -1,14 +1,20 @@
|
|||||||
package dev.inmo.micro_utils.android.recyclerview
|
package dev.inmo.micro_utils.android.recyclerview
|
||||||
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.*
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.*
|
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(
|
fun RecyclerView.lastVisibleItemFlow(
|
||||||
completingScope: CoroutineScope
|
completingScope: CoroutineScope
|
||||||
): Flow<Int> {
|
): 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())
|
val lastVisibleFlow = MutableStateFlow(lastVisibleElementFun())
|
||||||
addOnScrollListener(
|
addOnScrollListener(
|
||||||
object : RecyclerView.OnScrollListener() {
|
object : RecyclerView.OnScrollListener() {
|
||||||
|
Loading…
Reference in New Issue
Block a user