Created
June 4, 2026 19:52
-
-
Save LethalMaus/80e57fb40c1956d558d0731deb862f37 to your computer and use it in GitHub Desktop.
Scrollable Compose preview screenshot workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package dev.jamescullimore.app.ui.settings | |
| import androidx.compose.foundation.ScrollState | |
| import androidx.compose.foundation.layout.fillMaxSize | |
| import androidx.compose.foundation.rememberScrollState | |
| import androidx.compose.runtime.Composable | |
| import androidx.compose.ui.Modifier | |
| import androidx.compose.ui.tooling.preview.Preview | |
| import androidx.compose.material3.Surface | |
| import dev.jamescullimore.app.ui.preview.CombinedPreviews | |
| import dev.jamescullimore.app.ui.theme.AppTheme | |
| @Composable | |
| fun SettingsContent( | |
| onBack: () -> Unit, | |
| onNavigate: (String) -> Unit, | |
| onSignOut: () -> Unit, | |
| scrollState: ScrollState = rememberScrollState(), | |
| ) { | |
| // Screen content uses scrollState in a verticalScroll modifier. | |
| } | |
| @CombinedPreviews | |
| @Composable | |
| private fun SettingsScreenPreview() { | |
| AppTheme { | |
| Surface(modifier = Modifier.fillMaxSize()) { | |
| SettingsContent( | |
| onBack = {}, | |
| onNavigate = {}, | |
| onSignOut = {}, | |
| ) | |
| } | |
| } | |
| } | |
| @CombinedPreviews | |
| @Composable | |
| private fun SettingsScreenScrolledPreview() { | |
| AppTheme { | |
| Surface(modifier = Modifier.fillMaxSize()) { | |
| SettingsContent( | |
| onBack = {}, | |
| onNavigate = {}, | |
| onSignOut = {}, | |
| scrollState = rememberScrollState(initial = 420), | |
| ) | |
| } | |
| } | |
| } | |
| // For longer screens I kept a second preview with a non-zero initial scroll position. | |
| // That let the screenshot set show more than just the top of the page without needing | |
| // a separate capture pipeline for scrollable content. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment