Skip to content

Instantly share code, notes, and snippets.

View Nek-12's full-sized avatar
💭
I may be slow to respond.

Nek.12 Nek-12

💭
I may be slow to respond.
View GitHub Profile
@Nek-12
Nek-12 / DestinationScope.kt
Last active March 29, 2024 14:45
Koin <> Decompose Generic Component with injection
// warning - the descendants must be retained across config changes
@Stable
interface DestinationScope : KoinScopeComponent {
val coroutineScope: CoroutineScope
override fun equals(other: Any?): Boolean
override fun hashCode(): Int
}
val LocalDestinationScope = staticCompositionLocalOf<DestinationScope> {
@Nek-12
Nek-12 / DynamicBottomSheetScaffold.kt
Last active March 20, 2024 20:34
Dynamic non-modal bottom sheet for Compose that fixes existing issues with material3 implementation
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.windowInsetsPadding
@Nek-12
Nek-12 / StackNavigator.kt
Last active March 12, 2024 16:20
Decompose - Global navigation events with channel
internal class StackComponent(context: ComponentContext): Component {
private val results = Channel<NavResult<*>>(Channel.CONFLATED)
inline fun <reified R> sendResult(result: R) {
val config = stack.active.configuration
// or popWhile - bring desired page to the front
navigation.pop {
results.trySend(NavResult(config, result))
@Nek-12
Nek-12 / buld.gradle.kts
Created August 11, 2021 17:03
How to get your release application id as a buildConfig field
android {
defaultConfig {
applicationId = "com.nek.example" //be sure to follow the same order as here, or the id will be "null"
buildConfigField("String", "APPLICATION_ID_DEFAULT", "\"${android.defaultConfig.applicationId}\"")
//...
}
}
buildTypes {