Skip to content

Instantly share code, notes, and snippets.

package de.apuri.choicechips
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.expandHorizontally
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
@KlassenKonstantin
KlassenKonstantin / Nrith.kt
Created November 11, 2022 16:30
No running in the halls
package de.apuri.norunninginthehalls
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.EaseInQuint
import androidx.compose.animation.core.EaseOutQuint
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.VectorConverter
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@KlassenKonstantin
KlassenKonstantin / Blocking.kt
Created August 20, 2021 17:14
Blocking access to DataStore<Preferences> with Enum support
private class Blocking<T>(
private val dataStore: DataStore<Preferences>,
private val prefKey: Preferences.Key<T>
) : ReadWriteProperty<Any, T?> {
override fun getValue(thisRef: Any, property: KProperty<*>): T? = runBlocking {
dataStore.data.map {
it[prefKey]
}.firstOrNull()
}
// Usage
// PingPongSwitch(
// textFirst = "Ping",
// textSecond = "Pong"
// )
@Composable
fun PingPongSwitch(
state: PingPongSwitchState = rememberPingPongSwitchState(),
textFirst: String,
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.VectorConverter
import androidx.compose.animation.core.spring
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.forEachGesture
import android.graphics.Matrix
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.animateIntAsState
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
@KlassenKonstantin
KlassenKonstantin / RoundedCornerSurface.kt
Created August 9, 2023 15:21
Keep inner radii appealing
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
InnerRadiusTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
Column(
verticalArrangement = Arrangement.Center
) {
@Composable
fun PlacementWithinAnchor(
modifier: Modifier,
content: @Composable PlacementWithinAnchorScope.() -> Unit
) {
CompositionLocalProvider(
LocalLayoutCoordinatesHolder provides ContainerLayoutCoordinatesHolder()
) {
Box(
modifier = modifier
package de.apuri.boing
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.gestures.awaitFirstDown