androidMain.tech.skot.core.components.SKPagerViewProxy.kt Maven / Gradle / Ivy
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 saveState() {
for (screenViewProxy in screensLD.value) {
screenViewProxy.saveState()
}
}
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