### Custom Theme Shimmer Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/rememberShimmer.md This example shows how to create a Shimmer instance with a custom theme, overriding default properties like shimmerWidth, rotation, and shaderColors. ```kotlin import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import com.valentinilk.shimmer.defaultShimmerTheme import com.valentinilk.shimmer.rememberShimmer import com.valentinilk.shimmer.shimmer import com.valentinilk.shimmer.ShimmerBounds @Composable fun CustomThemeShimmer() { val customTheme = defaultShimmerTheme.copy( shimmerWidth = 200.dp, rotation = 30f, shaderColors = listOf( Color.Gray.copy(alpha = 0.25f), Color.White.copy(alpha = 1f), Color.Gray.copy(alpha = 0.25f), ) ) val shimmer = rememberShimmer( shimmerBounds = ShimmerBounds.View, theme = customTheme ) Box( modifier = Modifier .size(100.dp) .shimmer(shimmer) .background(Color.LightGray) ) } ``` -------------------------------- ### View Bounds Example Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-bounds.md Demonstrates using ShimmerBounds.View where each element calculates its own animation boundary. Smaller elements animate faster than larger ones. ```kotlin @Composable fun ViewBoundsExample() { Column(spacing = 16.dp) { // Small element—faster animation Box( modifier = Modifier .size(50.dp) .shimmer(rememberShimmer(ShimmerBounds.View)) .background(Color.LightGray) ) // Large element—slower animation Box( modifier = Modifier .size(200.dp) .shimmer(rememberShimmer(ShimmerBounds.View)) .background(Color.LightGray) ) } } ``` -------------------------------- ### Access and Provide ShimmerTheme Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/types.md Demonstrates how to get the current ShimmerTheme using CompositionLocal and how to provide a custom theme within a CompositionLocalProvider. ```kotlin val currentTheme = LocalShimmerTheme.current CompositionLocalProvider(LocalShimmerTheme provides customTheme) { ... } ``` -------------------------------- ### Window Bounds Shimmer Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/rememberShimmer.md This example demonstrates creating a Shimmer instance with window bounds. It applies the shimmer effect to multiple Box elements within a Column. ```kotlin import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import com.valentinilk.shimmer.rememberShimmer import com.valentinilk.shimmer.shimmer import com.valentinilk.shimmer.ShimmerBounds @Composable fun WindowShimmer() { val shimmer = rememberShimmer(ShimmerBounds.Window) Column { repeat(10) { Box( modifier = Modifier .fillMaxWidth() .height(50.dp) .shimmer(shimmer) .background(Color.LightGray) ) } } } ``` -------------------------------- ### ShimmerSpec Keyframes Generation Example Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmerSpec.md Illustrates the generated KeyframesSpec for a ShimmerSpec call with specified duration, delay, and easing. ```text Time: 0ms -------- 800ms --------- 2300ms Value: 0f ========== 1f ============== 1f └─ easing ──┘ └─ delay ──────┘ ``` -------------------------------- ### Scrollable Content Shimmer Example Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-class.md Demonstrates how to synchronize a shimmer animation with scrollable content using ShimmerBounds.Custom and the updateBounds() method. The shimmer is updated based on the global position of the scrollable container. ```kotlin @Composable fun ScrollableShimmerContent() { val shimmer = rememberShimmer(ShimmerBounds.Custom) LazyColumn( modifier = Modifier .fillMaxSize() .onGloballyPositioned { layoutCoordinates -> val bounds = layoutCoordinates.unclippedBoundsInWindow() shimmer.updateBounds(bounds) } ) { items(100) { Box( modifier = Modifier .fillMaxWidth() .height(50.dp) .shimmer(shimmer) .background(Color.LightGray) ) } } } ``` -------------------------------- ### Window Bounds Example Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-bounds.md Illustrates ShimmerBounds.Window, where all shimmer-affected elements animate synchronously across the entire window. This creates a unified wave effect spanning the display. ```kotlin @Composable fun WindowBoundsExample() { val shimmer = rememberShimmer(ShimmerBounds.Window) Column { repeat(10) { Box( modifier = Modifier .fillMaxWidth() .height(50.dp) .shimmer(shimmer) .background(Color.LightGray) ) } } } ``` -------------------------------- ### Custom Bounds Example with LazyColumn Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-bounds.md Shows how to use ShimmerBounds.Custom with a LazyColumn, manually updating bounds via Shimmer.updateBounds() based on the scrollable container's position. ```kotlin @Composable fun CustomBoundsExample() { val shimmer = rememberShimmer(ShimmerBounds.Custom) LazyColumn( modifier = Modifier .fillMaxSize() .onGloballyPositioned { layoutCoordinates -> val bounds = layoutCoordinates.unclippedBoundsInWindow() shimmer.updateBounds(bounds) } ) { items(100) { Box( modifier = Modifier .fillMaxWidth() .height(50.dp) .shimmer(shimmer) .background(Color.LightGray) ) } } } ``` -------------------------------- ### Custom Bounds Example for Vertical Scrolling Content Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-bounds.md Demonstrates ShimmerBounds.Custom for vertical scrolling content using a Column with verticalScroll, updating bounds as the user scrolls. ```kotlin @Composable fun ScrollableShimmer() { val shimmer = rememberShimmer(ShimmerBounds.Custom) Column( modifier = Modifier .fillMaxSize() .verticalScroll(rememberScrollState()) .onGloballyPositioned { layoutCoordinates -> val position = layoutCoordinates.unclippedBoundsInWindow() shimmer.updateBounds(position) } ) { repeat(50) { Box( modifier = Modifier .fillMaxWidth() .height(50.dp) .shimmer(shimmer) .background(Color.LightGray) ) } } } ``` -------------------------------- ### shimmerSpec.md Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/GENERATION_REPORT.txt Documents the shimmerSpec function, detailing its signature, parameters, return type, and behavior. Includes examples of animation configurations and easing curves. ```APIDOC ## shimmerSpec ### Description Defines the specification for a shimmer animation, including its timing, easing, and keyframes. Allows for detailed control over the animation's behavior. ### Signature Full function signature is provided. ### Parameters All parameters are explained. ### Return Return type documentation is available. ### Behavior How the spec is built is explained. ### Examples 5+ animation examples are provided. ### Easing Curves Table of easing options is included. ### Visualization Keyframes diagram is available. ### Source File path and line range are available. ``` -------------------------------- ### unclipped-bounds.md Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/GENERATION_REPORT.txt Details the unclippedBounds extension function, explaining its return type, rationale, and usage with practical examples. It also covers error handling and performance characteristics. ```APIDOC ## unclippedBounds ### Description An extension function that calculates shimmer bounds without clipping. Provides rationale, usage examples, and details on error handling and performance. ### Signature Extension function signature is provided. ### Return Return type and structure are documented. ### Rationale Explanation of why it's used compared to boundsInWindow(). ### Usage 3+ practical examples are provided. ### Exception Handling Details on error resilience are included. ### Rect Structure Properties table for the Rect structure. ### Performance Computational characteristics are described. ### Source File path and line range are available. ``` -------------------------------- ### Custom Shimmer Bounds with unclippedBoundsInWindow Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/unclipped-bounds.md Demonstrates how to use `unclippedBoundsInWindow()` to get custom shimmer bounds for a Column of shimmered Boxes. The bounds are updated via `onGloballyPositioned`. ```kotlin import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.unit.dp import com.valentinilk.shimmer.ShimmerBounds import com.valentinilk.shimmer.rememberShimmer import com.valentinilk.shimmer.shimmer import com.valentinilk.shimmer.unclippedBoundsInWindow @Composable fun CustomBoundsShimmer() { val shimmer = rememberShimmer(ShimmerBounds.Custom) Column( modifier = Modifier .fillMaxSize() .onGloballyPositioned { layoutCoordinates -> val bounds = layoutCoordinates.unclippedBoundsInWindow() shimmer.updateBounds(bounds) } ) { repeat(20) { Box( modifier = Modifier .fillMaxWidth() .height(50.dp) .shimmer(shimmer) .background(Color.LightGray) ) } } } ``` -------------------------------- ### Window Bounds Shimmer Configuration Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/configuration.md Use ShimmerBounds.Window for synchronized shimmer effects across the entire screen. This example demonstrates applying a single shimmer instance to multiple elements within a Column. ```kotlin import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.unclippedBoundsInWindow import com.valentinilk.shimmer.rememberShimmer import com.valentinilk.shimmer.shimmer @Composable fun WindowBoundsConfig() { val shimmer = rememberShimmer(ShimmerBounds.Window) // All elements use the same shimmer instance Column { repeat(10) { Box( modifier = Modifier .fillMaxWidth() .height(50.dp) .shimmer(shimmer) .background(Color.LightGray) ) } } } ``` -------------------------------- ### Run Desktop Sample App Source: https://github.com/valentinilk/compose-shimmer/blob/master/README.md Execute the desktop sample application using Gradle. This command is run from the project's root directory. ```bash ./gradlew :sample:run ``` -------------------------------- ### Run Browser Sample App Source: https://github.com/valentinilk/compose-shimmer/blob/master/README.md Launch the browser sample application using Gradle. This command is run from the project's root directory. ```bash ./gradlew :sample:jsBrowserDevelopmentRun ``` -------------------------------- ### Shimmer Animation Cycle Progression Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-effect-internal.md Illustrates the progression of the animatedState and traversal distance throughout the animation cycle, from start to end, and its repetition. ```text Frame 0: animatedState = 0.0 traversal = -translationDistance/2 shimmer is off-screen left Frame N/2: animatedState = 0.5 traversal = pivotPoint.x shimmer is at center of bounds Frame N: animatedState = 1.0 traversal = translationDistance/2 shimmer is off-screen right Then repeats based on AnimationSpec (usually RestartMode) ``` -------------------------------- ### Run WebAssembly Sample App Source: https://github.com/valentinilk/compose-shimmer/blob/master/README.md Execute the WebAssembly sample application using Gradle. This command is run from the project's root directory. ```bash ./gradlew :sample:wasmJsBrowserDevelopmentRun ``` -------------------------------- ### Advanced Shimmer Entry Point with Custom Theme Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/EXPORTS.md Integrate advanced configurations by creating a custom shimmer theme, such as modifying the rotation, and then applying it to a shimmer instance. This provides fine-grained control over the shimmer's appearance. ```kotlin val theme = defaultShimmerTheme.copy(rotation = 45f) val shimmer = rememberShimmer(ShimmerBounds.View, theme = theme) Box(modifier = Modifier.shimmer(shimmer)) ``` -------------------------------- ### Standard Shimmer Entry Point with Custom Instance Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/EXPORTS.md Create a custom shimmer instance using `rememberShimmer` with `ShimmerBounds.View` for more control. This allows for a customized shimmer effect on a Box composable. ```kotlin val shimmer = rememberShimmer(ShimmerBounds.View) Box(modifier = Modifier.shimmer(shimmer)) ``` -------------------------------- ### Using Dp for Density-Independent Pixels Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/types.md Demonstrates how to define values in density-independent pixels using the .dp extension. This is useful for defining sizes and dimensions that scale with screen density. ```kotlin 100.dp // 100 density-independent pixels shimmerWidth: Dp ``` -------------------------------- ### Theme Switching for Shimmer Effects Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/local-shimmer-theme.md Demonstrates how to dynamically switch between shimmer themes, such as dark mode and light mode, by providing different theme configurations to `CompositionLocalProvider`. This allows adapting shimmer appearance based on global application states. ```kotlin import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.graphics.Color import com.valentinilk.shimmer.defaultShimmerTheme import com.valentinilk.shimmer.LocalShimmerTheme @Composable fun ThemeSwitcher(isDarkMode: Boolean) { val theme = if (isDarkMode) { defaultShimmerTheme.copy( shaderColors = listOf( Color.Black.copy(alpha = 0.25f), Color.DarkGray.copy(alpha = 1f), Color.Black.copy(alpha = 0.25f), ) ) } else { defaultShimmerTheme.copy( shaderColors = listOf( Color.White.copy(alpha = 0.25f), Color.LightGray.copy(alpha = 1f), Color.White.copy(alpha = 0.25f), ) ) } CompositionLocalProvider( LocalShimmerTheme provides theme ) { App() } } ``` -------------------------------- ### Size Zero Initialization Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/types.md Illustrates initializing a Size object with zero width and height using Size.Zero. This is commonly used for representing an empty or default size. ```kotlin Size.Zero ``` -------------------------------- ### Remember ShimmerEffect Factory Function Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-effect-internal.md Creates and remembers a ShimmerEffect instance within a Composable. It converts shimmer width to pixels, memoizes the effect, and starts its animation. ```kotlin @Composable internal fun rememberShimmerEffect(theme: ShimmerTheme): ShimmerEffect { val shimmerWidth = with(LocalDensity.current) { theme.shimmerWidth.toPx() } val shimmerEffect = remember(theme) { ShimmerEffect( animationSpec = theme.animationSpec, blendMode = theme.blendMode, rotation = theme.rotation, shaderColors = theme.shaderColors, shaderColorStops = theme.shaderColorStops, shimmerWidth = shimmerWidth, ) } LaunchedEffect(shimmerEffect) { shimmerEffect.startAnimation() } return shimmerEffect } ``` -------------------------------- ### shimmerSpec() Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/GENERATION_REPORT.txt Creates a ShimmerSpec configuration. ```APIDOC ## shimmerSpec() ### Description Creates a `ShimmerSpec` configuration, which defines the colors, color stops, and shape of the shimmer gradient. ### Parameters * **shaderColors**: List - Required - The list of colors to use in the shimmer gradient. * **shaderColorStops**: List? - Optional - The list of color stops (0.0 to 1.0) corresponding to `shaderColors`. Must match the length of `shaderColors`. * **bounds**: ShimmerBounds - Optional - The bounds for the shimmer effect. Defaults to `ShimmerBounds.Window`. ### Constraints * `shaderColors` and `shaderColorStops` must match in length. * Color stops should be in the 0.0 to 1.0 range. * At least one color should have an alpha near 1.0. ### Response Returns a `ShimmerSpec` object. ### Request Example ```kotlin val spec = shimmerSpec( shaderColors = listOf(Color.Gray, Color.White, Color.Gray), shaderColorStops = listOf(0.0f, 0.5f, 1.0f) ) ``` ### Response Example ```kotlin ShimmerSpec ``` ``` -------------------------------- ### Manual Bounds Tracking with unclippedBoundsInWindow Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/unclipped-bounds.md Illustrates manual tracking of composable bounds using `unclippedBoundsInWindow()` and displaying them as text. The shimmer effect is also updated with these unclipped bounds. ```kotlin import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.material.Text import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.unit.dp import com.valentinilk.shimmer.ShimmerBounds import com.valentinilk.shimmer.rememberShimmer import com.valentinilk.shimmer.shimmer import com.valentinilk.shimmer.unclippedBoundsInWindow @Composable fun ManualBoundsTracking() { val shimmer = rememberShimmer(ShimmerBounds.Custom) var boundsText by remember { mutableStateOf("Bounds: Not positioned") } Column( modifier = Modifier .fillMaxSize() .onGloballyPositioned { layoutCoordinates -> val bounds = layoutCoordinates.unclippedBoundsInWindow() boundsText = "Bounds: ${bounds.left}, ${bounds.top}, ${bounds.right}, ${bounds.bottom}" shimmer.updateBounds(bounds) } ) { Text(boundsText) Box( modifier = Modifier .size(100.dp) .shimmer(shimmer) .background(Color.LightGray) ) } } ``` -------------------------------- ### Builder Pattern with copy() Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/module-overview.md Demonstrates creating a custom shimmer theme by copying and modifying a default theme using the `copy()` method. ```kotlin val customTheme = defaultShimmerTheme.copy(rotation = 45f) ``` -------------------------------- ### Shimmer Translation Distance Calculation (0° Rotation) Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-area-internal.md Example calculation for translation distance when a 100x100 view has 0° rotation and 50px shimmer width. The shimmer travels 150 pixels horizontally. ```plaintext width = 100/2 = 50 height = 100/2 = 50 distanceCornerToCenter = sqrt(50² + 50²) ≈ 70.7 beta = acos(50/70.7) ≈ 45° alpha = 45° - 0° = 45° distanceCornerToRotatedCenterLine = cos(45°) * 70.7 ≈ 50 translationDistance = 50 * 2 + 50 = 150 Shimmer travels 150 pixels horizontally. ``` -------------------------------- ### JavaScript for Dynamic Scaling Source: https://github.com/valentinilk/compose-shimmer/blob/master/sample/src/wasmJsMain/resources/index.html Initializes application dimensions and sets up a resize event listener to dynamically adjust the scale of the ComposeRoot element based on the window's current dimensions. This ensures the application fits within the viewport. ```javascript (() => { const appWidth = 480 const appHeight = 840 const root = document.getElementById("ComposeRoot") function updateScale() { const scale = Math.min( window.innerWidth / appWidth, window.innerHeight / appHeight, 1, ) root.style.transform = `scale(${scale})` } window.addEventListener("resize", updateScale) updateScale() })() ``` -------------------------------- ### Shimmer Translation Distance Calculation (45° Rotation) Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-area-internal.md Example calculation for translation distance when a 100x100 view has 45° rotation and 50px shimmer width. The shimmer travels approximately 191 pixels diagonally. ```plaintext width = 100/2 = 50 height = 100/2 = 50 distanceCornerToCenter = sqrt(50² + 50²) ≈ 70.7 beta = acos(50/70.7) ≈ 45° alpha = 45° - 45° = 0° distanceCornerToRotatedCenterLine = cos(0°) * 70.7 ≈ 70.7 translationDistance = 70.7 * 2 + 50 ≈ 191.4 Shimmer travels ~191 pixels diagonally. ``` -------------------------------- ### Rect Zero Initialization Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/types.md Shows how to initialize an empty Rect with zero width and height using Rect.Zero. This is useful for representing an uninitialized or zero-sized rectangle. ```kotlin Rect.Zero ``` -------------------------------- ### Apply Shimmer Modifier to UI Source: https://github.com/valentinilk/compose-shimmer/blob/master/README.md Apply the `.shimmer()` modifier to a Composable to create a shimmering effect on all subsequent UI elements within its scope. This example shows how to apply it to a `Row` containing placeholder elements. ```kotlin @Composable fun ShimmeringPlaceholder() { Row( modifier = Modifier .shimmer() // <- Affects all subsequent UI elements .fillMaxWidth() .padding(16.dp), horizontalArrangement = Arrangement.spacedBy(16.dp), ) { Box( modifier = Modifier .size(80.dp, 80.dp) .background(Color.LightGray), ) Column( verticalArrangement = Arrangement.spacedBy(16.dp), ) { Box( modifier = Modifier .fillMaxWidth() .height(24.dp) .background(Color.LightGray), ) Box( modifier = Modifier .size(120.dp, 20.dp) .background(Color.LightGray), ) } } } ``` -------------------------------- ### Provide Custom Theme to Subtree Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/local-shimmer-theme.md Shows how to provide a custom `ShimmerTheme` to a subtree of Composables using `CompositionLocalProvider`. Shimmers within this subtree will automatically use the custom theme. ```kotlin @Composable fun CustomThemeSubtree() { val customTheme = defaultShimmerTheme.copy( shimmerWidth = 200.dp, rotation = 30f ) CompositionLocalProvider( LocalShimmerTheme provides customTheme ) { // All shimmer() calls in this subtree will use customTheme Column { repeat(5) { Box( modifier = Modifier .fillMaxWidth() .height(50.dp) .shimmer() // No theme parameter needed .background(Color.LightGray) ) } } } } ``` -------------------------------- ### Set Application-Wide Theme Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/local-shimmer-theme.md Demonstrates setting a custom `ShimmerTheme` for the entire application by providing it at the root level using `CompositionLocalProvider`. All subsequent shimmers will inherit this theme. ```kotlin @Composable fun MyApp() { val appShimmerTheme = defaultShimmerTheme.copy( shimmerWidth = 300.dp, rotation = 20f, shaderColors = listOf( Color.Gray.copy(alpha = 0.25f), Color.White.copy(alpha = 1f), Color.Gray.copy(alpha = 0.25f), ) ) CompositionLocalProvider( LocalShimmerTheme provides appShimmerTheme ) { // All screens and composables use appShimmerTheme Navigation() } } ``` -------------------------------- ### shimmer-class Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/GENERATION_REPORT.txt Documentation for the Shimmer class, detailing its constructor, public methods like updateBounds(), and properties. It also covers usage aspects like memory, lifecycle, and thread safety. ```APIDOC ## Shimmer Class ### Description Represents the core Shimmer effect. This class manages the internal state and behavior of the shimmer animation, including methods for updating its bounds and properties. ### Constructor Constructor visibility is documented. ### Methods - **updateBounds()**: Documented method for updating the shimmer's bounds. ### Properties Public and internal properties are documented. ### Usage Details on memory, lifecycle, and thread safety are provided. ### Source File path and line range are available. ``` -------------------------------- ### Composition Local Provider for Theme Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/rememberShimmer.md Demonstrates how to provide a custom ShimmerTheme using CompositionLocalProvider. The rememberShimmer function will automatically pick up this theme if not explicitly provided. ```kotlin import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import com.valentinilk.shimmer.LocalShimmerTheme import com.valentinilk.shimmer.defaultShimmerTheme import com.valentinilk.shimmer.rememberShimmer import com.valentinilk.shimmer.ShimmerBounds @Composable fun ThemedApp() { val customTheme = defaultShimmerTheme.copy(rotation = 45f) CompositionLocalProvider( LocalShimmerTheme provides customTheme ) { val shimmer = rememberShimmer(ShimmerBounds.View) // shimmer will automatically use the provided custom theme } } ``` -------------------------------- ### startAnimation Method Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-effect-internal.md Launches the shimmer animation using the configured AnimationSpec. This method is called within a LaunchedEffect in rememberShimmerEffect(). ```kotlin internal suspend fun startAnimation() ``` -------------------------------- ### Factory with Memoization Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/module-overview.md Shows how to create and remember a Shimmer instance using a composable function, ensuring memoization. ```kotlin @Composable fun rememberShimmer(...): Shimmer = remember { Shimmer(...) } ``` -------------------------------- ### Compose Shimmer Data Flow Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/module-overview.md Illustrates the data flow from user code to the final shimmer animation in Compose. ```text User Code ↓ rememberShimmer() with ShimmerBounds ↓ (creates) Shimmer instance (holds theme + effect) ↓ Modifier.shimmer(shimmerInstance) ↓ (creates) ShimmerNode (draw + position tracking) ↓ ShimmerArea (calculates bounds/distance) ↓ ShimmerEffect (animates and renders) ↓ Output: Shimmer animation on UI ``` -------------------------------- ### Provide Composition-Wide Theme Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/INDEX.md Use CompositionLocalProvider to set a custom theme for all shimmer effects within a composition. This allows for consistent theming across your UI. ```kotlin CompositionLocalProvider( LocalShimmerTheme provides customTheme ) { // All shimmer() calls inherit customTheme } ``` -------------------------------- ### JavaScript for Dynamic Scaling Source: https://github.com/valentinilk/compose-shimmer/blob/master/sample/src/jsMain/resources/index.html Initializes application dimensions and retrieves the root element. The updateScale function calculates and applies a scale transform to the root element to fit the window, while maintaining a maximum scale of 1. An event listener ensures scaling updates on window resize. ```javascript (() => { const appWidth = 480; const appHeight = 840; const root = document.getElementById("ComposeRoot"); function updateScale() { const scale = Math.min( window.innerWidth / appWidth, window.innerHeight / appHeight, 1 ); root.style.transform = `scale(${scale})`; } window.addEventListener("resize", updateScale); updateScale(); })(); ``` -------------------------------- ### Configure Shimmer Instance Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/INDEX.md Create a custom Shimmer instance using rememberShimmer for specific configurations. You can customize shimmerBounds and the theme. ```kotlin val shimmer = rememberShimmer( shimmerBounds = ShimmerBounds.View, // or Window, or Custom theme = defaultShimmerTheme.copy(...) ) Box(modifier = Modifier.shimmer(shimmer)) ``` -------------------------------- ### Multiple Independent Shimmer Instances Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-class.md Shows how to use multiple independent Shimmer instances within the same composition to achieve different animation effects, such as varying speeds. ```kotlin @Composable fun MultipleShimmers() { val shimmer1 = rememberShimmer(ShimmerBounds.View) val shimmer2 = rememberShimmer(ShimmerBounds.View) Box(modifier = Modifier.shimmer(shimmer1)) { Text("Fast shimmer") } Box(modifier = Modifier.shimmer(shimmer2)) { Text("Slow shimmer") } } ``` -------------------------------- ### Minimal Custom Theme Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/configuration.md Applies a minimal custom theme by copying the default theme and modifying the rotation property. ```kotlin import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import com.valentinilk.shimmer.ShimmerBounds import com.valentinilk.shimmer.defaultShimmerTheme import com.valentinilk.shimmer.rememberShimmer import com.valentinilk.shimmer.shimmerSpec import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch import androidx.compose.animation.core.infiniteRepeatable import androidx.compose.animation.core.RepeatMode @Composable fun MinimalCustomTheme() { val theme = defaultShimmerTheme.copy( rotation = 45f ) val shimmer = rememberShimmer(ShimmerBounds.View, theme = theme) // Use shimmer... } ``` -------------------------------- ### defaultShimmerTheme Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/GENERATION_REPORT.txt The default ShimmerTheme instance. ```APIDOC ## defaultShimmerTheme ### Description The default `ShimmerTheme` instance used by the library. This provides a sensible default configuration for shimmer effects if no custom theme is provided. ### Type `ShimmerTheme` ### Example ```kotlin val theme = defaultShimmerTheme ``` ``` -------------------------------- ### Integrate Shimmer Theme with Material Design Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/local-shimmer-theme.md Shows how to create a `ShimmerTheme` that complements a Material Design color scheme. It uses `rememberDynamicColorScheme` and `MaterialTheme` to define shimmer colors based on the current Material theme. ```kotlin @Composable fun MaterialThemedApp() { val material3Theme = rememberDynamicColorScheme() MaterialTheme(colorScheme = material3Theme) { // Create shimmer theme that matches Material Design colors val shimmerTheme = defaultShimmerTheme.copy( shaderColors = listOf( MaterialTheme.colorScheme.surface.copy(alpha = 0.25f), MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 1f), MaterialTheme.colorScheme.surface.copy(alpha = 0.25f), ) ) CompositionLocalProvider( LocalShimmerTheme provides shimmerTheme ) { // All shimmers match the Material Design theme HomeScreen() } } } ``` -------------------------------- ### shimmer-bounds.md Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/GENERATION_REPORT.txt Explains the ShimmerBounds sealed interface and its variants (View, Window, Custom). It provides a comparison of modes and guidance on when to use each. ```APIDOC ## Shimmer Bounds ### Description Defines the interface for specifying the bounds of the shimmer effect. Includes different variants like View, Window, and Custom, with detailed comparisons and usage guidance. ### Definition Sealed interface definition. ### Variants - **View**: Explained. - **Window**: Explained. - **Custom**: Explained. ### Characteristics Table comparing the different modes. ### Examples Usage example for each variant is provided. ### Comparison Side-by-side mode comparison is available. ### Selection Guide Guidance on when to use which mode is provided. ### Source File path and line range are available. ``` -------------------------------- ### Provide Custom Shimmer Theme Source: https://github.com/valentinilk/compose-shimmer/blob/master/README.md Integrate custom shimmer themes into your MaterialTheme using CompositionLocalProvider. This allows for centralized theming of shimmer effects. ```kotlin val yourShimmerTheme = defaultShimmerTheme.copy(/* Set your desirable values */) CompositionLocalProvider( LocalShimmerTheme provides yourShimmerTheme ) { /* content */ } ``` -------------------------------- ### Apply Shimmer Effect to a Box Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/module-overview.md Demonstrates how to apply the shimmer effect to a Box composable using the .shimmer() modifier. Modifier order is important; elements after .shimmer() are affected. ```kotlin Box( modifier = Modifier .size(100.dp) .shimmer() // Shimmer applied here .background(Color.LightGray) // Background here ) ``` -------------------------------- ### Custom Shimmer Colors Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-theme.md Creates a custom Shimmer theme by copying the default and modifying the shader colors. This is useful for applying unique color gradients to the shimmer effect. ```kotlin @Composable fun CustomShimmerColor() { val customTheme = defaultShimmerTheme.copy( shaderColors = listOf( Color.Blue.copy(alpha = 0.25f), Color.Cyan.copy(alpha = 1f), Color.Blue.copy(alpha = 0.25f), ) ) val shimmer = rememberShimmer(ShimmerBounds.View, theme = customTheme) Box( modifier = Modifier .size(100.dp) .shimmer(shimmer) .background(Color.LightGray) ) } ``` -------------------------------- ### Add Basic Shimmer Placeholder Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/START_HERE.md Use the Modifier.shimmer() to apply a basic shimmer effect to a Box composable. This is the simplest way to add a placeholder. ```kotlin Box(modifier = Modifier.shimmer()) ``` -------------------------------- ### Scrollable Content with unclippedBoundsInWindow for Shimmer Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/unclipped-bounds.md Shows how to apply `unclippedBoundsInWindow()` to a `LazyColumn` to ensure shimmer animations correctly cover scrollable content, even when partially off-screen. Bounds are updated in `onGloballyPositioned`. ```kotlin import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.unit.dp import com.valentinilk.shimmer.ShimmerBounds import com.valentinilk.shimmer.rememberShimmer import com.valentinilk.shimmer.shimmer import com.valentinilk.shimmer.unclippedBoundsInWindow @Composable fun ScrollableWithShimmer() { val shimmer = rememberShimmer(ShimmerBounds.Custom) LazyColumn( modifier = Modifier .fillMaxSize() .onGloballyPositioned { layoutCoordinates -> shimmer.updateBounds(layoutCoordinates.unclippedBoundsInWindow()) } ) { items(100) { Box( modifier = Modifier .fillMaxWidth() .height(100.dp) .shimmer(shimmer) .background(Color.LightGray) ) } } } ``` -------------------------------- ### Custom Shimmer Theme in Jetpack Compose Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/INDEX.md Create and apply a custom shimmer theme to a composable. This allows for fine-grained control over the shimmer's appearance, such as rotation. ```kotlin @Composable fun CustomShimmer() { val theme = defaultShimmerTheme.copy(rotation = 45f) val shimmer = rememberShimmer(ShimmerBounds.View, theme = theme) Box( modifier = Modifier .size(100.dp) .shimmer(shimmer) .background(Color.LightGray) ) } ``` -------------------------------- ### Providing Global Shimmer Theme Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-theme.md Applies a custom Shimmer theme globally within a composable subtree using CompositionLocalProvider. All shimmers within this scope will automatically inherit the provided theme. ```kotlin @Composable fun GlobalShimmerTheme() { val appTheme = defaultShimmerTheme.copy( rotation = 20f, shimmerWidth = 300.dp ) CompositionLocalProvider( LocalShimmerTheme provides appTheme ) { // All shimmers in this subtree will use appTheme by default Column { repeat(5) { Box( modifier = Modifier .fillMaxWidth() .height(50.dp) .shimmer() // Uses appTheme automatically .background(Color.LightGray) ) } } } } ``` -------------------------------- ### Apply Shimmer with Window Bounds Source: https://github.com/valentinilk/compose-shimmer/blob/master/README.md Use ShimmerBounds.Window to make the shimmer animation traverse the entire window, not just the view. This is useful for consistent animation across multiple elements. ```kotlin Column { val shimmerInstance = rememberShimmer(shimmerBounds = ShimmerBounds.Window) Text("Shimmering Text", modifier = Modifier.shimmer(shimmerInstance)) Text("Non-shimmering Text") Text("Shimmering Text", modifier = Modifier.shimmer(shimmerInstance)) } ``` -------------------------------- ### Access Current Theme in Composable Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/local-shimmer-theme.md Demonstrates how to access the current `ShimmerTheme` from `LocalShimmerTheme` within a Composable function and use it to create a shimmer effect. ```kotlin @Composable fun CurrentThemeExample() { val currentTheme = LocalShimmerTheme.current val shimmer = rememberShimmer(ShimmerBounds.View, theme = currentTheme) Box( modifier = Modifier .size(100.dp) .shimmer(shimmer) .background(Color.LightGray) ) } ``` -------------------------------- ### ShimmerArea Initialization: Rotation Normalization Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-area-internal.md Normalizes the rotation angle to radians and constrains it to 0-90 degrees during initialization. ```kotlin private val reducedRotation = rotationInDegree .reduceRotation() .toRadian() ``` -------------------------------- ### Shimmer Shader Creation Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-effect-internal.md Creates a LinearGradientShader using the calculated transformation matrix, gradient points, and specified colors. ```kotlin shader = LinearGradientShader( from = transformationMatrix.map(gradientFrom), to = transformationMatrix.map(gradientTo), colors = shaderColors, colorStops = shaderColorStops, ) ``` -------------------------------- ### ShimmerArea Equality and Hashing Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-area-internal.md Implements equals() and hashCode() for ShimmerArea based on shimmer width and rotation. Two areas are considered equal if they share the same configuration, irrespective of their bounds. ```kotlin override fun equals(other: Any?): Boolean { if (other !is ShimmerArea) return false return widthOfShimmer == other.widthOfShimmer && reducedRotation == other.reducedRotation } override fun hashCode(): Int { var result = widthOfShimmer.hashCode() result = 31 * result + reducedRotation.hashCode() return result } ``` -------------------------------- ### shimmer-theme.md Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/GENERATION_REPORT.txt Defines the ShimmerTheme class and its associated properties, including default values and customization options. It explains how to use CompositionLocal for theme integration. ```APIDOC ## Shimmer Theme ### Description Defines the theming for the shimmer effect, allowing customization of its appearance across the application. Includes properties, default values, and usage patterns with CompositionLocal. ### Definition Class definition with all fields. ### Properties Table with type, default value, and description for each property. ### Default Theme Complete default theme is shown. ### Examples 8+ customization examples are provided. ### Composition Local Usage with provider explained. ### Constraints Validation rules are detailed. ### Source File path and line range are available. ``` -------------------------------- ### Shimmer Class Constructor Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/shimmer-class.md The constructor for the Shimmer class is internal and not directly accessible. Use rememberShimmer() to create instances. ```kotlin class Shimmer internal constructor( internal val theme: ShimmerTheme, internal val effect: ShimmerEffect, bounds: Rect?, ) ``` -------------------------------- ### Handle Multiple Nested Theme Providers Source: https://github.com/valentinilk/compose-shimmer/blob/master/_autodocs/api-reference/local-shimmer-theme.md Illustrates how nested `CompositionLocalProvider` calls for `LocalShimmerTheme` create distinct scopes with different shimmer themes. Each nested provider overrides the theme for its children. ```kotlin @Composable fun NestedThemes() { val theme1 = defaultShimmerTheme.copy(rotation = 15f) val theme2 = defaultShimmerTheme.copy(rotation = 45f) val theme3 = defaultShimmerTheme.copy(rotation = 75f) CompositionLocalProvider(LocalShimmerTheme provides theme1) { Box( modifier = Modifier .size(100.dp) .shimmer() .background(Color.LightGray) ) CompositionLocalProvider(LocalShimmerTheme provides theme2) { Box( modifier = Modifier .size(100.dp) .shimmer() .background(Color.LightGray) ) CompositionLocalProvider(LocalShimmerTheme provides theme3) { Box( modifier = Modifier .size(100.dp) .shimmer() .background(Color.LightGray) ) } } } } ```