Skip to content

Instantly share code, notes, and snippets.

View whitescent's full-sized avatar
😭
A proof of my faint existence

WhiteScent whitescent

😭
A proof of my faint existence
View GitHub Profile
@iamcalledrob
iamcalledrob / CaptureComposable.kt
Last active May 16, 2024 07:48
Android headless composable capture
import android.app.Presentation
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Picture
import android.graphics.SurfaceTexture
import android.hardware.display.DisplayManager
import android.view.Display
import android.view.Surface
import android.view.ViewGroup
import androidx.compose.foundation.layout.Box
@JunkFood02
JunkFood02 / CarouselContainerTransformDemo.kt
Last active June 23, 2024 16:20
🐈 A demo showcasing the new shared element transition API in Jetpack Compose!
/*
* Copyright 2024 The Android Open Source Project, JunkFood02
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@KlassenKonstantin
KlassenKonstantin / Pull2Refresh.kt
Created March 26, 2024 11:23
Fitbit style Pull 2 Refresh
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
WindowCompat.setDecorFitsSystemWindows(window, false)
super.onCreate(savedInstanceState)
setContent {
P2RTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
CompositionLocalProvider(
LocalOverscrollConfiguration provides null // Disable overscroll otherwise it consumes the drag before we get the chance
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshots.MutableSnapshot
import androidx.compose.runtime.snapshots.Snapshot
import java.util.WeakHashMap
@PublishedApi
internal class DebugStateObservation(private val id: String) {
private val map = WeakHashMap<Any, MutableList<Exception>>()
@tadfisher
tadfisher / PageLoadStates.kt
Last active January 9, 2024 10:28
Basic paging
sealed class PageLoadState(val endOfDataReached: Boolean) {
   data class Error(val error: Throwable) : PageLoadState(false) {
       override fun toString(): String = "Error(error=$error"
   }
   sealed class NotLoading(endOfDataReached: Boolean) : PageLoadState(endOfDataReached) {
       object Complete : NotLoading(true) {
           override fun toString(): String = "Complete"
       }
@Composable
fun AnimatedBorderCard(
modifier: Modifier,
contents: @Composable RowScope.() -> Unit
) {
val containerSize = 200.dp
var offsetFloat by remember { mutableStateOf(0f) }
LaunchedEffect(null) {
delay(100)
offsetFloat = containerSize.value * 10f
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.SpringSpec
import androidx.compose.animation.core.spring
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@mxalbert1996
mxalbert1996 / Scrollbar.kt
Last active July 24, 2024 22:50
Modifiers to draw scrollbars in Jetpack Compose
/*
* MIT License
*
* Copyright (c) 2022 Albert Chang
*
* 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
@apkelly
apkelly / Results.md
Last active February 1, 2024 18:53
Annotated String resources in Kotlin and for Jetpack Compose UI

The code below renders the following text in both Android Views and in Jetpack Compose UI.

Contact our team on 555 555 555 Opt 3 to activate.

@cedrickring
cedrickring / ColoredShadow.kt
Last active June 24, 2024 10:26
Draw a colored shadow in Android Jetpack Compose
/*
Copyright 2020 Cedric Kring.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,