clickable + valueChangeAction · Counter
An integer changed by expressions on tap.
Open the live, interactive demo →
Change its controls, read the remote document it produces and the diff after every change.
What it is
Makes something tappable and changes what is shown immediately on the device — toggles, counters, selections — with no trip to the server.
Good for
- Switches and checkboxes
- Steppers and counters
- Tabs and selections
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.valueChangeAction
import androidx.compose.remote.creation.compose.layout.RemoteAlignment
import androidx.compose.remote.creation.compose.layout.RemoteArrangement
import androidx.compose.remote.creation.compose.layout.RemoteBox
import androidx.compose.remote.creation.compose.layout.RemoteComposable
import androidx.compose.remote.creation.compose.layout.RemoteRow
import androidx.compose.remote.creation.compose.layout.RemoteText
import androidx.compose.remote.creation.compose.modifier.RemoteModifier
import androidx.compose.remote.creation.compose.modifier.RemoteRole
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.size
import androidx.compose.remote.creation.compose.shapes.RemoteRoundedCornerShape
import androidx.compose.remote.creation.compose.state.MutableRemoteInt
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.remote.creation.compose.state.rsp
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
@Composable
@RemoteComposable
fun ClickCounter(step: Int) {
val count = remember { MutableRemoteInt(0) }
RemoteRow(
verticalAlignment = RemoteAlignment.CenterVertically,
horizontalArrangement = RemoteArrangement.spacedBy(16.rdp),
) {
RemoteBox(
RemoteModifier.size(56.rdp)
.clip(RemoteRoundedCornerShape(28.rdp))
.background(Color(0xFF1E88E5).rc)
.clickable(valueChangeAction(count, count - step.ri), role = RemoteRole.Button),
contentAlignment = RemoteAlignment.Center,
) {
RemoteText("−$step".rs, color = Color.White.rc, fontSize = 18.rsp)
}
RemoteText(count.toRemoteString(), fontSize = 32.rsp)
RemoteBox(
RemoteModifier.size(56.rdp)
.clip(RemoteRoundedCornerShape(28.rdp))
.background(Color(0xFF1E88E5).rc)
.clickable(valueChangeAction(count, count + step.ri), role = RemoteRole.Button),
contentAlignment = RemoteAlignment.Center,
) {
RemoteText("+$step".rs, color = Color.White.rc, fontSize = 18.rsp)
}
}
}
API
creation.compose.modifier.clickable
RemoteModifier clickable(RemoteModifier, RemoteAction onClick, optional boolean enabled, optional RemoteRole? role)creation.compose.action.valueChangeAction
<T> RemoteAction valueChangeAction(MutableRemoteState<T> remoteState, RemoteState<T> updatedValue)creation.compose.modifier.RemoteRole
value class RemoteRole
RemoteRole.Companion Companion
RemoteRole Button
RemoteRole Carousel
RemoteRole Checkbox
RemoteRole DropdownList
RemoteRole Image
RemoteRole RadioButton
RemoteRole Switch
RemoteRole Tab
RemoteRole ValuePicker