Remote Compose Storybook English GitHub

Onboarding

Tap Next.

Onboarding: документ, нарисованный плеером Remote Compose
Открыть живое интерактивное демо →

Меняйте параметры, смотрите удалённый документ, который получается, и разницу после каждого изменения.

Что это

Пошаговый сценарий: все шаги приходят сразу и работают на устройстве.

Подходит для

  • Онбординг и обучение
  • Опросы и пошаговые формы

Код

Исходник примера с импортами androidx.compose.remote. CI компилирует каждый фрагмент кода на сайте против 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.RemoteColumn
import androidx.compose.remote.creation.compose.layout.RemoteComposable
import androidx.compose.remote.creation.compose.layout.RemoteRow
import androidx.compose.remote.creation.compose.layout.RemoteStateLayout
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.fillMaxSize
import androidx.compose.remote.creation.compose.modifier.fillMaxWidth
import androidx.compose.remote.creation.compose.modifier.height
import androidx.compose.remote.creation.compose.modifier.padding
import androidx.compose.remote.creation.compose.modifier.size
import androidx.compose.remote.creation.compose.shapes.RemoteCircleShape
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.remote.creation.compose.text.RemoteFontWeight
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color

/** A three-step onboarding: every step is in the document, the player moves between them. */
@Composable
@RemoteComposable
fun Onboarding(accent: Color) {
    val step = remember { MutableRemoteInt(0) }
    RemoteColumn(
        RemoteModifier.size(300.rdp, 320.rdp)
            .clip(RemoteRoundedCornerShape(24.rdp))
            .background(Color.White.rc)
            .padding(20.rdp),
        verticalArrangement = RemoteArrangement.SpaceBetween,
        horizontalAlignment = RemoteAlignment.CenterHorizontally,
    ) {
        // A fixed-height box around the steps: the web player otherwise lets a state layout take
        // its
        // parent's whole height.
        RemoteBox(RemoteModifier.fillMaxWidth().height(200.rdp)) {
            RemoteStateLayout(step, 0, 1, 2, modifier = RemoteModifier.fillMaxSize()) { index ->
                val (title, body) =
                    when (index) {
                        0 ->
                            "Welcome" to
                                "Screens like this one arrive as data, not as an app update."
                        1 ->
                            "Interactive" to
                                "Taps, steps and animations run on the device, offline."
                        else ->
                            "Always fresh" to
                                "The server can change this flow any day, for every user."
                    }
                RemoteColumn(
                    RemoteModifier.fillMaxSize(),
                    horizontalAlignment = RemoteAlignment.CenterHorizontally,
                    verticalArrangement =
                        RemoteArrangement.spacedBy(12.rdp, RemoteAlignment.CenterVertically),
                ) {
                    RemoteBox(
                        RemoteModifier.size(72.rdp).clip(RemoteCircleShape).background(accent.rc),
                        contentAlignment = RemoteAlignment.Center,
                    ) {
                        RemoteText("${index + 1}".rs, color = Color.White.rc, fontSize = 28.rsp)
                    }
                    RemoteText(title.rs, fontSize = 22.rsp, fontWeight = RemoteFontWeight.Bold)
                    RemoteText(body.rs, fontSize = 14.rsp, color = Color(0xFF5F6368).rc)
                }
            }
        }
        RemoteRow(
            horizontalArrangement = RemoteArrangement.spacedBy(8.rdp),
            verticalAlignment = RemoteAlignment.CenterVertically,
        ) {
            for (dot in 0..2) {
                RemoteBox(
                    RemoteModifier.size(8.rdp)
                        .clip(RemoteCircleShape)
                        .background(step.isEqualTo(dot.ri).select(accent.rc, Color(0xFFDADCE0).rc)),
                )
            }
        }
        RemoteBox(
            RemoteModifier.fillMaxWidth()
                .clip(RemoteRoundedCornerShape(12.rdp))
                .background(accent.rc)
                .clickable(valueChangeAction(step, (step + 1.ri) % 3.ri), role = RemoteRole.Button)
                .padding(vertical = 12.rdp),
            contentAlignment = RemoteAlignment.Center,
        ) {
            RemoteText(
                step.isEqualTo(2.ri).select("Start over".rs, "Next".rs),
                color = Color.White.rc,
            )
        }
    }
}

API

creation.compose.layout.RemoteStateLayout

void RemoteStateLayout(RemoteBoolean currentState, optional RemoteModifier modifier, java.lang.Boolean.() -> Unit content)
<T extends java.lang.Enum<T>> void RemoteStateLayout(RemoteEnum<T> currentState, optional RemoteModifier modifier, T.() -> Unit content)
void RemoteStateLayout(RemoteInt currentState, int... states, optional RemoteModifier modifier, java.lang.Integer.() -> Unit content)

creation.compose.action.valueChangeAction

<T> RemoteAction valueChangeAction(MutableRemoteState<T> remoteState, RemoteState<T> updatedValue)

Справочник

Ещё в разделе «Готовые экраны»