Skip to content

Instantly share code, notes, and snippets.

View AndroidPoet's full-sized avatar
🎯
Focusing

Ranbir Singh AndroidPoet

🎯
Focusing
View GitHub Profile
//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")
}
//function we call in our code
@Composable
@NonRestartableComposable
@OptIn(InternalComposeApi::class)
fun LaunchedEffect(
key1: Any?,
block: suspend CoroutineScope.() -> Unit
) {
val applyContext = currentComposer.applyCoroutineContext
@Composable
fun rememberMapViewWithLifecycle() {
DisposableEffect(key1 = lifecycle, key2 = mapView) {
// Make MapView follow the current lifecycle
val lifecycleObserver = getMapLifecycleObserver(mapView)
lifecycle.addObserver(lifecycleObserver)
onDispose {
}
@Composable
fun DemoCoroutineScope() {
val scope = rememberCoroutineScope()
Button(onClick = {
scope.launch {
//CoroutineScope
//run any suspend functions inside this scope
@Composable
fun DemoLaunchedEffect(key1: String, key2: String, key3: String, list: Array<String>) {
LaunchedEffect(key1 = key1) {
//CoroutineScope
}
LaunchedEffect(key1 = key1, key2 = key2) {
//CoroutineScope
@Composable
fun TestComposable(modifier: Modifier = Modifier, data: () -> Unit) {
//scope of the composebale
//
}
@Composable
fun SecondRootComposable() {
Box(Modifier.fillMaxSize()) { // Recomposition Scope Start
val scroll = rememberScrollState(0)
Title(snack = snack, scrollProvider = {scroll.value })
}
}
@Composable
fun SecondRootComposable() {
Box(Modifier.fillMaxSize()) { // Recomposition Scope Start
val scroll = rememberScrollState(0)
Title(snack = snack,scroll=scroll.value)
}
}
var name by remember { mutableStateOf("") }
@Composable
fun TextFieldDemo() {
Column(Modifier.padding(16.dp)) {
val textState = remember {mutableStateOf(mutableStateOf(""))}
TextField(
value = textState.value,
onValueChange = { textState.value = it }
)
Text("The textfield has this text:textState.value.text)
}