AdaptiveFragmentHelper

constructor(fragment: Fragment, viewVariantSelector: (widthDp: Int, heightDp: Int) -> T, viewFactoryProvider: (T) -> IviFragment.ViewFactory<*>)

Parameters

T

The enum type of view variant.

fragment

The adaptive fragment.

viewVariantSelector

Called when the fragment's root view updates its size in order to determine which view variant to use. If the returned value differs from the previous one the fragment will be reattached in order to recreate the view. In case the value to which the size is compared is stored in the dimen xml, one can use the Context.getDimensionByAttrInDp function. If a view or any of its parents has the layout param WRAP_CONTENT, the size can vary after the view variant is chosen, causing a new view variant to be selected, which may end up in an endless loop. To prevent this from happening, such a view will report the stable value 0 in the WRAP_CONTENT dimension.

viewFactoryProvider

Called when the size of the fragment's root view changes and a different view variant is returned by viewVariantSelector. This function should return the new value for viewFactory, which can be returned from IviFragment.viewFactory to apply the new view variant when the fragment recreates its view.