Tin Tran
02/18/2022, 3:21 AMjava.lang.IllegalStateException: pending composition has not been applied
with compose 1.1.0? . Full stack trace in 🧵Tin Tran
02/18/2022, 3:24 AMjava.lang.IllegalStateException: You cannot access the NavBackStackEntry's ViewModels after the NavBackStackEntry is destroyed.
Tin Tran
02/18/2022, 5:45 AM@Composable invocations can only happen from the context of a @Composable function
. It wasn’t the case in 1.1.0. Is this expected?
buildAnnotatedString{
withStyle(SpanStyle(....)){
append(" • ${stringResource(key = "key", defaultValue = "Open now")}") //won't compile
}
}
buildAnnotatedString {
append(stringResource(key = "key", defaultValue ="Work time")) //compile
}
Lance Gao
02/18/2022, 6:27 AMrember { mutableStateOf(mutableListOf<Int>())}
?Saurabh Khare
02/18/2022, 7:57 AMelye
02/18/2022, 8:33 AMUpdateTransition
animation being interupted half way, does it still retain its velocity for it’s subsequent animation (that interrupt it)? I think it should, as that’s what AnimateAsState
and Animatable
behave like. For more context, I provide a full code and some GIF animation to illustrate this clearer in https://stackoverflow.com/questions/71170430/will-updatetransition-animation-maintain-its-running-velocity-when-if-being-chanGerardo Ernesto Rodriguez Navar
02/18/2022, 10:01 AM@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()
linus muema
02/18/2022, 10:46 AMLokik Soni
02/18/2022, 11:13 AM@AndroidEntryPoint
class MainActivity : ComponentActivity() {
@Inject
lateinit var batteryBroadcast: BatteryBroadcast
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
BatteryAlarmGoldTheme {
val homeViewModel = hiltViewModel<HomeViewModel>()
lifecycle.addObserver(batteryBroadcast)
homeViewModel.setBatteryProfileData(batteryBroadcast.dataFlow)
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
BatteryAlarmGoldApp()
}
}
}
}
}
Now I want to use the same ViewModel in my compose to access that data. I am using NavHost for that currently
fun NavGraphBuilder.homeNavGraph(
navController: NavHostController
) {
navigation(startDestination = Screen.HomeScreen.route, route = HOME_ROUTE) {
composable(Screen.HomeScreen.route) {
val homeBackStackEntry = remember { navController.getBackStackEntry(HOME_ROUTE) }
val homeViewModel: HomeViewModel = hiltViewModel(homeBackStackEntry)
HomeScreen(
navController = navController,
viewModel = homeViewModel
)
}
composable(Screen.SelectRingtoneScreen.route) {
val homeBackStackEntry = remember { navController.getBackStackEntry(HOME_ROUTE) }
val homeViewModel: HomeViewModel = hiltViewModel(homeBackStackEntry)
RingtoneScreen(
viewModel = homeViewModel
)
}
}
}
Or there is any batter solution to achieve the same please suggest me.Mike Speed
02/18/2022, 11:16 AMLazyColumn
. I am updating the menuList State
in the ViewModel, the view recomposes but the debugger gets to LazyColumn and then stops, which means the children aren’t redrawn with the new data. Any ideas why? Thanks!
MyView:
val menuList = viewModel.menuData.observeAsState()
LazyColumn() {
items(menuList.value.size) { i->
MenuItem(menuList.value[i])
}
}
MyViewModel:
private var menu: MenuUiState? = null
val menuData: SingleLiveEvent<MenuUiState> by lazy { SingleLiveEvent() }
// ...
menu?.sections?.forEach {
//update menu properties here
}
menuData.value = menu?.copy()
Kamesh Yadav
02/18/2022, 12:52 PMMjahangiry75
02/18/2022, 2:26 PMSideEffect
gets triggered on every recomposition
so it works fine in the code below(triggered only once when MainScreen
starts composition), but if I uncomment the LaunchedEffect
the SideEffect
block will get triggered whenever the count
state changes, while if I comment the LaunchedEffect
block it will not. why?Zoltan Demant
02/18/2022, 3:18 PMTextFields
after a long press? DisableSelection
exists and works for Text
, but not TextField
.Vsevolod Kaganovych
02/18/2022, 4:10 PMdimsuz
02/18/2022, 4:12 PMBottomSheetScaffold
it's content
seems to "steal" clicks even if it's empty. View below this scaffold doesn't receive them. is there an option to make them pass through content
?David Corrado
02/18/2022, 5:23 PMaoriani
02/18/2022, 7:34 PMtheapache64
02/19/2022, 1:04 PMAlexander Maryanovsky
02/19/2022, 2:29 PMWindowState.position
of type WindowPosition
and WindowStateImpl
implements it as
override var position by mutableStateOf(position)
but from just looking at the WindowState
interface, there’s no way for you to know that position
can be observed.
Wouldn’t it better if the type of WindowState.position
was MutableState<WindowPosition>
?Tolriq
02/19/2022, 3:37 PMval playlistEntriesItems = remember(playlistEntries) {
Log.e("AAA", "Update entries")
playlistEntries.toMutableStateList()
}
Then use that state list in a LazyColumn. All works correctly and change to items order properly triggers recomposition. If that function is called again with a new playlistEntries the state is properly updated, but then the LazyColumn no more react on the changes. Am I missing something obvious?Landry Norris
02/19/2022, 6:03 PMMohammad Sianaki
02/20/2022, 11:35 AMLazyRow
:
val timerState = produceState(
initialValue = TimerCounter(0L, 0L, 0L),
key1 = product.id,
producer = {
withContext(Dispatchers.Default) {
val endTimeInMillis =
product.productDeal?.dealEndTime?.toTimeInMillis() ?: return@withContext
val endTimeInSeconds = endTimeInMillis / 1000
while (isActive) {
val currentTimeInSecond = System.currentTimeMillis() / 1000
if (endTimeInSeconds < currentTimeInSecond) {
value = TimerCounter(0L, 0L, 0L)
return@withContext
}
var reminders: Long
val durationInSeconds = endTimeInSeconds - currentTimeInSecond
val remainDays = durationInSeconds / DAY_IN_SECONDS
reminders = durationInSeconds % DAY_IN_SECONDS
val remainHours = ((reminders / HOURS_IN_SECONDS)) + (remainDays * 24)
reminders %= HOURS_IN_SECONDS
val remainMinutes = reminders / MINUTE_IN_SECOND
val remainSecond = reminders % MINUTE_IN_SECOND
value = TimerCounter(remainHours, remainMinutes, remainSecond)
delay(1000)
}
}
}
)
the above code is in composable which shows list item.
is this a right approach? in case not, which Effect
should?Marcin Wisniowski
02/20/2022, 12:09 PMCard
default elevation different from CardView
? In a mixed app, this makes the cards looks different, which looks especially bad in layouts that have both.Bradleycorn
02/20/2022, 11:20 PMcreateAndroidComposeRule()
?
I do not want or need to load my app’s main activity. That would load all of my application content, and this is a Unit Test for a single composable. But I need to get a string resource to test with.brabo-hi
02/21/2022, 1:54 AMRow {
AndroidView(factory = { context -> CustomView(context, "A") }, update = {})
AndroidView(factory = { context -> CustomView(context, "B") }, update = {})
Button(onClick = { swapViews() }) {
Text(text = "Swap view")
}
}
swapViews()
should swap both views. but it looks like i have to manually remove each view from parent. Should i call removeView()
in each update{}
? here is the error i am getting
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.`
Mehmet Peker
02/21/2022, 2:02 AMRene Win
02/21/2022, 7:20 AMColumn {
Box {
AnimatedVisibility(visible = true) {
Text("test")
}
}
}
This results into an error:
'fun ColumnScope.AnimatedVisibility(visible: Boolean, modifier: Modifier = ..., enter: EnterTransition = ..., exit: ExitTransition = ..., label: String = ..., content: AnimatedVisibilityScope.() -> Unit): Unit' can't be called in this context by implicit receiver. Use the explicit one if necessary
The provided fix from IDE is to annotate the AnimatedVisibility with
Column {
Box {
this@Column.AnimatedVisibility(visible = true) {
Text("test")
}
}
}
Then everything works fine. The question is why is this necessary? Is this the correct fix? Why cant I call this composable like every other composable?Hussain Saad
02/21/2022, 10:11 AMMohammad Sianaki
02/21/2022, 1:23 PMcontentType
in LazyColumn
? I’m trying to implement a multi type List, but I’m facing serious performance issueGuilherme Delgado
02/21/2022, 1:36 PMPointerInputScope.detectTransformGestures
to compute and apply some transformations to a composable
but I need to know when the user stops touching the screen.
I was thinking in combining it with PointerInputScope.detectDragGestures
and listen for onDragEnd
but only one is used.
1 - Is is possibile to combine “Gestures”?
2 - What’s the best approach for what I want?
thx.Guilherme Delgado
02/21/2022, 1:36 PMPointerInputScope.detectTransformGestures
to compute and apply some transformations to a composable
but I need to know when the user stops touching the screen.
I was thinking in combining it with PointerInputScope.detectDragGestures
and listen for onDragEnd
but only one is used.
1 - Is is possibile to combine “Gestures”?
2 - What’s the best approach for what I want?
thx.Albert Chang
02/21/2022, 3:44 PMdetectTransformGestures
.Guilherme Delgado
02/21/2022, 4:34 PMsuspend fun PointerInputScope.detectTransformGestures(
panZoomLock: Boolean = false,
onEvent: (event: PointerEvent) -> Unit, <<<<<<<<<<<<<<<<<<<<<<<<<
onGesture: (centroid: Offset, pan: Offset, zoom: Float, rotation: Float) -> Unit
) { ... }