Skip to content

Instantly share code, notes, and snippets.

View Kiolk's full-sized avatar
🏠
Working from home

Yauheni Slizh Kiolk

🏠
Working from home
View GitHub Profile
@Kiolk
Kiolk / Spring Animation.txt
Last active February 20, 2026 20:44
Spring Animation
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessMediumLow,
visibilityThreshold = 0.001f,
),
@Kiolk
Kiolk / Animation Preview.txt
Last active February 20, 2026 20:44
Animation Preview
@Preview(showBackground = true, name = "Animation")
@Composable
private fun BouncingProgressAnimationPreview() {
var progress by remember { mutableIntStateOf(0) }
LaunchedEffect(Unit) {
while (true) {
progress = 0
delay(600)
progress = 60
@Kiolk
Kiolk / Simple ProgressBar.txt
Last active February 20, 2026 20:43
BouncingProgressPreview
private class ProgressPreviewProvider : PreviewParameterProvider<Float> {
override val values = (0..100 step 10).map { it / 100f }.asSequence()
}
@Preview(showBackground = true, uiMode = UI_MODE_NIGHT_NO, name = "Light")
@Preview(showBackground = true, uiMode = UI_MODE_NIGHT_YES, name = "Dark")
@Composable
private fun BouncingProgressPreview(
@PreviewParameter(ProgressPreviewProvider::class) progress: Float,
) {
@Kiolk
Kiolk / Simple ProgressBar.txt
Last active February 20, 2026 20:42
Simple ProgressBar
Box(
modifier = modifier
.fillMaxWidth()
.height(height)
.clip(RoundedCornerShape(50))
.background(trackColor)
) {
Box(
modifier = Modifier
.fillMaxWidth(animatedProgress)
@Kiolk
Kiolk / Animation Preview for ProgressBar.txt
Last active March 5, 2026 13:36
Animation Preview for ProgressBar
import android.content.res.Configuration.UI_MODE_NIGHT_NO
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.spring
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@Kiolk
Kiolk / ShowMoreComposable.kt
Last active December 19, 2024 21:42
How to Handle the "More" Feature on Android?
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
@Kiolk
Kiolk / AuthenticationPlugin.txt
Last active October 6, 2024 13:31
A simple way to set a token for requests using Ktor
import io.ktor.client.plugins.api.ClientPlugin
import io.ktor.client.plugins.api.createClientPlugin
class AuthenticationPlugin(private val settingsRepository: SettingsRepository) {
fun createPlugin(): ClientPlugin<Unit> {
val token = settingsRepository.getToken()
return createClientPlugin(PLUGIN_NAME) {
onRequest { request, _ ->
@Kiolk
Kiolk / CoroutineWithFlow.kt
Created October 4, 2020 20:48
Example coroutine with Flow
abstract class BaseFlowUseCase<out Type, in Params> {
abstract suspend fun execute(param: Params): Flow<Type>
}
override suspend fun getNumberInvites(): Flow<Int> {
return local.getNumberInvites()
}
override suspend fun getNumberInvites(): Flow<Int> {
@Kiolk
Kiolk / GoalDataSource.kt
Created October 4, 2020 20:02
Use coroutine outside viewModelScope
class GoalDataSource(private val getReactGoalsUseCase: GetReactGoalsUseCase) :
PositionalDataSource<Goal>() {
override fun loadRange(params: LoadRangeParams, callback: LoadRangeCallback<Goal>) {
CoroutineScope(Dispatchers.Main).launch {
getReactGoalsUseCase.invoke(this, GetReactGoalsUseCase.Param(params.startPosition)) {
it.either({}, { goals: List<Goal> ->
callback.onResult(goals)
})
}
@Kiolk
Kiolk / BaseUseCase.kt
Last active October 4, 2020 19:56
Coroutines Example: Base UseCase with coroutine
abstract class BaseUseCase<in Param, out Type> where Type : Any {
abstract suspend fun run(param: Param): Either<Failure, Type>
open val dispatcher: CoroutineDispatcher = Dispatchers.Main
open operator fun invoke(
scope: CoroutineScope,
param: Param,
result: (Either<Failure, Type>) -> Unit = {}