Skip to content

Instantly share code, notes, and snippets.

View ShikaSD's full-sized avatar
🍍
Being there, doing that

Andrei Shikov ShikaSD

🍍
Being there, doing that
View GitHub Profile
/*
Copyright (c) 2025 Andrei Shikov
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:
@ShikaSD
ShikaSD / Demo.kt
Last active August 1, 2023 20:19
onPlacedDemo
@Preview
@Composable
private fun LazyColumnDemo() {
var spacerPositionOffset by remember {
mutableStateOf(Offset.Unspecified)
}
val configuration = LocalConfiguration.current
val windowSize = remember(configuration) {
DpSize(configuration.screenWidthDp.dp, configuration.screenHeightDp.dp)
}
@ShikaSD
ShikaSD / TextMeasure.java
Created March 2, 2022 04:33
ReactNativeConfig with a feature flag for big text cache enabled
new ReactNativeConfig() {
@Override
public boolean getBool(String s) {
return s.equals(
"react_fabric:enable_large_text_measure_cache_android");
}
@Override
public long getInt64(String s) {
return 0;
@ShikaSD
ShikaSD / BackgroundMeasure.kt
Last active December 11, 2021 13:30
Measuring Compose content on background thread.
import android.content.Context
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Composition
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MonotonicFrameClock
import androidx.compose.runtime.Recomposer
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@Composable
fun TodoList() {
h1 { text("TodoList") }
p(modifier = Modifier.lineHeight(1.5f)) {
text("Classic example interacting with a list of items.")
br()
text("Use input below to add more items to a list (submit using Enter)")
}
val todos = remember {
@Composable
fun Component(hasDiv: Boolean) {
// Note that Component does not add anything to tree directly
// Only calls to emit change "virtual DOM"
// Here it is called from div -> tag -> emit
if (hasDiv) {
div() // <-- adding or removing node here based on parameter, updating tree
}
}
@Composable
fun input(
type: String,
value: String,
modifier: Modifier = Modifier
) {
tag(
tagName = 'input',
modifier = modifier.type(type).value(value)
)
@Composable
fun input(
value: String,
type: String,
onChange: (String) -> Unit,
onKeyUp: (String) -> Unit
) {
tag(
tagName = 'input',
attributes = mapOf('value' to value, 'type' to type),
object Click : Event {
override val type: String = "click"
object Payload : Event.Payload<Click> {
override val descriptor: Click = Click
}
class Callback(override val onReceive: (payload: Payload) -> Unit) : Event.Callback<Click, Payload> {
override val descriptor: Click = Click
}
private val CommandDispatcherAmbient = staticAmbientOf<RenderCommandDispatcher>()
// Instantiate it
composition.setContent {
Providers(CommandDispatcherAmbient provides commandDispatcher) {
composable()
}
}
// Use it