hostAction / combinedAction · Named host actions
A named action, with and without a value.
Открыть живое интерактивное демо →
Меняйте параметры, смотрите удалённый документ, который получается, и разницу после каждого изменения.
Что это
Нажатие, которое сообщает приложению вокруг экрана, что нужно сделать: открыть страницу или сохранить закладку, — заодно обновляя экран.
Подходит для
- Переходы на экраны приложения
- Кнопки «нравится», «в закладки», «поделиться»
Код
Исходник примера с импортами androidx.compose.remote. CI компилирует каждый фрагмент кода на сайте против 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