🌈 Create new beautiful Compose Gradients with our new wesite ->

Zoomable scrollable row

Embed
<script src="https://composables.com/embed/@usuiat/components/0b9203286274b75a08dbfc8e.js"></script>
CommunityCommunityZoomableScrollableRowSamplePreview.kt
import androidx.compose.runtime.Composable
import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.unit.dp
import net.engawapg.lib.zoomable.ExperimentalZoomableApi
import net.engawapg.lib.zoomable.rememberZoomState
import net.engawapg.lib.zoomable.zoomableWithScroll
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Switch
import androidx.compose.material3.TextButton
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.rememberCoroutineScope
import kotlinx.coroutines.launch
import net.engawapg.lib.zoomable.MouseWheelZoom
import net.engawapg.lib.zoomable.ScrollGesturePropagation

@Composable
fun CommunityZoomableScrollableRowSample() {
    ScrollableRowSample(
        settings = Settings(),
        onTap = {},
        onLongPress = {},
    )
}

@OptIn(ExperimentalZoomableApi::class)
@Composable
fun ScrollableRowSample(
    settings: Settings,
    onTap: (Offset) -> Unit,
    onLongPress: (Offset) -> Unit,
) {
    Row(
        horizontalArrangement = Arrangement.spacedBy(16.dp),
        verticalAlignment = Alignment.CenterVertically,
        modifier = Modifier
            .fillMaxSize()
            .zoomableWithScroll(
                zoomState = rememberZoomState(initialScale = settings.initialScale),
                zoomEnabled = settings.zoomEnabled,
                enableOneFingerZoom = settings.enableOneFingerZoom,
                onTap = onTap,
                onLongPress = onLongPress,
            )
            .horizontalScroll(state = rememberScrollState())
    ) {
        repeat(10) { RowItem(text = "Item $it") }
    }
}

@Composable
private fun RowItem(text: String, modifier: Modifier = Modifier) {
    Text(
        text = text,
        modifier = modifier
            .size(200.dp)
            .background(MaterialTheme.colorScheme.surfaceContainerHigh, MaterialTheme.shapes.medium)
            .wrapContentSize()
    )
}

data class Settings(
    val zoomEnabled: Boolean = true,
    val enableOneFingerZoom: Boolean = true,
    val scrollGesturePropagation: ScrollGesturePropagation = ScrollGesturePropagation.ContentEdge,
    val initialScale: Float = 1f,
    val mouseWheelZoom: MouseWheelZoom = MouseWheelZoom.EnabledWithCtrlKey,
)

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SettingsBottomSheet(
    settings: Settings,
    onSettingsChange: (Settings) -> Unit,
    onDismissRequest: () -> Unit,
) {
    val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
    val scope = rememberCoroutineScope()
    ModalBottomSheet(
        sheetState = sheetState,
        onDismissRequest = onDismissRequest,
    ) {
        SettingsContent(
            settings = settings,
            onSettingsChange = onSettingsChange,
            onDoneClick = {
                scope
                    .launch { sheetState.hide() }
                    .invokeOnCompletion {
                        if (!sheetState.isVisible) {
                            onDismissRequest()
                        }
                    }
            }
        )
    }
}

