Skip to content

Instantly share code, notes, and snippets.

View es0329's full-sized avatar

Eric es0329

View GitHub Profile
@5AbhishekSaxena
5AbhishekSaxena / ArticleListViewModelRobot.kt
Last active September 30, 2021 04:00
Test Robot with Execute around example
class ArticleListViewModelRobot private constructor() {
private lateinit var viewModel: ArticleListViewModel
private val fakeRepository = FakeArticleRepository()
private fun setup() {
buildViewModel()
}
fun buildViewModel() = apply {
@virendersran01
virendersran01 / ReorderableList.kt
Created September 3, 2021 01:59 — forked from surajsau/DragDropList.kt
Drag-n-Drop implementation in Jetpack Compose
@Composable
fun ReorderableList(
items: List<ReorderItem>,
onMove: (Int, Int) -> Unit,
modifier: Modifier = Modifier
) {
val scope = rememberCoroutineScope()
var overscrollJob by remember { mutableStateOf<Job?>(null) }
@surajsau
surajsau / DragDropList.kt
Last active January 19, 2026 09:29
Drag-n-Drop implementation in Jetpack Compose
@Composable
fun DragDropList(
items: List<ReorderItem>,
onMove: (Int, Int) -> Unit,
modifier: Modifier = Modifier
) {
val scope = rememberCoroutineScope()
var overscrollJob by remember { mutableStateOf<Job?>(null) }
@c5inco
c5inco / MaterialMotionTransitions.kt
Last active June 4, 2025 05:48
Reusable transitions that map to Material 2 motion system - https://material.io/develop/android/theming/motion
// Requires Compose 1.1.0-alpha02+
// Best used with navigation animation transitions in Accompanist 0.17.0+
import androidx.compose.animation.*
import androidx.compose.animation.core.FastOutLinearInEasing
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
@Aidanvii7
Aidanvii7 / NavControllerComposeUtils.kt
Last active August 13, 2023 16:38
Compose Navigation with Parcelable arguments
@file:Suppress("UnnecessaryVariable", "PackageDirectoryMismatch")
package androidx.navigation
import android.os.Bundle
import android.os.Parcelable
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
fun NavController.navigate(
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Paint
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
package glureau.frameradar
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import java.util.*
@AdamMc331
AdamMc331 / Fragment.kt
Created June 8, 2021 21:38
Example for navigating with ViewModel to Fragment
class Fragment : Fragment() {
fun listenForNavigation() {
lifecycleScope.launchWhenResumed {
val directions = viewModel.navigationChannel.receive()
findNavController().navigate(directions)
}
}
}
@pyricau
pyricau / Example.kt
Created June 4, 2021 20:21
A test coroutine dispatcher to reproduce race conditions
// Here's an example based on a test that was meant to reproduce a race condition,
// where we were launching several coroutines in a specific order without realizing
// that a different order would introduce race conditions. The test code here was used to
// reproduce the exact bad order.
// Note: there are probably better approaches to doing this.
val dispatcher = QueueDelegatingTestDispatcher()
// ... TODO pass in the dispatcher to the tested code launching coroutines
@daniel-j-h
daniel-j-h / Map.kt
Last active June 16, 2023 07:37
Adapting an imperative map (Google Map, Mapbox Map, etc.) for a declarative UI such as Android Compose; below shows an example for a Mapbox map, in https://github.com/android/compose-samples/tree/e6994123804b976083fa937d3f5bf926da4facc5/Crane#crane-sample you will find an example for a Google Map
package com.example.view
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.viewinterop.AndroidView
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import com.mapbox.geojson.Point