You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's start with what a "screen" is, and how it relates to views.
31
79
32
80
"Screen" is just the term we use to refer to a value type that represents the view model for a logical screen. Sometimes we'll even use the terms "screen" and "view model" interchangeably. It has no special type. Typically, a screen will be used as the rendering type for the workflow that is responsible for that screen. A screen is usually a data class, since that's the easiest way to make value type-like classes in Kotlin.
33
81
34
-
For our welcome screen, we'll define what it needs for a backing view model:
82
+
For our welcome screen, we'll create a new class and define what it needs for a backing view model:
35
83
```kotlin
36
84
data classWelcomeScreen(
37
85
/** The current name that has been entered. */
@@ -43,7 +91,8 @@ data class WelcomeScreen(
43
91
)
44
92
```
45
93
46
-
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. 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
95
+
`. However if you would like to create and lay out the view yourself instead, feel free to do so!
@@ -141,7 +188,7 @@ Right now, the workflow isn't handling any of the events from the UI. Let's upda
141
188
142
189
All workflows have a `State` type that represents the internal state of the workflow. This should be all of the data for which *this* workflow is _responsible_. It usually corresponds to the state for the UI.
143
190
144
-
Let's model the first part of state that we want to track: the login `username`. Update the `State`type to include a username property. We will also need to update `initialState` to give an initial value:
191
+
Let's model the first part of state that we want to track: the login `username`. Update the `State`to a `data class` and include a username property. We will also need to update `initialState` to give an initial value:
Copy file name to clipboardExpand all lines: samples/tutorial/Tutorial2.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -304,7 +304,7 @@ Workflows can only communicate with each other through their "properties" as inp
304
304
305
305
Our welcome workflow has a login button that doesn't do anything, and we'll now handle it and let our parent know that we've "logged in" so it can navigate to another screen.
306
306
307
-
Add an action for `onLogin` and define our `OutputT` type as a new `data class LoggedIn` to be able to message our parent:
307
+
Add an action for `onLogin` and change our `OutputT` type from `Output` to a new `data class LoggedIn` to be able to message our parent:
0 commit comments