hfhbd
02/09/2022, 8:09 PMCompositionLocalProvider
?
https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#CompositionLocalProvider(kotlin.Array,kotlin.Function0)Jeff Jackson
02/09/2022, 9:04 PMDropdownMenuItem
s where one has a selection state (check mark)?brabo-hi
02/09/2022, 9:36 PMChris Johnson
02/09/2022, 11:04 PMremember { X }
inside LazyColumn/Row items and the next time you scroll to that item it remembers that state. Or maybe I've gotten lucky in that and there's a cache amount that I haven't scrolled past yet.Zoltan Demant
02/10/2022, 5:22 AMNo static method stickyHeader$default
after upgrading to 1.2.0-alpha03
. Seems to only affect my design systems module, e.g. I can place a LazyColumn
with stickyHeaders in other modules just fine. Proguard is temporarily disabled, and my dependencies are exactly identical between the modules. Any other clues as to what I should look for (Ive tried invalidate caches + clean)?Gerardo Ernesto Rodriguez Navar
02/10/2022, 6:31 AMOG
02/10/2022, 8:13 AMgalex
02/10/2022, 8:36 AM@Composable
outside of setContent {}
so that I could get the size of one child Composable
within?
I don’t care doing that in the UI thread right now, just want to know if it’s possible!Tolriq
02/10/2022, 9:43 AMArpit Shukla
02/10/2022, 10:47 AMTim Malseed
02/10/2022, 12:34 PMTrym Nilsen
02/10/2022, 2:16 PMSelectionContainer { Text(...) }
right now it only selects the word that was pressed.martinsumera
02/10/2022, 3:22 PMNathaniel Rowe
02/10/2022, 4:58 PMViewModel has no zero argument constructor
error when trying to construct a hilt view model in a compose function. Anyone else experiencing this? I'm not using the jetpack navigation component, just trying to inject a view model scoped to LocalViewModelStoreOwner.current. I get this error when trying to inject even a simple class with no sub-dependencies.
My view model is provided like this: viewModel: MyViewModel = viewModel()
, and I'm using the @HiltViewModel annotation on my view model. My activity and application all support hilt injection properly. I'm using the "androidx.lifecycle:lifecycle-viewmodel-compose" dependency for creating my view model. Let me know if you need more information.
Edit: this also only happens when trying to create the view model with any injected dependencies. If the view model has no dependencies, it works fine. The hiltViewModel()
is only supposed to be used with the navigation component, which I am not using. I am using an alternate navigation library (this one: https://github.com/olshevski/compose-navigation-reimagined), but from my understanding, it sets the LocalViewModelStoreOwner properly, and that's what the viewModel()
function uses. I'm assuming it's something to do with the view model factory.Rajashekar
02/10/2022, 5:30 PMScaffold(
floatingActionButton = {
FloatingDialButton(
keyboardController,
focusRequester
)
},
modifier = Modifier.focusRequester(focusRequester)
) {
ScreenContent(uiState)
}
@Composable
fun FloatingDialButton(
keyboardController: SoftwareKeyboardController?,
focusRequester: FocusRequester,
) {
FloatingActionButton(
onClick = {
focusRequester.requestFocus()
keyboardController?.show()
},
) {
Icon(
painterResource(id = R.drawable.ic_dialpad),
contentDescription = "",
tint = MaterialTheme.colors.onSecondary
)
}
}
Matthew Laser
02/10/2022, 5:44 PMViewModel
, along with a data class MyUIState
. I’m initializing my property as such: var uiState by mutableStateOf(MyUiState.empty)
. , where empty
is just a default initializer with default values.
I’m then updating individual properties of uiState
as events happen, for instance uiState.loading = true
The `ViewModel`s is passed into my composable MyScreen
as such from MyActivity
setContent { MyScreen(viewModel) }
Finally, inside of my composable MyScreen
I'm doing val uiState = viewModel.uiState
and driving changes off of those values, for instance if (uiState.loading)
- however, this is the point at which they aren't recomposed.
Most of the examples I can find use a very simple value like mutableStateOf(true)
, so I'm assuming there is something going on where just updating a property isn't having the right effect.Alderson Elliot
02/10/2022, 6:52 PMAlderson Elliot
02/10/2022, 7:17 PMVahalaru
02/11/2022, 12:39 AMLaunchedEffect
will cancel and re-launch if
// scaffoldState.snackbarHostState
changes
LaunchedEffect(scaffoldState.snackbarHostState) {
// Show snackbar using a coroutine, when the coroutine is cancelled the
// snackbar will automatically dismiss. This coroutine will cancel whenever
// state.hasError
is false, and only start when state.hasError
is true
// (due to the above if-check), or if scaffoldState.snackbarHostState
changes.
scaffoldState.snackbarHostState.showSnackbar(
message = "Error message",
actionLabel = "Retry message"
)
}
}
Scaffold(scaffoldState = scaffoldState) {
/* ... */
}
}Guilherme Delgado
02/11/2022, 12:03 PMinit {}
it’s called twice.
I’m using jetpack compose (1.1.0 and it happened also with 1.1.0-rc01):
• ActivityA has ViewModelA and everything is ok.
• ActivityB has a AnimatedNavHost
with 3 composable (“screens”). When they’re first created I get this 2 time problem, but after that, when I change between them, the init {}
is called only once as expected.
What could it be?Andrew Leung
02/11/2022, 5:32 PMjava.lang.IllegalStateException: You cannot access the NavBackStackEntry's ViewModels after the NavBackStackEntry is destroyed.
at androidx.navigation.NavBackStackEntry.getViewModelStore(NavBackStackEntry.kt:207)
at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost(AnimatedNavHost.kt:144)
at com.google.accompanist.navigation.animation.AnimatedNavHostKt$AnimatedNavHost$11.invoke(Unknown Source:23)
at com.google.accompanist.navigation.animation.AnimatedNavHostKt$AnimatedNavHost$11.invoke(Unknown Source:10)
at androidx.compose.runtime.RecomposeScopeImpl.compose(RecomposeScopeImpl.kt:140)
at androidx.compose.runtime.ComposerImpl.recomposeToGroupEnd(Composer.kt:2158)
at androidx.compose.runtime.ComposerImpl.skipCurrentGroup(Composer.kt:2404)
at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:2585)
at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:2571)
at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:247)
at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(Unknown Source:1)
at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:2571)
at androidx.compose.runtime.ComposerImpl.recompose$runtime_release(Composer.kt:2547)
at androidx.compose.runtime.CompositionImpl.recompose(Composition.kt:620)
at androidx.compose.runtime.Recomposer.performRecompose(Recomposer.kt:786)
at androidx.compose.runtime.Recomposer.access$performRecompose(Recomposer.kt:105)
This is on latest 2.5.0-alpha01, but was also occurring on 2.4.0-alpha01 (but with a different error message)Mehdi Haghgoo
02/11/2022, 5:58 PMEvgeny Taskaev
02/11/2022, 7:05 PMsamp
02/11/2022, 9:08 PMLandry Norris
02/11/2022, 9:31 PMcaused by java.lang.RuntimeException: Method allowThreadDiskReads in android.os.StrictMode not mocked
. I wrote a simple test (in thread), which reproduced the issue. This only started when I added Compose tests.oday
02/11/2022, 9:48 PMjames
02/12/2022, 12:16 AMTextField
once my ModalBottomSheet
is shown, is using the `ModalBottomSheetState`'s confirmStateChange
the correct place to do that, or is there a better place? I understand it can work but it doesn't necessarily feel right.. is there a listener I can use which signals "the modal bottom sheet has finished appearing"?Nathaniel Rowe
02/12/2022, 4:11 AMActivity.isChangingConfigurations
property, but is this reliable? Or should I just make sure to add a call to cancel jobs at every point where a navigation event happens, and make sure no navigation events happen higher up in the composition hierarchy?
2. What is the best practice for the view model communicating a nav event to the composable? I have a single UI state object for each screen, should I include a "nav event" property in the UI state? And how can I ensure this nav event only triggers up to one actual navigation event? I was thinking of creating an object which is like a "OneShotEvent" object, which has a "consume" method that suspends, and only consumes events that weren't already consumed. Or would a SharedFlow with no replay cache, or some application of producer channels be more idiomatic?james
02/12/2022, 11:11 AMHalfExpanded
. if I only open it half way, show the keyboard, then hide the keyboard, nothing strange happens.. but if I open it to Expanded
, then as soon as I hide that keyboard, it re-animates back onto screen 🤯Tolriq
02/12/2022, 12:24 PMTolriq
02/12/2022, 12:24 PM