fun SettingsScreen()

in shared/src/commonMain/kotlin/org/jetbrains/kotlinconf/screens/SettingsScreen.kt [64:111]


fun SettingsScreen(
    onBack: () -> Unit,
    viewModel: SettingsViewModel = koinViewModel(),
) {
    val graphicsLayer = rememberGraphicsLayer()
    val scope = rememberCoroutineScope()
    var bitmap by remember { mutableStateOf<ImageBitmap?>(null) }
    var bitmapVisibility = remember { Animatable(1f) }

    val currentTheme by viewModel.theme.collectAsStateWithLifecycle()

    Box(Modifier.fillMaxSize()) {
        SettingsScreenImpl(
            onBack = onBack,
            currentTheme = currentTheme,
            onThemeChange = { theme ->
                scope.launch {
                    bitmap = graphicsLayer.toImageBitmap()
                    bitmapVisibility.snapTo(1f)
                    bitmapVisibility.animateTo(0f, tween(500, easing = EaseOutQuad))
                    bitmap = null
                }
                viewModel.setTheme(theme)
            },
            viewModel = viewModel,
            modifier = Modifier
                .drawWithContent {
                    graphicsLayer.record {
                        this@drawWithContent.drawContent()
                    }
                    drawLayer(graphicsLayer)
                }
        )

        bitmap?.let { bitmap ->
            Image(
                bitmap = bitmap,
                contentDescription = null,
                modifier = Modifier
                    .fillMaxHeight(fraction = bitmapVisibility.value)
                    .fillMaxWidth()
                    .align(Alignment.BottomCenter),
                contentScale = ContentScale.Crop,
                alignment = Alignment.BottomCenter
            )
        }
    }
}