-
Notifications
You must be signed in to change notification settings - Fork 104
Modernize tutorials #1316
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
Modernize tutorials #1316
Conversation
c5676e6
to
549a127
Compare
1c3247f
to
8a04e34
Compare
aa77bc6
to
175ce28
Compare
```kotlin | ||
val renderings: StateFlow<Any> by lazy { | ||
val renderings: Flow<Screen> by lazy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dropped all the StateFlow
declarations because WorkflowLayout.take
only requires a Flow
, and that's what the navigation logger I add downstream produces.
samples/tutorial/tutorial-1-complete/src/main/java/workflow/tutorial/TutorialActivity.kt
Outdated
Show resolved
Hide resolved
samples/tutorial/tutorial-2-complete/src/main/java/workflow/tutorial/RootNavigationWorkflow.kt
Outdated
Show resolved
Hide resolved
samples/tutorial/tutorial-3-complete/src/main/java/workflow/tutorial/TodoEditWorkflow.kt
Outdated
Show resolved
Hide resolved
samples/tutorial/tutorial-4-complete/src/main/java/workflow/tutorial/TodoNavigationWorkflow.kt
Show resolved
Hide resolved
samples/tutorial/tutorial-4-complete/src/main/java/workflow/tutorial/WelcomeWorkflow.kt
Outdated
Show resolved
Hide resolved
43150f1
to
ee0b0d8
Compare
samples/tutorial/tutorial-4-complete/src/main/java/workflow/tutorial/TodoNavigationWorkflow.kt
Show resolved
Hide resolved
samples/tutorial/tutorial-4-complete/src/main/java/workflow/tutorial/WelcomeWorkflow.kt
Outdated
Show resolved
Hide resolved
samples/tutorial/build.gradle
Outdated
@@ -4,7 +4,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | |||
buildscript { | |||
ext { | |||
kotlin_version = '2.0.21' | |||
workflow_version = "1.12.1-beta04" | |||
workflow_version = "1.18.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Requires 1.19.0, fix and wait for that release
ee0b0d8
to
309f059
Compare
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") } } ```
At long last, the Tutorial catches up with the current release. - Big picture discussion of our navigation story (see the end of Tutorial2.md) - 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 - Hint at the existance of `ComposeWorkflow` and `Overlay` without turning this into a complete rewrite - 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)) } ``` (Although most of these are inlined as `eventHandler("…") {}` calls.) I've mainly focussed on updating what exists, not extending its coverage further. Once this is merged I'd like to follow up and do more: - Introduce `Overlay` properly - How about move `TodoEditScreen` to a `BottomSheetDialog`? - Could be too noisy, `BottomSheetDialog` is a bastard. - If that's the case create a separate sample for it. - Introduce `Compose`. - I think the way to go is add a sixth step that updates `TodoListScreen`, talk about getting rid of that `RecyclerView`. - Could point out that the existing workflows and tests are unchangedn
309f059
to
471d1d7
Compare
At long last, the Tutorial catches up with the current release.
Big picture discussion of our navigation story (see the end of Tutorial2.md)
Use
AndroidScreen
and dropViewRegistry
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
commentsHint at the existance of
ComposeWorkflow
andOverlay
without turning this into a complete rewriteMore consistent naming, code style for actions and event handlers in
Screen
renderingsonVerbPhrase
, likeonBackPressed
Thus:
(Although most of these are inlined as
eventHandler("…") {}
calls.)I've mainly focussed on updating what exists, not extending its coverage further. Once this is merged I'd like to follow up and do more:
Overlay
properlyTodoEditScreen
to aBottomSheetDialog
?BottomSheetDialog
is a bastard.Compose
.TodoListScreen
, talk about getting rid of thatRecyclerView
.