Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession
* particular events.
*
* If you want to trace how long Workflow takes to process a UI event, then
* annotate the [RenderContext.eventHandler] name argument with [keyForTrace]. That will cause
* annotate the `RenderContext.eventHandler` name argument with [keyForTrace]. That will cause
* this interceptor to pick it up when the action is sent into the sink and trace that main thread
* message.
*
* If you want to trace how long Workflow takes to process the result of a [Worker], then
* annotate the [Worker] using [TraceableWorker] which will set it up with a key such that when
* If you want to trace how long Workflow takes to process the result of a `Worker`, then
* annotate the `Worker` using [TraceableWorker] which will set it up with a key such that when
* the action for the result is sent to the sink the main thread message will be traced.
*/
class ActionHandlingTracingInterceptor : WorkflowInterceptor, Resettable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package com.squareup.sample.compose.inlinerendering

import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.SizeTransform
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
Expand Down Expand Up @@ -38,12 +37,15 @@ object InlineRenderingWorkflow : StatefulWorkflow<Unit, Int, Nothing, Screen>()
renderProps: Unit,
renderState: Int,
context: RenderContext
) = ComposeScreen {
Box {
Button(onClick = context.eventHandler("increment") { state += 1 }) {
Text("Counter: ")
AnimatedCounter(renderState) { counterValue ->
Text(counterValue.toString())
): ComposeScreen {
val onClick = context.eventHandler("increment") { state += 1 }
return ComposeScreen {
Box {
Button(onClick = onClick) {
Text("Counter: ")
AnimatedCounter(renderState) { counterValue ->
Text(counterValue.toString())
}
}
}
}
Expand All @@ -68,7 +70,6 @@ internal fun InlineRenderingWorkflowPreview() {
InlineRenderingWorkflowRendering()
}

@OptIn(ExperimentalAnimationApi::class)
@Composable
private fun AnimatedCounter(
counterValue: Int,
Expand All @@ -79,6 +80,7 @@ private fun AnimatedCounter(
transitionSpec = {
((slideInVertically() + fadeIn()).togetherWith(slideOutVertically() + fadeOut()))
.using(SizeTransform(clip = false))
}
},
label = ""
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this fixed a compiler warning? Will check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, seems to serve no purpose, will revert.

) { content(it) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object StanzaListWorkflow : StatelessWorkflow<Props, SelectedStanza, StanzaListS

data class Props(
val poem: Poem,
val eventHandlerTag: (String) -> String = { "" }
val eventHandlerTag: (String) -> String = { it }
)

const val NO_SELECTED_STANZA = -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object StanzaWorkflow : StatelessWorkflow<Props, Output, StanzaScreen>() {
data class Props(
val poem: Poem,
val index: Int,
val eventHandlerTag: (String) -> String = { "" }
val eventHandlerTag: (String) -> String = { it }
)

enum class Output {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class TimeMachineWorkflowTest {
val delegateWorkflow = Workflow.stateful<String, Nothing, DelegateRendering>(
initialState = "initial",
render = { renderState ->
DelegateRendering(renderState, setState = eventHandler("") { s -> state = s })
DelegateRendering(
renderState,
setState = eventHandler("setState") { s -> state = s }
)
}
)
val clock = TestTimeSource()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object NestedOverlaysWorkflow : StatefulWorkflow<Unit, State, Nothing, Screen>()
name = R.string.close,
onClick = closeOuter
),
context.toggleInnerSheetButton(renderState),
context.toggleInnerSheetButton(name = "inner", renderState),
color = android.R.color.holo_green_light,
showEditText = true,
),
Expand Down Expand Up @@ -103,33 +103,59 @@ object NestedOverlaysWorkflow : StatefulWorkflow<Unit, State, Nothing, Screen>()
name = "outer",
overlays = listOfNotNull(outerSheet),
body = TopAndBottomBarsScreen(
topBar = if (!renderState.showTopBar) null else context.topBottomBar(renderState),
topBar = if (!renderState.showTopBar) {
null
} else {
context.topBottomBar(
top = true,
renderState
)
},
content = BodyAndOverlaysScreen(
name = "inner",
body = bodyBarButtons,
overlays = listOfNotNull(innerSheet)
),
bottomBar = if (!renderState.showBottomBar) null else context.topBottomBar(renderState)
bottomBar = if (!renderState.showBottomBar) {
null
} else {
context.topBottomBar(
top = false,
renderState
)
}
)
)
}

override fun snapshotState(state: State) = null

private fun RenderContext.topBottomBar(
top: Boolean,
renderState: State
) = ButtonBar(
toggleInnerSheetButton(renderState),
Button(
name = R.string.cover_all,
onClick = eventHandler("cover everything") { state = state.copy(showOuterSheet = true) }
): ButtonBar {
val name = if (top) "top" else "bottom"
return ButtonBar(
toggleInnerSheetButton(
name = name,
renderState = renderState,
),
Button(
name = R.string.cover_all,
onClick = eventHandler("$name cover everything") {
state = state.copy(showOuterSheet = true)
}
)
)
)
}

private fun RenderContext.toggleInnerSheetButton(renderState: State) =
private fun RenderContext.toggleInnerSheetButton(
name: String,
renderState: State
) =
Button(
name = if (renderState.showInnerSheet) R.string.reveal_body else R.string.cover_body,
onClick = eventHandler("reveal / cover body") {
onClick = eventHandler("$name: reveal / cover body") {
state = state.copy(showInnerSheet = !state.showInnerSheet)
}
)
Expand Down
Loading
Loading