//workflow/com.squareup.workflow1.ui/toUnwrappingViewFactory
toUnwrappingViewFactory¶
[androidJvm]
Content
@WorkflowUiExperimentalApi()
inline fun <WrapperT : Screen, WrappedT : Screen> ScreenViewFactory<WrappedT>.toUnwrappingViewFactory(crossinline unwrap: (WrapperT) -> WrappedT): ScreenViewFactory<WrapperT>
More info
Transforms a ScreenViewFactory of WrappedT into one that can handle instances of WrapperT. Allows WrapperT to wrap instances of WrappedT to add information or behavior, without requiring wasteful wrapping in the view system.
One general note: when creating a wrapper rendering, you’re very likely to want it to implement Compatible, to ensure that checks made to update or replace a view are based on the wrapped item. Each wrapper example below illustrates this.
This a simpler variant of the like named function that takes two arguments, for use when there is no need to customize the view or the environment.
Examples¶
To make one rendering type an “alias” for another – that is, to use the same ScreenViewFactory to display it:
1 2 3 4 5 6 7 8 9 |
|
To make one rendering type a wrapper for others:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
To make a wrapper that adds information to the ViewEnvironment:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
Parameters¶
androidJvm
unwrap | a function to extract WrappedT instances from WrapperTs. |
[androidJvm]
Content
@WorkflowUiExperimentalApi()
inline fun <WrapperT : Screen, WrappedT : Screen> ScreenViewFactory<WrappedT>.toUnwrappingViewFactory(crossinline unwrap: (WrapperT) -> WrappedT, crossinline showWrapperScreen: (view: View, WrapperT, environment: ViewEnvironment, showUnwrappedScreen: (WrappedT, ViewEnvironment) -> Unit) -> Unit): ScreenViewFactory<WrapperT>
More info
Transforms a ScreenViewFactory of WrappedT into one that can handle instances of WrapperT.
One general note: when creating a wrapper rendering, you’re very likely to want it to implement Compatible, to ensure that checks made to update or replace a view are based on the wrapped item. Each wrapper example below illustrates this.
Also see the simpler variant of this function that takes only an unwrap argument.
Example¶
To make a wrapper that customizes View initialization:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Parameters¶
androidJvm
unwrap | a function to extract WrappedT instances from WrapperTs. |
showWrapperScreen | a function invoked when an instance of WrapperT needs to be shown in a View built to display instances of WrappedT. Allows pre- and post-processing of the View. |