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

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

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

import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import tech.skot.core.SKLog
import tech.skot.view.extensions.setVisible

class SKBoxView(
    proxy: SKBoxViewProxy,
    activity: SKActivity,
    fragment: Fragment?,
    viewGroup: ViewGroup
) : SKComponentView(proxy, activity, fragment, viewGroup) {


    private var currentViews:List? = null
    fun onItems(items: List>) {
        binding.removeAllViews()
        subViews.clear()
        binding.post {
            items.forEach { newItemProxy ->
                val existingView = currentViews?.find { it.tag == newItemProxy.hashCode() }
                if (existingView != null) {
                    binding.addView(existingView)
                }
                else {
                    newItemProxy.inflateInParentAndBind(activity = activity, fragment = fragment, parent = binding)
                }
            }
            val newCurrentViews = mutableListOf()
            (0 until binding.childCount).forEach {
                newCurrentViews.add(binding.getChildAt(it))
            }
            currentViews = newCurrentViews
        }

    }

    fun onHidden(hidden: Boolean?) {
        hidden?.let { binding.setVisible(!it) }

    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy