Skip to content

Commit 352c13f

Browse files
authored
Merge pull request #869 from 6879756e/main
Update Tutorial1.md
2 parents 94c0b4b + 9410806 commit 352c13f

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

samples/tutorial/Tutorial1.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ data class WelcomeScreen(
9191
)
9292
```
9393

94-
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
95-
`. However if you would like to create and lay out the view yourself instead, feel free to do so!
94+
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!
9695

9796
```kotlin
97+
@OptIn(WorkflowUiExperimentalApi::class)
9898
class WelcomeLayoutRunner(
9999
private val welcomeBinding: WelcomeViewBinding
100100
) : LayoutRunner<WelcomeScreen> {
@@ -168,6 +168,10 @@ dependencies {
168168
We'll update the `TutorialActivity` to set its content using a `ViewRegistry` that points to our `LayoutRunner`'s `ViewFactory`:
169169

170170
```kotlin
171+
@file:OptIn(WorkflowUiExperimentalApi::class)
172+
package workflow.tutorial
173+
// ...
174+
171175
// This doesn't look like much right now, but we'll add more layout runners shortly.
172176
private val viewRegistry = ViewRegistry(WelcomeLayoutRunner)
173177

@@ -189,9 +193,9 @@ class TutorialActivity : AppCompatActivity() {
189193
class TutorialViewModel(savedState: SavedStateHandle) : ViewModel() {
190194
val renderings: StateFlow<WelcomeScreen> by lazy {
191195
renderWorkflowIn(
192-
workflow = WelcomeWorkflow,
193-
scope = viewModelScope,
194-
savedStateHandle = savedState
196+
workflow = WelcomeWorkflow,
197+
scope = viewModelScope,
198+
savedStateHandle = savedState
195199
)
196200
}
197201
}
29.6 KB
Loading
30.4 KB
Loading

0 commit comments

Comments
 (0)