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

Tutorial update #1159

wants to merge 2 commits into from

Conversation

rjrjr
Copy link
Contributor

@rjrjr rjrjr commented Jan 20, 2024

Long lived branch that is collecting commits that bring the tutorial up to date with undeprecated workflow UI API. Expect rebases. So far the source code in samples/tutorial/tutorial-final is in the proper form. No prose has been updated yet.

@rjrjr rjrjr force-pushed the ray/tutorial-update branch 5 times, most recently from a27b010 to ae5bece Compare May 13, 2025 16:23
Our templates were out of date, and our `install.sh` script doesn't work any more.
Replaced with an IDE-produced zip file that the IDE is willing to import.

Replaces `Layout Runner (ViewBinding)` with `Android Screen (ViewBinding)`:

```kotlin
package ${PACKAGE_NAME}

import com.squareup.workflow1.ui.AndroidScreen
import com.squareup.workflow1.ui.ScreenViewFactory
import com.squareup.workflow1.ui.ScreenViewRunner
import com.squareup.workflow1.ui.ViewEnvironment
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi

@OptIn(WorkflowUiExperimentalApi::class)
data class $Name(
  // TODO: add properties needed to update $VIEW_BINDING_TYPE
) : AndroidScreen<$Name> {

  override val viewFactory =
    ScreenViewFactory.fromViewBinding($VIEW_BINDING_TYPE::inflate, ::${Name}Runner)
}

@OptIn(WorkflowUiExperimentalApi::class)
private class ${Name}Runner(
  private val viewBinding: $VIEW_BINDING_TYPE
) : ScreenViewRunner<$Name> {

  override fun showRendering(
    rendering: $Name,
    environment: ViewEnvironment
  ) {
    TODO("Update viewBinding from rendering")
  }
}
```
@rjrjr rjrjr force-pushed the ray/tutorial-update branch 2 times, most recently from 53448df to 1f97aae Compare May 13, 2025 23:06
It's time to get the Tutorial caught up with undeprecated API. This PR modifies only the final tutorial module. Once we're happy with the code, I'll back port the changes and update the prose in follow ups.

- Use `AndroidScreen` and drop `ViewRegistry`
- Better, more consistent use of `BackStackScreen`
- Use `View.setBackHandler`
- Use `TextController`
- Use `RequestContext.eventHandler`
- Delete a lot of `// Exactly what the function name and the code say` comments
- More consistent naming, code style for actions and event handlers in `Screen` renderings
  - Event handler fields are named `onVerbPhrase`, like `onBackPressed`
  - Action names are verb phrases describing the action that is being taken, not the event that is being handled
  - Output names are generally in terms of the semantic event being reported to the parent, rather than describing what the parent will do

Thus:

```kotlin
return TodoListScreen(
  onRowPressed = { context.actionSink.send(reportSelection(it)) }
```

```kotlin
  private fun reportSelection(index: Int) = action {
    // Tell our parent that a todo item was selected.
    setOutput(TodoSelected(index))
  }
```

To Do:

- Introduce `Overlay`. How about move `TodoEditScreen` to a `BottomSheet`?
- Introduce `Compose`.
  - I think the way to go is add a fifth step that updates `TodoListScreen`, talk about getting rid of that `RecyclerView`.
  - Should also mention at the top that people can use `ComposeScreen` instead of `AndroidScreen`;
    and on the `TextController` page call out `asMutableState()`
@rjrjr rjrjr force-pushed the ray/tutorial-update branch from 1f97aae to 9b2b7ac Compare May 13, 2025 23:09
@rjrjr rjrjr closed this May 13, 2025
@rjrjr
Copy link
Contributor Author

rjrjr commented May 13, 2025

The branch is still there and I'm working on it actively (again, finally) but it's wasteful to keep this PR open and kick off CI runs that won't pass and won't be looked at.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant