1 /* 2 * Copyright 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.compose.foundation.lazy.grid 18 19 import androidx.compose.animation.core.FiniteAnimationSpec 20 import androidx.compose.animation.core.Spring 21 import androidx.compose.animation.core.VisibilityThreshold 22 import androidx.compose.animation.core.spring 23 import androidx.compose.runtime.Stable 24 import androidx.compose.ui.Modifier 25 import androidx.compose.ui.unit.IntOffset 26 27 /** Receiver scope being used by the item content parameter of [LazyVerticalGrid]. */ 28 @Stable 29 @LazyGridScopeMarker 30 sealed interface LazyGridItemScope { 31 /** 32 * This modifier animates the item appearance (fade in), disappearance (fade out) and placement 33 * changes (such as an item reordering). 34 * 35 * You should also provide a key via [LazyGridScope.item]/[LazyGridScope.items] for this 36 * modifier to enable animations. 37 * 38 * @sample androidx.compose.foundation.samples.GridAnimateItemSample 39 * @param fadeInSpec an animation specs to use for animating the item appearance. When null is 40 * provided the item will be appearing without animations. 41 * @param placementSpec an animation specs that will be used to animate the item placement. 42 * Aside from item reordering all other position changes caused by events like arrangement or 43 * alignment changes will also be animated. When null is provided no animations will happen. 44 * @param fadeOutSpec an animation specs to use for animating the item disappearance. When null 45 * is provided the item will be disappearance without animations. 46 */ animateItemnull47 fun Modifier.animateItem( 48 fadeInSpec: FiniteAnimationSpec<Float>? = spring(stiffness = Spring.StiffnessMediumLow), 49 placementSpec: FiniteAnimationSpec<IntOffset>? = 50 spring( 51 stiffness = Spring.StiffnessMediumLow, 52 visibilityThreshold = IntOffset.VisibilityThreshold 53 ), 54 fadeOutSpec: FiniteAnimationSpec<Float>? = spring(stiffness = Spring.StiffnessMediumLow), 55 ): Modifier 56 } 57