Remote Compose Storybook English GitHub

animateEnterExit / animationSpec · animationSpec(enabled)

Layout changes animated or instant.

animateEnterExit / animationSpec · animationSpec(enabled): документ, нарисованный плеером 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.RemoteBox
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.animationSpec
import androidx.compose.remote.creation.compose.modifier.background
import androidx.compose.remote.creation.compose.modifier.clickable
import androidx.compose.remote.creation.compose.modifier.size
import androidx.compose.remote.creation.compose.state.MutableRemoteBoolean
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.runtime.remember
import androidx.compose.ui.graphics.Color

@Composable
@RemoteComposable
fun AnimationToggle(enabled: Boolean) {
    val wide = remember { MutableRemoteBoolean(false) }
    // animationSpec(enabled) switches layout animation on or off for a component.
    RemoteBox(
        RemoteModifier.animationSpec(enabled)
            .size(wide.select(260.rdp, 120.rdp), 80.rdp)
            .background(Color(0xFF00897B).rc)
            .clickable(valueChangeAction(wide, !wide)),
        contentAlignment = RemoteAlignment.Center,
    ) {
        RemoteText("Tap to resize".rs, color = Color.White.rc)
    }
}

API

creation.compose.modifier.animateEnterExit

RemoteModifier animateEnterExit(RemoteModifier, optional RemoteEnterTransition enter, optional RemoteExitTransition exit, optional RemoteTweenSpec spec, optional int animationId)

creation.compose.modifier.animationSpec

RemoteModifier animationSpec(RemoteModifier, boolean enabled)
RemoteModifier animationSpec(RemoteModifier, optional int animationId, optional RemoteTweenSpec motionSpec, optional RemoteTweenSpec visibilitySpec, optional RemoteEnterTransition enter, optional RemoteExitTransition exit)
RemoteModifier animationSpec(RemoteModifier, int animationId, boolean enabled)

creation.compose.modifier.RemoteEnterTransition

class RemoteEnterTransition
  RemoteEnterTransition.Companion Companion
  RemoteEnterTransition FadeIn
  RemoteEnterTransition Particle
  RemoteEnterTransition Rotate
  RemoteEnterTransition SlideInBottom
  RemoteEnterTransition SlideInLeft
  RemoteEnterTransition SlideInRight
  RemoteEnterTransition SlideInTop

creation.compose.modifier.RemoteExitTransition

class RemoteExitTransition
  RemoteExitTransition.Companion Companion
  RemoteExitTransition FadeOut
  RemoteExitTransition Particle
  RemoteExitTransition Rotate
  RemoteExitTransition SlideOutBottom
  RemoteExitTransition SlideOutLeft
  RemoteExitTransition SlideOutRight
  RemoteExitTransition SlideOutTop

creation.compose.modifier.remoteFadeIn

RemoteEnterTransition remoteFadeIn()

creation.compose.modifier.remoteFadeOut

RemoteExitTransition remoteFadeOut()

Справочник

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

Ещё в разделе «Анимация»