All Downloads are FREE. Search and download functionalities are using the official Maven repository.

androidMain.tech.skot.core.components.SKPagerViewProxy.kt Maven / Gradle / Ivy

There is a newer version: 1.2.9
Show newest version
package tech.skot.core.components

import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2
import tech.skot.view.live.MutableSKLiveData


class SKPagerViewProxy(
    initialScreens: List>,
    override val onSwipeToPage: ((index: Int) -> Unit)?,
    initialSelectedPageIndex: Int,
    override val swipable: Boolean
) : SKComponentViewProxy(), SKPagerVC {

    private val selectedPageIndexLD = MutableSKLiveData(initialSelectedPageIndex)
    override var selectedPageIndex by selectedPageIndexLD

    private val screensLD = MutableSKLiveData(initialScreens)
    override var screens: List
        get() = screensLD.value
        set(value) {
            screensLD.postValue(value as List>)
        }

    override fun bindTo(
        activity: SKActivity,
        fragment: Fragment?,
        binding: ViewPager2
    ) =
        SKPagerView(this, activity, fragment, binding).apply {
            onOnSwipeToPage(onSwipeToPage)
            onSwipable(swipable)
            selectedPageIndexLD.observe {
                onSelectedPageIndex(it)
            }
            screensLD.observe {
                onScreens(it)
            }
        }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy