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
}
Retorna o contexto:
fun getContext(): Context
Retorna um lifecycleOwner:
fun getLifecycleOwner(): LifecycleOwner
Retorna um ViewModelStore
para activity e fragment:
fun getViewModelStoreOwner(): ViewModelStoreOwner
Retorna o id da View
pai que encapsula todo o conteúdo renderizado:
fun getParentId(): Int
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
}
Atributo | Tipo | Obrigatório | Definição |
---|---|---|---|
activity | AppCompatActivity | ✓ | Recebe a instância de uma activity |
parentId | Int | ✓ | Id view pai. |
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
}
Atributo | Tipo | Obrigatório | Definição |
---|---|---|---|
fragment | Fragment | ✓ | Recebe a instância de um fragment |
parentId | Int | ✓ | Id view pai. |
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.