Member-only story

Things to know about in Jetpack Compose.

Jayant Kumar🇮🇳
3 min readSep 25, 2023

--

Photo by AbsolutVision on Unsplash

In this article we will see some common things in jetpack compose

1). Get Context of the current screen

@Composable
fun FindContext() {

val context = LocalContext.current

Toast.makeText(context,"Hey",Toast.LENGTH_LONG).show()

}

We get the context through LocalContext.currrent composition local

2). Auto Focus on TextField

Get auto focus on textfield , when it visible for the first time.

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun FocusOnTextField(
modifier: Modifier = Modifier
) {

val focusRequester = remember { FocusRequester() }

LaunchedEffect(key1 = Unit) {
focusRequester.requestFocus()
}
Box(modifier = modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
TextField(
value = "",
onValueChange = {},
placeholder = { Text(text = "Enter username") },
modifier = Modifier.focusRequester(focusRequester)
)
}

}

--

--

Jayant Kumar🇮🇳
Jayant Kumar🇮🇳

Written by Jayant Kumar🇮🇳

Hello My name is Jayant Kumar, I am a software Engineer , specialist in Mobile Development (Android , IOS , Flutter , React Native and Ionic) from India 🇮🇳

No responses yet