hostAction / combinedAction · Named host actions
A named action, with and without a value.
Open the live, interactive demo →
Change its controls, read the remote document it produces and the diff after every change.
What it is
A tap that tells the app around the screen to do something, such as open a page or save a bookmark, optionally while also updating the screen.
Good for
- Navigation to app screens
- Like, bookmark and share buttons
Code
The story's source with androidx.compose.remote imports. CI compiles every snippet on this site against AndroidX.
import androidx.compose.remote.creation.compose.action.hostAction
import androidx.compose.remote.creation.compose.layout.RemoteArrangement
import androidx.compose.remote.creation.compose.layout.RemoteBox
import androidx.compose.remote.creation.compose.layout.RemoteColumn
import androidx.compose.remote.creation.compose.layout.RemoteComposable
import androidx.compose.remote.creation.compose.layout.RemoteText
import androidx.compose.remote.creation.compose.modifier.RemoteModifier
import androidx.compose.remote.creation.compose.modifier.background
import androidx.compose.remote.creation.compose.modifier.clickable
import androidx.compose.remote.creation.compose.modifier.clip
import androidx.compose.remote.creation.compose.modifier.padding
import androidx.compose.remote.creation.compose.shapes.RemoteRoundedCornerShape
import androidx.compose.remote.creation.compose.state.rc
import androidx.compose.remote.creation.compose.state.rdp
import androidx.compose.remote.creation.compose.state.ri
import androidx.compose.remote.creation.compose.state.rs
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
@Composable
@RemoteComposable
fun HostActions(actionName: String) {
// A host action is delivered to the app that plays the document (see the Actions tab).
RemoteColumn(verticalArrangement = RemoteArrangement.spacedBy(12.rdp)) {
RemoteBox(
RemoteModifier.clip(RemoteRoundedCornerShape(12.rdp))
.background(Color(0xFF1E88E5).rc)
.clickable(hostAction(name = actionName.rs))
.padding(16.rdp),
) {
RemoteText("hostAction(\"$actionName\")".rs, color = Color.White.rc)
}
RemoteBox(
RemoteModifier.clip(RemoteRoundedCornerShape(12.rdp))
.background(Color(0xFF43A047).rc)
.clickable(hostAction(name = actionName.rs, value = 42.ri))
.padding(16.rdp),
) {
RemoteText("hostAction with a value".rs, color = Color.White.rc)
}
}
}
API
creation.compose.action.hostAction
RemoteAction hostAction(RemoteString name)
RemoteAction hostAction(RemoteString name, RemoteBoolean value)
RemoteAction hostAction(RemoteString name, RemoteFloat value)
RemoteAction hostAction(RemoteString name, RemoteInt value)
RemoteAction hostAction(RemoteString name, RemoteString value)
RemoteAction hostAction(int id, optional RemoteString? metadata)creation.compose.action.combinedAction
RemoteAction combinedAction(RemoteAction... actions)creation.compose.action.RemoteAction
interface RemoteAction
RemoteAction.Companion Companion
RemoteAction None