Skip to content

Instantly share code, notes, and snippets.

View necatisozer's full-sized avatar
👨‍💻
You don't know me, you're about to...

Necati Sözer necatisozer

👨‍💻
You don't know me, you're about to...
View GitHub Profile
@riggaroo
riggaroo / GraphicsBlend.kt
Created May 9, 2024 11:57
GraphicsLayer APIs - BlendMode per layer
@Preview
@Composable
private fun GraphicsLayerBlurBackground() {
Box(modifier = Modifier
.fillMaxSize()){
Image(
painter = painterResource(id = R.drawable.sunset),
contentDescription = null
)
val graphicsLayer2 = rememberGraphicsLayer()
@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
@alexstyl
alexstyl / MaterialColors.kt
Created May 15, 2023 10:05
All colors found in the 2014 Material Design color palette, ready to be used in Jetpack Compose.
/**
* Contains all color defined in the 2014 Material Design color palette.
*
*
*/
object MaterialColors {
val Red50 = Color(0xFFFFEBEE)
val Red100 = Color(0xFFFFCDD2)
val Red200 = Color(0xFFEF9A9A)
val Red300 = Color(0xFFE57373)
@surajsau
surajsau / ParallaxScreen.kt
Last active April 16, 2024 13:53
Parallax effect with Jetpack Compose
@Composable
fun ParallaxScreen(modifier: Modifier = Modifier) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
var data by remember { mutableStateOf<SensorData?>(null) }
DisposableEffect(Unit) {
val dataManager = SensorDataManager(context)
dataManager.init()
import kotlinx.coroutines.CancellationException
/**
* Like [runCatching], but with proper coroutines cancellation handling. Also only catches [Exception] instead of [Throwable].
*
* Cancellation exceptions need to be rethrown. See https://github.com/Kotlin/kotlinx.coroutines/issues/1814.
*/
inline fun <R> resultOf(block: () -> R): Result<R> {
return try {
Result.success(block())
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
1. hiltvm (applicable in top-level)
@dagger.hilt.android.lifecycle.HiltViewModel
class $NAME$ @javax.inject.Inject constructor(
$PARAM$
) : androidx.lifecycle.ViewModel() {
$END$
}
2. vmstatefunc (applicable in class)
private val _$NAME$ = androidx.compose.runtime.mutableStateOf<$TYPE$>($INITIAL_VALUE$)
@SumeraMartin
SumeraMartin / Sample.kt
Created July 19, 2021 14:10
Code snippet for article (Tricky refactoring of Jetpack Compose code (be careful with side effects))
@Composable
fun Screen() {
// OriginalWorkingVersion()
// RefactoredVersionWithIncorrectBehavior1()
// RefactoredVersionWithIncorrectBehavior2()
RefactoredWorkingVersion()
}
//region Original working version
@Composable
import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
@iamutkarshtiwari
iamutkarshtiwari / Jetpack Compose Right and Left ModalDrawer
Last active July 29, 2023 10:12
Custom Jetpack Compose ModalDrawer to support Left and Right alignments
package com.iamutkarshtiwari.ds.component.drawer
import androidx.annotation.FloatRange
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope