Skip to content

Tutorial update #1159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README-templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# File Templates

`workflow-file-templates.zip` can be imported into Android Studio / IntelliJ IDEA to add a few Workflow-specific file templates, via _File > Manage IDE Settings > Import Settings…_.

To update the templates:

* edit them in the IDE (_Settings > Editor > File and Code Templates_)
* export them (_File > Manage IDE Settings > Import Settings…_), taking care to clear every checkbox except that for File Templates.
87 changes: 0 additions & 87 deletions fileTemplates/Stateful Workflow.kt

This file was deleted.

61 changes: 0 additions & 61 deletions fileTemplates/Stateless Workflow.kt

This file was deleted.

27 changes: 0 additions & 27 deletions install-templates.sh

This file was deleted.

24 changes: 2 additions & 22 deletions samples/tutorial/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
# Tutorial

## Stale Docs Warning

**This tutorial is tied to an older version of Workflow, and relies on API that has been deprecated or deleted.**
The general concepts are the same, and refactoring to the current API is straightforward,
so it is still worthwhile to work through the tutorial in its current state until we find time to update it.
(Track that work [here](https://github.com/square/workflow-kotlin/issues/905)
and [here](https://github.com/square/workflow-kotlin/issues/884).)

Here's a summary of what has changed, and what replaces what:

- Use of `ViewRegistry` is now optional, and rare.
Have your renderings implement `AndroidScreen` or `ComposeScreen` to avoid it.
- The API for binding a rendering to UI code has changed as follows, and can all
be avoided if you use `ComposeScreen`:
- `ViewFactory<in RenderingT : Any>` is replaced by `ScreenViewFactory<in ScreenT : Screen>`.
-`LayoutRunner<RenderingT : Any>` is replaced by `ScreenViewRunner<in ScreenT : Screen>`.
- `LayoutRunner.bind` is replaced by `ScreenViewFactory.fromViewBinding`.
- `BackStackScreen` has been moved to package `com.squareup.workflow1.ui.navigation`.
- `EditText.updateText` and `EditText.setTextChangedListener` are replaced by `TextController`

## Overview

Oh hi! Looks like you want build some software with Workflows! It's a bit different from traditional
Android development, so let's go through building a simple little TODO app to get the basics down.
Android development, so let's go through building a simple little To-Do app to get the basics down.

## Layout

Expand All @@ -33,7 +13,7 @@ To help with the setup, we have created a few helper modules:

- `tutorial-views`: A set of 3 views for the 3 screens we will be building, `Welcome`, `TodoList`,
and `TodoEdit`.
- `tutorial-base`: This is the starting point to build out the tutorial. It contains layouts that host the views from `TutorialViews` to see how they display.
- `tutorial-base`: This is the starting point to build out the tutorial.
- `tutorial-final`: This is an example of the completed tutorial - could be used as a reference if
you get stuck.

Expand Down
22 changes: 0 additions & 22 deletions samples/tutorial/Tutorial1.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@

_Let's get something on the screen..._

## Stale Docs Warning

**This tutorial is tied to an older version of Workflow, and relies on API that has been deprecated or deleted.**
The general concepts are the same, and refactoring to the current API is straightforward,
so it is still worthwhile to work through the tutorial in its current state until we find time to update it.
(Track that work [here](https://github.com/square/workflow-kotlin/issues/905)
and [here](https://github.com/square/workflow-kotlin/issues/884).)

Here's a summary of what has changed, and what replaces what:

- Use of `ViewRegistry` is now optional, and rare.
Have your renderings implement `AndroidScreen` or `ComposeScreen` to avoid it.
- The API for binding a rendering to UI code has changed as follows, and can all
be avoided if you use `ComposeScreen`:
- `ViewFactory<in RenderingT : Any>` is replaced by `ScreenViewFactory<in ScreenT : Screen>`.
-`LayoutRunner<RenderingT : Any>` is replaced by `ScreenViewRunner<in ScreenT : Screen>`.
- `LayoutRunner.bind` is replaced by `ScreenViewFactory.fromViewBinding`.
- `BackStackScreen` has been moved to package `com.squareup.workflow1.ui.navigation`.
- `EditText.updateText` and `EditText.setTextChangedListener` are replaced by `TextController`

## Setup

To follow this tutorial, launch Android Studio and open this folder (`samples/tutorial`).
Expand Down Expand Up @@ -81,7 +61,6 @@ Use the `Layout Runner (ViewBinding)` template to create a second file.
![Layout Runner Name](images/layout-runner-name.png)

```kotlin
@OptIn(WorkflowUiExperimentalApi::class)
class WelcomeLayoutRunner(
private val binding: WelcomeViewBinding
) : LayoutRunner<WelcomeScreen> {
Expand Down Expand Up @@ -120,7 +99,6 @@ 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!

```kotlin
@OptIn(WorkflowUiExperimentalApi::class)
class WelcomeLayoutRunner(
private val welcomeBinding: WelcomeViewBinding
) : LayoutRunner<WelcomeScreen> {
Expand Down
37 changes: 3 additions & 34 deletions samples/tutorial/Tutorial2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@

_Multiple Screens and Navigation_

## Stale Docs Warning

**This tutorial is tied to an older version of Workflow, and relies on API that has been deprecated or deleted.**
The general concepts are the same, and refactoring to the current API is straightforward,
so it is still worthwhile to work through the tutorial in its current state until we find time to update it.
(Track that work [here](https://github.com/square/workflow-kotlin/issues/905)
and [here](https://github.com/square/workflow-kotlin/issues/884).)

Here's a summary of what has changed, and what replaces what:

- Use of `ViewRegistry` is now optional, and rare.
Have your renderings implement `AndroidScreen` or `ComposeScreen` to avoid it.
- The API for binding a rendering to UI code has changed as follows, and can all
be avoided if you use `ComposeScreen`:
- `ViewFactory<in RenderingT : Any>` is replaced by `ScreenViewFactory<in ScreenT : Screen>`.
-`LayoutRunner<RenderingT : Any>` is replaced by `ScreenViewRunner<in ScreenT : Screen>`.
- `LayoutRunner.bind` is replaced by `ScreenViewFactory.fromViewBinding`.
- `BackStackScreen` has been moved to package `com.squareup.workflow1.ui.navigation`.
- `EditText.updateText` and `EditText.setTextChangedListener` are replaced by `TextController`

## Setup

To follow this tutorial, launch Android Studio and open this folder (`samples/tutorial`).
Expand Down Expand Up @@ -539,29 +519,18 @@ class BackStackScreen<StackedT : Any>(
}
```

The `BackStackScreen` contains a list of all screens in the back stack that are specified on each render pass. `BackStackScreen` is part of the `workflow-ui-container-android` artifact. Update `build.gradle` to include this dependency:

```groovy
dependencies {
// ...
implementation deps.workflow.container_android
implementation deps.workflow.core_android
}
```

Update the `RootWorkflow` to return a `BackStackScreen` with a list of back stack items:

```kotlin
object RootWorkflow : StatefulWorkflow<Unit, State, Nothing, BackStackScreen<Any>>() {
object RootWorkflow : StatefulWorkflow<Unit, State, Nothing, BackStackScreen<*>>() {

// …

@OptIn(WorkflowUiExperimentalApi::class)
override fun render(
override fun render(
renderProps: Unit,
renderState: State,
context: RenderContext
): BackStackScreen<Any> {
): BackStackScreen<*> {

// Our list of back stack items. Will always include the "WelcomeScreen".
val backstackScreens = mutableListOf<Any>()
Expand Down
24 changes: 3 additions & 21 deletions samples/tutorial/Tutorial3.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
# Step 3

## Stale Docs Warning

**This tutorial is tied to an older version of Workflow, and relies on API that has been deprecated or deleted.**
The general concepts are the same, and refactoring to the current API is straightforward,
so it is still worthwhile to work through the tutorial in its current state until we find time to update it.
(Track that work [here](https://github.com/square/workflow-kotlin/issues/905)
and [here](https://github.com/square/workflow-kotlin/issues/884).)

Here's a summary of what has changed, and what replaces what:

- Use of `ViewRegistry` is now optional, and rare.
Have your renderings implement `AndroidScreen` or `ComposeScreen` to avoid it.
- The API for binding a rendering to UI code has changed as follows, and can all
be avoided if you use `ComposeScreen`:
- `ViewFactory<in RenderingT : Any>` is replaced by `ScreenViewFactory<in ScreenT : Screen>`.
-`LayoutRunner<RenderingT : Any>` is replaced by `ScreenViewRunner<in ScreenT : Screen>`.
- `LayoutRunner.bind` is replaced by `ScreenViewFactory.fromViewBinding`.
- `BackStackScreen` has been moved to package `com.squareup.workflow1.ui.navigation`.
- `EditText.updateText` and `EditText.setTextChangedListener` are replaced by `TextController`
_State throughout a tree of workflows_

## Setup

Expand Down Expand Up @@ -284,15 +266,15 @@ object TodoListWorkflow : StatefulWorkflow<ListProps, State, Back, List<Any>>()
Now that `TodoListWorkflow` renders a `List<Any>` we need to update its parent `RootWorkflow` to accept this list:

```kotlin
object RootWorkflow : StatefulWorkflow<Unit, State, Nothing, BackStackScreen<Any>>() {
object RootWorkflow : StatefulWorkflow<Unit, State, Nothing, BackStackScreen<*>>() {

// ...

override fun render(
renderProps: Unit,
renderState: State,
context: RenderContext
): BackStackScreen<Any> {
): BackStackScreen<*> {
// ..
// When the state is Todo, defer to the TodoListWorkflow.
is Todo -> {
Expand Down
Loading
Loading