Skip to content

Instantly share code, notes, and snippets.

View LouisCAD's full-sized avatar

Louis CAD LouisCAD

View GitHub Profile
@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
@sagar-viradiya
sagar-viradiya / ThreadLikePathAnimation.kt
Last active June 2, 2024 14:50
An attampt to implement Threads app like path animation on pull to refresh in Jetpack Compose
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun PullToRefreshAnimation() {
val path = remember {
GitHubLogoPath.path.toPath()
}
val lines = remember {
path.asAndroidPath().flatten(error = 0.5f).toList()
}
@halilozercan
halilozercan / DrawGlyphs.kt
Created October 1, 2023 20:30
A Set of helper functions and classes to draw each individual glyph separately
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.ImageBitmap
@KlassenKonstantin
KlassenKonstantin / TextTransition.kt
Created October 1, 2023 17:42
Cascading Text Transition
@Composable
fun TextTransition(textAndColor: Pair<String, Color>) {
AnimatedContent(
targetState = textAndColor,
transitionSpec = {
fadeIn() togetherWith fadeOut()
}
) { (text, color) ->
Row {
text.forEachIndexed { index, char ->
@Kashif-E
Kashif-E / ToUIColor.kt
Created September 3, 2023 15:14
Material Color to UIColor
val uiColor = MaterialTheme.colors.surface.toUIColor()
@OptIn(ExperimentalForeignApi::class)
fun Color.toUIColor(): UIColor {
val colorSpace = CGColorSpaceCreateDeviceRGB()
val components = nativeHeap.allocArray<DoubleVar>(4)
components[0] = red.toDouble()
components[1] = green.toDouble()
components[2] = blue.toDouble()
components[3] = alpha.toDouble()
@rock3r
rock3r / EqualWidthComponentsRow.kt
Last active July 5, 2023 14:40
Compose Custom Layout: row of components, all made as wide as the widest one
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Sebastiano Poggi wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Seb
* ----------------------------------------------------------------------------
*/
package dev.sebastiano.bundel
/* Copyright 2023 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.MarqueeSpacing
import androidx.compose.foundation.basicMarquee
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
@riggaroo
riggaroo / CompositingStrategyOffscreenExample.kt
Last active May 27, 2024 16:20
GraphicsLayer CompositingStrategy Example demonstrating offscreen compositing strategy in Jetpack Compose, leveraging BlendMode.Clear to mask some of the image away.
/* Copyright 2022 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Composable
fun GraphicsLayerCompositingStrategyExample() {
Image(painter = painterResource(id = R.drawable.dog),
contentDescription = "Dog",
contentScale = ContentScale.Crop,
modifier = Modifier
.size(120.dp)
.aspectRatio(1f)
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
import org.json.JSONObject
import java.io.File
const val tinyPngApiKey = "<YOUR-API-KEY-GOES-HERE>"
val projectDir = File("<PATH-TOPROJECT-ROOT>")
val supportedExtensions = listOf("png", "jpg")
fun main() {
projectDir.walk().forEach { srcFile ->
if (supportedExtensions.contains(srcFile.extension)) {