diff --git a/samples/tutorial/Tutorial1.md b/samples/tutorial/Tutorial1.md index 24f98c1f1a..2d3690e9a5 100644 --- a/samples/tutorial/Tutorial1.md +++ b/samples/tutorial/Tutorial1.md @@ -91,10 +91,10 @@ data class WelcomeScreen( ) ``` -Then we need to create a `ViewFactory` that knows how to create an Android `View` to draw the actual screen. The easiest way to create a `ViewFactory` is to create a layout runner. A layout runner is a class that has a reference to the view and knows how to update the view given an instance of a screen. In a typical app, every screen will have a layout runner. Layout runners can also work with AndroidX `ViewBinding`s, which we'll use to define the `WelcomeLayoutRunner`. We have a pre-built `WelcomeViewBinding` that you can use. This binding will be autogenerated from layout files in `tutorials-views` when you first build the app. If Android Studio does not automatically find the file, you can manually import it `import workflow.tutorial.views.databinding.WelcomeViewBinding -`. However if you would like to create and lay out the view yourself instead, feel free to do so! +Then we need to create a `ViewFactory` that knows how to create an Android `View` to draw the actual screen. The easiest way to create a `ViewFactory` is to create a layout runner. A layout runner is a class that has a reference to the view and knows how to update the view given an instance of a screen. In a typical app, every screen will have a layout runner. Layout runners can also work with AndroidX `ViewBinding`s, which we'll use to define the `WelcomeLayoutRunner`. We have a pre-built `WelcomeViewBinding` that you can use. This binding will be autogenerated from layout files in `tutorials-views` when you first build the app. If Android Studio does not automatically find the file, you can manually import it `import workflow.tutorial.views.databinding.WelcomeViewBinding`. However if you would like to create and lay out the view yourself instead, feel free to do so! ```kotlin +@OptIn(WorkflowUiExperimentalApi::class) class WelcomeLayoutRunner( private val welcomeBinding: WelcomeViewBinding ) : LayoutRunner { @@ -168,6 +168,10 @@ dependencies { We'll update the `TutorialActivity` to set its content using a `ViewRegistry` that points to our `LayoutRunner`'s `ViewFactory`: ```kotlin +@file:OptIn(WorkflowUiExperimentalApi::class) +package workflow.tutorial +// ... + // This doesn't look like much right now, but we'll add more layout runners shortly. private val viewRegistry = ViewRegistry(WelcomeLayoutRunner) @@ -189,9 +193,9 @@ class TutorialActivity : AppCompatActivity() { class TutorialViewModel(savedState: SavedStateHandle) : ViewModel() { val renderings: StateFlow by lazy { renderWorkflowIn( - workflow = WelcomeWorkflow, - scope = viewModelScope, - savedStateHandle = savedState + workflow = WelcomeWorkflow, + scope = viewModelScope, + savedStateHandle = savedState ) } } diff --git a/samples/tutorial/images/layout-runner-name.png b/samples/tutorial/images/layout-runner-name.png index af9730b67b..e804e8a7ff 100644 Binary files a/samples/tutorial/images/layout-runner-name.png and b/samples/tutorial/images/layout-runner-name.png differ diff --git a/samples/tutorial/images/workflow-name.png b/samples/tutorial/images/workflow-name.png index c2d0c004b4..7d9a02a69f 100644 Binary files a/samples/tutorial/images/workflow-name.png and b/samples/tutorial/images/workflow-name.png differ