Flow Type | Purpose | Key Features | Use Case |
---|---|---|---|
flow {} |
Creates a cold flow that emits values lazily. | Emits values only when collected. Supports suspending functions. |
Creating custom flows to emit data on demand. |
flowOf() |
Creates a flow from a fixed set of values. | Emits provided values sequentially. Cold by nature. |
Emit predefined values (e.g., configuration settings). |
asFlow() |
Converts collections, sequences, arrays, or ranges to flows. | Supports many standard types. Cold by nature. |
Convert lists or arrays into flows for processing. |
`c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.compose.animation.core.* | |
import androidx.compose.foundation.Canvas | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.layout.* | |
import androidx.compose.material.Text | |
import androidx.compose.runtime.* | |
import androidx.compose.ui.Alignment | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.geometry.Offset | |
import androidx.compose.ui.geometry.Size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[versions] | |
compose = "1.7.0-alpha01" | |
[libraries] | |
compose = { id = "org.jetbrains.compose", version.ref = "compose" } | |
[plugins] | |
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } | |
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } | |
compose = { id = "org.jetbrains.compose", version.ref = "compose" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//settings.gradle.kts | |
dependencyResolutionManagement { | |
repositories { | |
maven { url = uri("https://androidx.dev/snapshots/builds/11670047/artifacts/repository/") } | |
google() | |
mavenCentral() | |
maven(url = "https://plugins.gradle.org/m2/") | |
maven(url = "https://maven.pkg.jetbrains.space/public/p/compose/dev") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//function we call in our code | |
@Composable | |
@NonRestartableComposable | |
@OptIn(InternalComposeApi::class) | |
fun LaunchedEffect( | |
key1: Any?, | |
block: suspend CoroutineScope.() -> Unit | |
) { | |
val applyContext = currentComposer.applyCoroutineContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun rememberMapViewWithLifecycle() { | |
DisposableEffect(key1 = lifecycle, key2 = mapView) { | |
// Make MapView follow the current lifecycle | |
val lifecycleObserver = getMapLifecycleObserver(mapView) | |
lifecycle.addObserver(lifecycleObserver) | |
onDispose { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun DemoCoroutineScope() { | |
val scope = rememberCoroutineScope() | |
Button(onClick = { | |
scope.launch { | |
//CoroutineScope | |
//run any suspend functions inside this scope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun DemoLaunchedEffect(key1: String, key2: String, key3: String, list: Array<String>) { | |
LaunchedEffect(key1 = key1) { | |
//CoroutineScope | |
} | |
LaunchedEffect(key1 = key1, key2 = key2) { | |
//CoroutineScope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun TestComposable(modifier: Modifier = Modifier, data: () -> Unit) { | |
//scope of the composebale | |
// | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun SecondRootComposable() { | |
Box(Modifier.fillMaxSize()) { // Recomposition Scope Start | |
val scroll = rememberScrollState(0) | |
Title(snack = snack, scrollProvider = {scroll.value }) | |
} | |
} |
NewerOlder