Skip to content

Update code snippets in the tutorials #1362

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion samples/tutorial/Tutorial1.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class TutorialActivity : AppCompatActivity() {
@OptIn(WorkflowExperimentalRuntime::class)
val renderings: Flow<Screen> by lazy {
renderWorkflowIn(
workflow = RootNavigationWorkflow,
workflow = WelcomeWorkflow,
scope = viewModelScope,
savedStateHandle = savedState,
runtimeConfig = RuntimeConfigOptions.ALL
Expand Down
9 changes: 5 additions & 4 deletions samples/tutorial/Tutorial2.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ At the same time, add a `reportNavigation()` call when creating the `renderings`
scope = viewModelScope,
savedStateHandle = savedState
)
}.reportNavigation()
}.reportNavigation {
Log.i("navigate", it.toString())
}
```

Now when you run the app we'll see the welcome screen again.
Expand Down Expand Up @@ -587,8 +589,7 @@ So far it has output `Nothing`.
Define a `BackPressed` object and use it as `TodoListWorkflow`'s output type.
Update `render()` to create an `eventHandler` function to post the new output event.

At the same time, update TodoListScreen with an `onBack` event handler,
and use workflow's handy `View.setBackHandler` function to respond to Android back press events.
At the same time, use workflow's handy `View.setBackHandler` function to respond to Android back press events.

> [!NOTE] `View.setBackHandler` is implemented via
> [OnBackPressedCallback](https://developer.android.com/reference/androidx/activity/OnBackPressedCallback)
Expand All @@ -614,7 +615,7 @@ object TodoListWorkflow : StatefulWorkflow<ListProps, State, BackPressed, TodoLi
return TodoListScreen(
username = renderProps.username,
todoTitles = titles,
onBackPressed = { context.actionSink.send(onBack()) }
onBackPressed = context.eventHandler("onBackPressed") { setOutput(BackPressed) }
)
}
```
Expand Down
2 changes: 1 addition & 1 deletion samples/tutorial/Tutorial3.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ object TodoListWorkflow : StatefulWorkflow<ListProps, State, BackPressed, List<S
TodoListScreen(
username = renderProps.username,
todoTitles = titles,
onBackPressed = { context.actionSink.send(onBack()) }
onBackPressed = context.eventHandler("onBackPressed") { setOutput(BackPressed) }
)
)
}
Expand Down
5 changes: 2 additions & 3 deletions samples/tutorial/Tutorial4.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ object TodoListWorkflow : StatefulWorkflow<ListProps, State, Output, TodoListScr
onRowPressed = context.eventHandler("onRowPressed") { index ->
// Tell our parent that a todo item was selected.
setOutput(TodoSelected(index))
},
onBackPressed = { context.actionSink.send(reportBackPress) },
}
)
}
}
Expand Down Expand Up @@ -227,7 +226,7 @@ object TodoNavigationWorkflow : StatefulWorkflow<TodoProps, State, Back, List<Sc
return listOf(todoListScreen)
}

private fun requestExit() = action("requestExit") {
private fun goBack() = action("requestExit") {
setOutput(Back)
}

Expand Down