How to share a viewmodel between two or more Jetpack composables inside a Compose NavGraph?

You can to pass your top viewModelStoreOwner to each destination directly passing to .viewModel() call, composable(“first”) in my example overriding LocalViewModelStoreOwner for the whole content, so each composable inside CompositionLocalProvider will have access to the same view models, composable(“second”) in my example val viewModelStoreOwner = checkNotNull(LocalViewModelStoreOwner.current) { “No ViewModelStoreOwner was provided via LocalViewModelStoreOwner” } val … Read more

How to set the Scaffold Drawer Width in JetpackCompose?

You can modify the shape (including width and height) using drawerShape parameter in Scaffold method. So for instance Scaffold( scaffoldState = scaffoldState, drawerContent = { Text(“Drawer content”) }, drawerShape = customShape(), content = {inner padding -> /* Body*/} ) Then your customShape function fun customShape() = object : Shape { override fun createOutline( size: Size, … Read more

Jetpack Compose LazyColumn – How to update values of each Item seperately?

Create a mutableStateListOf(…) (or mutableStateOf(listOf(…)) object if the former does not support your data type) in your ViewModel. Now, access this state from the composable you wish to read it from, i.e., your LazyColumn. Inside your ViewModel, you can set the values however you wish, and they will be updated in the Composable as and … Read more

How can I detect keyboard opening and closing in jetpack compose?

Update With the new WindowInsets API, it gets easier First, to return the correct values, you need to set: WindowCompat.setDecorFitsSystemWindows(window, false) Then to use Keyboard as a state: @Composable fun keyboardAsState(): State<Boolean> { val isImeVisible = WindowInsets.ime.getBottom(LocalDensity.current) > 0 return rememberUpdatedState(isImeVisible) } use example: val isKeyboardOpen by keyboardAsState() // true or false ps: I’ve tried … Read more