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

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

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

import android.widget.FrameLayout
import androidx.fragment.app.Fragment
import tech.skot.view.SKTransitionAndroidLegacy
import tech.skot.view.live.MutableSKLiveData

data class StateProxy(override val screens:List>, override val transition:SKTransitionAndroidLegacy?):SKStackVC.State(screens, transition)

class SKStackViewProxy() : SKComponentViewProxy(), SKStackVC {

    private val lastScreenLD: MutableSKLiveData, SKTransitionAndroidLegacy?>?> = MutableSKLiveData(null)
    override var state: SKStackVC.State = StateProxy(emptyList(),null)
        set(newVal) {
            val newProxyList = newVal.screens as List>
            lastScreenLD.value?.let {
                if (newProxyList.lastOrNull() != it && newProxyList.contains(it.first)) {
                    it.first.saveState()
                }
            }
            lastScreenLD.postValue(newProxyList.lastOrNull()?.let { Pair(it, newVal?.transition as? SKTransitionAndroidLegacy) })
            field = state
        }

    override fun saveState() {
        lastScreenLD.value?.first?.saveState()
    }

    override fun bindTo(activity: SKActivity, fragment: Fragment?, binding: FrameLayout) =
            SKStackView(this, activity, fragment, binding).apply {
                lastScreenLD.observe {
                    onLastScreen(it)
                }
            }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy