RootView

Interface RootView detém a referência de activity ou fragment.

RootView

A interface RootView detém a referência de uma **activity** ou **fragment**. Através dos métodos da interface, você tem referência de contexto, ciclo de vida, **ViewModelStore** e a ID da **View** pai.

RootView está presente como atributo nas interfaces ViewConvertable e Action:

interface RootView {

    fun getContext(): Context

    fun getLifecycleOwner(): LifecycleOwner

    fun getViewModelStoreOwner(): ViewModelStoreOwner

    fun getParentId(): Int
}

getContext()

Retorna o contexto:

fun getContext(): Context

getLifecycleOwner()

Retorna um lifecycleOwner:

fun getLifecycleOwner(): LifecycleOwner

getViewModelStoreOwner()

Retorna um ViewModelStore para activity e fragment:

fun getViewModelStoreOwner(): ViewModelStoreOwner

getParentId()

Retorna o id da View pai que encapsula todo o conteúdo renderizado:

fun getParentId(): Int

ActivityRootView

A classe ActivityRootView guarda a referência da Activity da qual um método loadView é chamado.

class ActivityRootView(
    val activity: AppCompatActivity,
    private val parentId: Int
) : RootView {

    override fun getContext(): Context = activity

    override fun getLifecycleOwner(): LifecycleOwner = activity

    override fun getViewModelStoreOwner(): ViewModelStoreOwner = activity

    override fun getParentId(): Int = parentId
}
AtributoTipoObrigatórioDefinição
activityAppCompatActivityRecebe a instância de uma activity
parentIdIntId view pai.

FragmentRootView

A classe FragmentRootView é responsável por guardar a referência do Fragment do qual um metodo loadView é chamado.

class FragmentRootView(
    val fragment: Fragment,
    private val parentId: Int
) : RootView {

    override fun getContext(): Context = fragment.requireContext()

    override fun getLifecycleOwner(): LifecycleOwner = fragment.viewLifecycleOwner

    override fun getViewModelStoreOwner(): ViewModelStoreOwner = fragment

    override fun getParentId(): Int = parentId
}
AtributoTipoObrigatórioDefinição
fragmentFragmentRecebe a instância de um fragment
parentIdIntId view pai.

Última modificação 17/09/2021: Reviewed Android section (#773) (e4c75e98)