@Composable
internal fun SettingsContent(
    settings: Settings,
    onSettingsChange: (Settings) -> Unit,
    onDoneClick: () -> Unit,
) {
    Row(
        verticalAlignment = Alignment.CenterVertically,
        modifier = Modifier.padding(horizontal = 16.dp)
    ) {
        Text(
            text = "Settings",
            style = MaterialTheme.typography.titleLarge,
            modifier = Modifier.weight(1f)
        )
        TextButton(onClick = onDoneClick) {
            Text("Done")
        }
    }

    HorizontalDivider(modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp))

    Column(
        modifier = Modifier.verticalScroll(rememberScrollState())
    ) {
        SwitchSettingItem(
            text = "zoomEnabled",
            checked = settings.zoomEnabled,
            onCheckedChange = {
                onSettingsChange(settings.copy(zoomEnabled = it))
            },
        )
        SwitchSettingItem(
            text = "enableOneFingerZoom",
            checked = settings.enableOneFingerZoom,
            onCheckedChange = {
                onSettingsChange(settings.copy(enableOneFingerZoom = it))
            },
        )

        HorizontalDivider(modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp))

        Text(
            text = "scrollGesturePropagation",
            style = MaterialTheme.typography.titleMedium,
            modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
        )
        RadioButtonSettingItem(
            text = "ContentEdge",
            selected = settings.scrollGesturePropagation == ScrollGesturePropagation.ContentEdge,
            onClick = {
                onSettingsChange(
                    settings.copy(scrollGesturePropagation = ScrollGesturePropagation.ContentEdge)
                )
            },
        )
        RadioButtonSettingItem(
            text = "NotZoomed",
            selected = settings.scrollGesturePropagation == ScrollGesturePropagation.NotZoomed,
            onClick = {
                onSettingsChange(
                    settings.copy(scrollGesturePropagation = ScrollGesturePropagation.NotZoomed)
                )
            },
        )

        HorizontalDivider(modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp))

        Text(
            text = "initialScale",
            style = MaterialTheme.typography.titleMedium,
            modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
        )
        Text(
            text = "To reflect the changed values, switch the sample to be displayed.",
            style = MaterialTheme.typography.bodyMedium,
            color = MaterialTheme.colorScheme.onSurfaceVariant,
            modifier = Modifier.padding(horizontal = 16.dp)
        )
        Spacer(modifier = Modifier.height(8.dp))
        RadioButtonSettingItem(
            text = "1.0",
            selected = settings.initialScale == 1f,
            onClick = { onSettingsChange(settings.copy(initialScale = 1f)) },
        )
        RadioButtonSettingItem(
            text = "2.0",
            selected = settings.initialScale == 2f,
            onClick = { onSettingsChange(settings.copy(initialScale = 2f)) },
        )

        HorizontalDivider(modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp))

        Text(
            text = "mouseWheelZoom",
            style = MaterialTheme.typography.titleMedium,
            modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
        )
        MouseWheelZoom.entries.forEach { mouseWheelZoom ->
            RadioButtonSettingItem(
                text = mouseWheelZoom.toString(),
                selected = settings.mouseWheelZoom == mouseWheelZoom,
                onClick = { onSettingsChange(settings.copy(mouseWheelZoom = mouseWheelZoom)) },
            )
        }

        Spacer(modifier = Modifier.height(24.dp))
    }
}

@Composable
private fun SwitchSettingItem(
    text: String,
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit,
    modifier: Modifier = Modifier,
) {
    Row(
        verticalAlignment = Alignment.CenterVertically,
        modifier = modifier
            .fillMaxWidth()
            .clickable { onCheckedChange(!checked) }
            .padding(vertical = 4.dp, horizontal = 16.dp)
            .heightIn(min = 48.dp)
    ) {
        Text(
            text = text,
            style = MaterialTheme.typography.titleMedium,
            modifier = Modifier.weight(1f)
        )
        Switch(
            checked = checked,
            onCheckedChange = null
        )
    }
}

@Composable
private fun RadioButtonSettingItem(
    text: String,
    selected: Boolean,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
) {
    Row(
        verticalAlignment = Alignment.CenterVertically,
        modifier = modifier
            .fillMaxWidth()
            .heightIn(min = 48.dp)
            .padding(horizontal = 12.dp)
            .clickable(onClick = onClick)
    ) {
        RadioButton(
            selected = selected,
            onClick = null,
            modifier = Modifier.size(48.dp)
        )
        Text(text = text)
    }
}

@Preview(name = "Zoomable scrollable row")
@Composable
fun CommunityCommunityZoomableScrollableRowSamplePreview() {
    CommunityZoomableScrollableRowSample()
}
build.gradle.kts
dependencies {
    implementation("net.engawapg.lib:zoomable:2.13.0")
    implementation("org.jetbrains.compose.runtime:runtime:1.12.0")
    implementation("org.jetbrains.compose.foundation:foundation:1.12.0")
    implementation("org.jetbrains.compose.ui:ui:1.12.0")
    implementation("org.jetbrains.compose.material3:material3:1.9.0")
}

MIT License

MIT License

Copyright (c) 2026 Usuiat

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.