Skip to content

Commit

Permalink
Added isManuallyStarted to the registerForFlowResult API
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac-udy committed May 30, 2024
1 parent 1f20a27 commit 8748f1c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Unreleased
* Added `isManuallyStarted` to the `registerForFlowResult` API, which allows for the flow to be started manually with a call to `update` rather than performing this automatically when the flow is created.

## 2.5.0
* Added `update` to the public API for `NavigationFlow`, as this is required for some use cases where the flow needs to be updated after changes in external state which may affect the logic of the flow. This function was previously named `next`, and removed from the public API in 2.4.0.
* Moved `NavigationContext.getViewModel` and `requireViewModel` extensions to the `dev.enro.viewmodel` package.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,15 @@ public class NavigationFlow<T> internal constructor(
* generally not cause external side effects. The [onCompleted] lambda will be invoked when the flow completes and returns a
* result.
*
* [NavigationFlow.update] is triggered automatically as part of this function, you do not need to manually call update to
* begin the flow.
* If [isManuallyStarted] is false, [NavigationFlow.update] is triggered automatically as part of this function,
* and you do not need to manually call update to begin the flow. This is the default behavior.
*
* If [isManuallyStarted] is true, you will need to call [NavigationFlow.update] to trigger the initial update of the flow,
* which will then trigger the flow to continue.
*/
public fun <T> ViewModel.registerForFlowResult(
savedStateHandle: SavedStateHandle,
isManuallyStarted: Boolean = false,
flow: NavigationFlowScope.() -> T,
onCompleted: (T) -> Unit,
): PropertyDelegateProvider<ViewModel, ReadOnlyProperty<ViewModel, NavigationFlow<T>>> {
Expand Down Expand Up @@ -210,7 +214,9 @@ public fun <T> ViewModel.registerForFlowResult(
onCompleted = onCompleted,
)
navigationHandle.extras[NavigationFlow.RESULT_FLOW] = navigationFlow
navigationFlow.update()
if (!isManuallyStarted) {
navigationFlow.update()
}
ReadOnlyProperty { _, _ -> navigationFlow }
}
}

0 comments on commit 8748f1c

Please sign in to comment.