RootView

In this section, you will find information about Interface RootView holder the reference of activity or fragment.

RootView

The RootView interface holds the reference of an activity or fragment. Through the interface methods, you have a reference to context, life cycle, ViewModelStore and parent view Id.

RootView is available as an attribute in the ViewConvertable and Action interfaces:

interface RootView {
    
    fun getContext(): Context

    fun getLifecycleOwner(): LifecycleOwner

    fun getViewModelStoreOwner(): ViewModelStoreOwner

    fun getParentId(): Int
}

getContext()

Returns the context:

fun getContext(): Context

getLifecycleOwner()

Returns the lifecycle:

fun getLifecycleOwner(): LifecycleOwner

getViewModelStoreOwner()

Returns a ViewModelStore for activity and fragment:

fun getViewModelStoreOwner(): ViewModelStoreOwner

getParentId()

Returns the id of the parent View that encapsulates all rendered content:

fun getParentId(): Int

ActivityRootView

The ActivityRootView class is responsible for keeping the Activity reference of which a loadView method is called:

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
}
AttributesTypeRequiredDescription
activityAppCompatActivityReceives the instance of an activity.
parentIdIntView id.

FragmentRootView

The FragmentRootView class is responsible for keeping the Fragment reference of which a loadView method is called:

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
}
AttributesTypeRequiredDescription
fragmentFragmentReceives the instance of an fragment.
parentIdIntView id.

Last modified September 20, 2021: Review android 1.10 (#776) (1a04515a)