mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
start add recycler view
This commit is contained in:
parent
cc18f58e4c
commit
347e9c32fe
15
front/common/build.gradle
Normal file
15
front/common/build.gradle
Normal file
@ -0,0 +1,15 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
}
|
||||
|
||||
apply from: "$mppJsProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api internalProject("micro_utils.common")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package dev.inmo.micro_utils.front.recycler_view
|
||||
|
||||
import dev.inmo.micro_utils.common.isOnScreen
|
||||
import kotlinx.browser.document
|
||||
import org.w3c.dom.HTMLDivElement
|
||||
|
||||
abstract class RecyclerViewAdapter<T>(
|
||||
protected val data: List<T>,
|
||||
protected val drawer: RecyclerViewDrawer,
|
||||
private val visibleOutsideOfViewportElements: Int = 1
|
||||
) {
|
||||
val element: HTMLDivElement = document.createElement("div") as HTMLDivElement
|
||||
protected val itemsToElements = mutableMapOf<T, RecyclerViewElement>()
|
||||
|
||||
abstract fun createViewFactory(element: T): RecyclerViewElement
|
||||
|
||||
fun updateVisibleElements() {
|
||||
var firstVisibleElementIndex = -1
|
||||
var lastVisibleElementIndex = -1
|
||||
|
||||
for ((i, item) in data.withIndex()) {
|
||||
itemsToElements[item] ?.let {
|
||||
firstVisibleElementIndex = when {
|
||||
firstVisibleElementIndex == -1 -> i
|
||||
it.element.isOnScreen -> minOf(firstVisibleElementIndex, i)
|
||||
else -> firstVisibleElementIndex
|
||||
}
|
||||
lastVisibleElementIndex = when {
|
||||
lastVisibleElementIndex == -1 -> i
|
||||
it.element.isOnScreen -> maxOf(lastVisibleElementIndex, i)
|
||||
else -> lastVisibleElementIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package dev.inmo.micro_utils.front.recycler_view
|
||||
|
||||
import org.w3c.dom.HTMLElement
|
||||
|
||||
interface RecyclerViewDrawer {
|
||||
fun drawBefore(what: HTMLElement, before: HTMLElement)
|
||||
fun drawAfter(what: HTMLElement, after: HTMLElement)
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package dev.inmo.micro_utils.front.recycler_view
|
||||
|
||||
import org.w3c.dom.HTMLElement
|
||||
|
||||
interface RecyclerViewElement {
|
||||
val element: HTMLElement
|
||||
suspend fun onOutsideOfViewport()
|
||||
suspend fun onInsideOfViewport()
|
||||
}
|
30
mppJsProject
Normal file
30
mppJsProject
Normal file
@ -0,0 +1,30 @@
|
||||
project.version = "$version"
|
||||
project.group = "$group"
|
||||
|
||||
apply from: "$publishGradlePath"
|
||||
|
||||
kotlin {
|
||||
js (BOTH) {
|
||||
browser()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-common')
|
||||
implementation kotlin('test-annotations-common')
|
||||
}
|
||||
}
|
||||
jsTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-js')
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user