Remote Compose Storybook English GitHub

Time & configuration · RemoteConfiguration

The player's window, density and font size. Change the viewport.

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

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

Что это

То, что знает только устройство: текущее время и дата, размер экрана, плотность и размер шрифта.

Подходит для

  • Часы и обратный отсчёт
  • Раскладки под размер экрана
  • Учёт размера шрифта пользователя

Код

Исходник примера с импортами androidx.compose.remote. CI компилирует каждый фрагмент кода на сайте против AndroidX.

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.RemoteText
import androidx.compose.remote.creation.compose.modifier.RemoteModifier
import androidx.compose.remote.creation.compose.modifier.background
import androidx.compose.remote.creation.compose.modifier.size
import androidx.compose.remote.creation.compose.state.RemoteConfiguration
import androidx.compose.remote.creation.compose.state.rc
import androidx.compose.remote.creation.compose.state.rdp
import androidx.compose.remote.creation.compose.state.rs
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

@Composable
@RemoteComposable
fun Configuration() {
    // RemoteConfiguration is the player's display, known only at play time.
    val config = RemoteConfiguration
    RemoteColumn(verticalArrangement = RemoteArrangement.spacedBy(4.rdp)) {
        RemoteText(
            "window: ".rs +
                config.windowWidthPx.toRemoteString() +
                " × ".rs +
                config.windowHeightPx.toRemoteString() +
                " px".rs,
        )
        RemoteText("density: ".rs + config.density.toRemoteString())
        RemoteText("fontSize: ".rs + config.fontSizePx.toRemoteString() + " px".rs)
        // The window size as dp drives layout: a bar half the window wide.
        RemoteBox(
            RemoteModifier.size(config.windowWidth / 2, 12.rdp).background(Color(0xFF1E88E5).rc),
        )
        // …a square the size of the user's font size, and a bar a tenth of the window high.
        RemoteRow(horizontalArrangement = RemoteArrangement.spacedBy(8.rdp)) {
            RemoteBox(
                RemoteModifier.size(config.fontSize, config.fontSize)
                    .background(Color(0xFFFB8C00).rc),
            )
            RemoteBox(
                RemoteModifier.size(24.rdp, config.windowHeight / 10)
                    .background(Color(0xFF8E24AA).rc),
            )
        }
    }
}

API

creation.compose.state.RemoteTimeVariables

class RemoteTimeVariables
  RemoteFloat animationDeltaTime
  RemoteFloat animationTime
  RemoteFloat continuousSeconds
  RemoteInt dayOfMonth
  RemoteInt dayOfWeek
  RemoteInt dayOfYear
  RemoteInt epochSecond
  RemoteInt hourOfDay
  RemoteInt minuteOfDay
  RemoteInt month
  RemoteInt secondOfHour
  RemoteInt utcOffsetSeconds
  RemoteInt year
  RemoteTimeVariables INSTANCE

creation.compose.state.RemoteConfiguration

class RemoteConfiguration
  RemoteFloat density
  RemoteDp fontSize
  RemoteFloat fontSizePx
  RemoteDp windowHeight
  RemoteFloat windowHeightPx
  RemoteDp windowWidth
  RemoteFloat windowWidthPx
  RemoteConfiguration INSTANCE

creation.compose.text.RemoteTimeDefaults

class RemoteTimeDefaults
  RemoteString defaultTimeString(optional RemoteBoolean is24HourFormat)
  RemoteBoolean is24HourFormat()
  RemoteTimeDefaults INSTANCE

Справочник

Другие примеры этого компонента

Ещё в разделе «Состояние и выражения»