Skip to content

Instantly share code, notes, and snippets.

View LouisCAD's full-sized avatar

Louis CAD LouisCAD

View GitHub Profile
@halilozercan
halilozercan / TypingAnimation.kt
Last active November 13, 2024 12:04
TextField Typing Animation
package com.example.textfieldtypinganimation
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.AnimationVector1D
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
@KlassenKonstantin
KlassenKonstantin / MainActivity.kt
Created August 14, 2024 09:37
AnimatedVisibility overload with target state
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
TheTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
val helloWorld = "Hello World!"
var textOrNull by remember { mutableStateOf<String?>(helloWorld) }
@iamcalledrob
iamcalledrob / CaptureComposable.kt
Last active April 6, 2025 20:32
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
@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 December 17, 2024 14:34
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
@iamcalledrob
iamcalledrob / UNUserNotificationCenter+Async.swift
Created May 16, 2023 16:48
Fix for UNUserNotificationCenter.removeDeliveredNotifications not actually removing notifications
extension UNUserNotificationCenter {
func removeDeliveredNotificationsAsync(withIdentifiers identifiers: [String]) async {
// Calls to `UNUserNotificationCenter.current().removeDeliveredNotifications` schedule work
// on a background thread, with no completion handler or async/await interface. There is no
// way to know whether the work completed or not. If the notification service extension exits
// before the work has been completed, the work is cancelled and notifications are not removed.
//
// This is really poor API design on Apple's part, and even poorer documentation
//
// https://stackoverflow.com/questions/54565979#comment104110958_54680225