Skip to content

Instantly share code, notes, and snippets.

View belinwu's full-sized avatar

吴上阿吉 belinwu

View GitHub Profile
@belinwu
belinwu / StateMachineDebounceExample.kt
Created November 21, 2023 14:12 — forked from linean/StateMachineDebounceExample.kt
Simple example how events can be debounced on StateMachine side
// Keep in mind this is just simplified example
class Example {
private val scope = CoroutineScope(Job())
private val debouncingChannel = Channel<UserEvent>(
capacity = RENDEZVOUS,
onBufferOverflow = BufferOverflow.DROP_OLDEST,
)
@belinwu
belinwu / DecomposeUtils.kt
Created November 28, 2023 10:00 — forked from aartikov/DecomposeUtils.kt
Creates CoroutineScope for Decompose component
fun ComponentContext.componentCoroutineScope(): CoroutineScope {
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
if (lifecycle.state != Lifecycle.State.DESTROYED) {
lifecycle.doOnDestroy {
scope.cancel()
}
} else {
scope.cancel()
}
@belinwu
belinwu / SettingsSection.kt
Created December 15, 2023 12:48 — forked from bmc08gt/SettingsSection.kt
SettingsSectionScope
interface SettingsSectionScope {
fun item(
icon: ImageVector? = null,
title: String,
subtitle: String? = null,
endSlot: @Composable () -> Unit = { },
onClick: (() -> Unit)? = null,
)
@Composable
import io.reactivex.subjects.PublishSubject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.launch
import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.suspendCancellableCoroutine
@belinwu
belinwu / FlipAnimation.kt
Created April 28, 2024 04:32 — forked from vishal2376/FlipAnimation.kt
Card Flip Animation using Jetpack Compose
package com.vishal2376.animations.ui.theme
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.EaseInOut
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@belinwu
belinwu / CardSlideAnimation.kt
Created May 15, 2024 13:46 — forked from vishal2376/CardSlideAnimation.kt
Beautiful Card Sliding Animation
package com.vishal2376.animations
import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@belinwu
belinwu / Place.kt
Created May 20, 2024 04:14 — forked from vishal2376/Place.kt
Image Reflection with cool animation using Jetpack Compose
data class Place(
val name: String,
val resId: Int
)
@belinwu
belinwu / SweepGradientImage.kt
Created May 27, 2024 09:37 — forked from vishal2376/SweepGradientImage.kt
Sweep Line effect with some rotation and scale animation
@Composable
fun SweepGradientImage(
imgResId: Int,
maxImgSize: Dp = 250.dp,
maxImgRotation: Float = -10f
) {
var animationPlayed by remember { mutableStateOf(false) }
val lineOffset by animateFloatAsState(
@belinwu
belinwu / LazyListAnimation.kt
Created August 15, 2024 04:31 — forked from darvld/LazyListAnimation.kt
This gist contains a simple implementation of animated item transitions for use with `LazyListScope` (`LazyColumn`/`LazyRow`).
package io.github.darvld.utils
import androidx.compose.animation.*
import androidx.compose.animation.core.ExperimentalTransitionApi
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.*
import androidx.recyclerview.widget.AsyncListDiffer
import androidx.recyclerview.widget.DiffUtil