Skip to content

Instantly share code, notes, and snippets.

View zarini's full-sized avatar

Amir KhodadadZarini zarini

  • AsanPardakht
  • Tehran, Iran
View GitHub Profile
@zarini
zarini / SuspendRunner.kt
Last active April 6, 2024 18:13
Now you can call every kotlin suspend function in java code if you want to block until function call finished
@file:kotlin.jvm.JvmName("SuspendRunner")
import kotlinx.coroutines.*
import java.util.concurrent.FutureTask
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import kotlin.coroutines.CoroutineContext
/**
@zarini
zarini / BackButtonHandler.kt
Last active September 4, 2021 06:54
Compose back button handler
@Composable
fun BackButtonAction(onBackPressed: () -> Unit) {
CompositionLocalProvider(
localBackPressedDispatcher provides (
LocalLifecycleOwner.current as ComponentActivity
).onBackPressedDispatcher
) {
BackButtonHandler {
onBackPressed.invoke()
}