-
Notifications
You must be signed in to change notification settings - Fork 112
Remove Compose Dependency from Android Runtime #1379
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 4 additions & 37 deletions
41
workflow-runtime-android/dependencies/releaseRuntimeClasspath.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,23 +3,20 @@ | |
| package com.squareup.workflow1.android | ||
|
|
||
| import androidx.annotation.VisibleForTesting | ||
| import androidx.compose.ui.platform.AndroidUiDispatcher | ||
| import androidx.lifecycle.SavedStateHandle | ||
| import com.squareup.workflow1.RuntimeConfig | ||
| import com.squareup.workflow1.RuntimeConfigOptions | ||
| import com.squareup.workflow1.Workflow | ||
| import com.squareup.workflow1.WorkflowInterceptor | ||
| import com.squareup.workflow1.WorkflowTracer | ||
| import com.squareup.workflow1.renderWorkflowIn | ||
| import kotlinx.coroutines.CoroutineDispatcher | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.SharingStarted.Companion.Eagerly | ||
| import kotlinx.coroutines.flow.StateFlow | ||
| import kotlinx.coroutines.flow.map | ||
| import kotlinx.coroutines.flow.onEach | ||
| import kotlinx.coroutines.flow.stateIn | ||
| import kotlinx.coroutines.plus | ||
|
|
||
| /** | ||
| * An Android `ViewModel`-friendly wrapper for [com.squareup.workflow1.renderWorkflowIn], | ||
|
|
@@ -58,10 +55,12 @@ import kotlinx.coroutines.plus | |
| * in any workflows, after the initial render pass, will be handled by this scope, and cancelling | ||
| * this scope will cancel the workflow runtime and any running workers. Note that any dispatcher | ||
| * in this scope will _not_ be used to execute the very first render pass (which happens | ||
| * synchronously). | ||
| * Also note that if there is no [CoroutineDispatcher] in this scope then Compose UI's | ||
| * [AndroidUiDispatcher.Main] will be used as this is the most performant Android UI dispatcher | ||
| * for Workflow. | ||
| * synchronously). We recommend using a `CoroutineDispatcher` in this scope's `CoroutineContext` | ||
| * that will ensure that all dispatched coroutines are run before the next Choreographer frame. | ||
| * Compose UI's `AndroidUiDispatcher.Main` provides this behavior in a performant way! | ||
| * Another way to achieve that is to use an immediate (or Unconfined) dispatcher like | ||
| * Dispatchers.Main.immediate. However, that dispatcher cannot take advantage of some runtime | ||
| * optimizations. E.G., see [RuntimeConfigOptions.DRAIN_EXCLUSIVE_ACTIONS]. | ||
| * | ||
| * @param savedStateHandle | ||
| * Used to restore workflow state in a new process. Typically this is the | ||
|
|
@@ -141,10 +140,12 @@ public fun <OutputT, RenderingT> renderWorkflowIn( | |
| * in any workflows, after the initial render pass, will be handled by this scope, and cancelling | ||
| * this scope will cancel the workflow runtime and any running workers. Note that any dispatcher | ||
| * in this scope will _not_ be used to execute the very first render pass (which happens | ||
| * synchronously). | ||
| * Also note that if there is no [CoroutineDispatcher] in this scope then Compose UI's | ||
| * [AndroidUiDispatcher.Main] will be used as this is the most performant Android UI dispatcher | ||
| * for Workflow. | ||
| * synchronously). We recommend using a `CoroutineDispatcher` in this scope's `CoroutineContext` | ||
| * that will ensure that all dispatched coroutines are run before the next Choreographer frame. | ||
| * Compose UI's `AndroidUiDispatcher.Main` provides this behavior in a performant way! | ||
| * Another way to achieve that is to use an immediate (or Unconfined) dispatcher like | ||
| * Dispatchers.Main.immediate. However, that dispatcher cannot take advantage of some runtime | ||
| * optimizations. E.G., see [RuntimeConfigOptions.DRAIN_EXCLUSIVE_ACTIONS]. | ||
| * | ||
| * @param prop | ||
| * Specifies the sole [PropsT] value to use to render the root workflow. To allow updates, | ||
|
|
@@ -243,10 +244,12 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn( | |
| * in any workflows, after the initial render pass, will be handled by this scope, and cancelling | ||
| * this scope will cancel the workflow runtime and any running workers. Note that any dispatcher | ||
| * in this scope will _not_ be used to execute the very first render pass (which happens | ||
| * synchronously). | ||
| * Also note that if there is no [CoroutineDispatcher] in this scope then Compose UI's | ||
| * [AndroidUiDispatcher.Main] will be used as this is the most performant Android UI dispatcher | ||
| * for Workflow. | ||
| * synchronously). We recommend using a `CoroutineDispatcher` in this scope's `CoroutineContext` | ||
| * that will ensure that all dispatched coroutines are run before the next Choreographer frame. | ||
| * Compose UI's `AndroidUiDispatcher.Main` provides this behavior in a performant way! | ||
| * Another way to achieve that is to use an immediate (or Unconfined) dispatcher like | ||
| * Dispatchers.Main.immediate. However, that dispatcher cannot take advantage of some runtime | ||
| * optimizations. E.G., see [RuntimeConfigOptions.DRAIN_EXCLUSIVE_ACTIONS]. | ||
| * | ||
| * @param props | ||
| * Specifies the initial [PropsT] to use to render the root workflow, and will cause a re-render | ||
|
|
@@ -278,7 +281,6 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn( | |
| * A [StateFlow] of [RenderingT]s that will emit any time the root workflow creates a new | ||
| * rendering. | ||
| */ | ||
| @OptIn(ExperimentalStdlibApi::class) | ||
| public fun <PropsT, OutputT, RenderingT> renderWorkflowIn( | ||
| workflow: Workflow<PropsT, OutputT, RenderingT>, | ||
| scope: CoroutineScope, | ||
|
|
@@ -291,16 +293,9 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn( | |
| ): StateFlow<RenderingT> { | ||
| val restoredSnap = savedStateHandle?.get<PickledTreesnapshot>(KEY)?.snapshot | ||
|
|
||
| // Add in Compose's AndroidUiDispatcher.Main by default if none is specified. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be too magical to use reflection to look for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think probably? |
||
| val updatedContext = if (scope.coroutineContext[CoroutineDispatcher.Key] == null) { | ||
| scope.coroutineContext + AndroidUiDispatcher.Main | ||
| } else { | ||
| scope.coroutineContext | ||
| } | ||
|
|
||
| val renderingsAndSnapshots = renderWorkflowIn( | ||
| workflow, | ||
| scope + updatedContext, | ||
| scope, | ||
| props, | ||
| restoredSnap, | ||
| interceptors, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 2 additions & 30 deletions
32
workflow-ui/core-android/dependencies/releaseRuntimeClasspath.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should update all the compose samples to demonstrate.
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.
Workflow.renderAsStateto sidestep thinking about this. Too much?renderAsStateto allow a config to be passed in?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.
That's a good point about the samples!
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 don't think so!
Uh oh!
There was an error while loading. Please reload this page.
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.
Turns out we did. It takes the scope by default from
rememberCoroutineScope()which will take it from Compose which will likely beAndroidUiDispatcher.Mainon Android.