Skip to content

Instantly share code, notes, and snippets.

View jmadaminov's full-sized avatar

Jakhongir Madaminov jmadaminov

View GitHub Profile
@jmadaminov
jmadaminov / BackgroundShader
Created April 20, 2023 10:43
Liquid like AGSL shader effect
import android.graphics.Bitmap
import android.graphics.BitmapShader
import android.graphics.RuntimeShader
import android.graphics.Shader
import android.os.Build
import androidx.compose.animation.core.withInfiniteAnimationFrameMillis
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.getValue
import androidx.compose.runtime.produceState
import androidx.compose.ui.Modifier
@jmadaminov
jmadaminov / BackgroundShader.kt
Created February 23, 2023 06:14
A modifier which can be used on a Box composable for fancy animated look - works only on Android 13
import android.graphics.Color
import android.graphics.RuntimeShader
import android.os.Build
import androidx.compose.animation.core.withInfiniteAnimationFrameMillis
import androidx.compose.runtime.getValue
import androidx.compose.runtime.produceState
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.graphics.Brush
@jmadaminov
jmadaminov / gist:5bb7d207ae263b9ae2ef7b7e3313d3e2
Last active November 1, 2022 14:28
UI-Event test ViewModel
const val SECONDS = 5
class MainViewModel : ViewModel() {
private var timerJob: Job? = null
private val _uiState = MutableStateFlow(MainUiState())
val uiState = _uiState.asStateFlow()
fun makeApiCall() {
timerJob?.cancel()
timerJob = viewModelScope.launch {
@jmadaminov
jmadaminov / gist:8ffec6b7c16847b73b3afd1a4a0fb40a
Last active November 1, 2022 14:38
UI-Event through UiState
@Composable
private fun MainScreen(viewModel: MainViewModel) {
val context = LocalContext.current
val uiState = viewModel.uiState.collectAsState()
Box(modifier = Modifier.fillMaxSize()) {
Text(
modifier = Modifier
.align(Alignment.TopCenter)
@jmadaminov
jmadaminov / drawPath.kt
Created May 22, 2022 21:16
Draw on path
val strokeColor = Color(0x80ffffff)
val transparent = Color.Transparent
drawPath(
path = path,
color = strokeColor,
style = Stroke(1f),
blendMode = BlendMode.Luminosity
// blendMode = BlendMode.Luminosity
)
drawPath(
val scrollState = rememberScrollState()
val items = listOf(1, 2, 3, 4)
Box {
Image(
bitmap = bg.asImageBitmap(),
contentDescription = "",
modifier = Modifier.fillMaxWidth()
)
We couldn’t find that file to show.
...
var screenWidthPx: Int
var screenWidthDp: Int
var cardWidthPx: Int
var cardWidthDp: Int
var cardHeightPx: Int
val cardHeightDp = 150
var cardMarginPx: Int
val cardMarginDp = 15
@jmadaminov
jmadaminov / MainActivity.kt
Created May 22, 2022 20:51
Glassmorphism in jetpack compose
package dev.jakhongirmadaminov.glassmorphic_sample
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.Image
import androidx.compose.foundation.background