ste
07/25/2022, 5:34 PMAlex Vanyo
07/25/2022, 6:16 PMMutableStateFlow<MyUiEvent>
, it reads like you are prolonging the handling of an event and keeping it in-flight for longer to be handled later. When you call triggerEvent
, that sort of reads as “tell the UI to do this thing” (both of which are antipatterns as described in the article)
Telling the UI to do something is not directly possible. If the UI isn’t available, then multiple calls to triggerEvent
will clear out the previous “event” that was sent, without it being handled. Maybe that’s what you want, and maybe not, depending on the exact situation. Another weird issue that might happen because block
is suspending: What happens if, while block
is in the middle of running, triggerEvent
is called again?
I would try to turn triggerEvent
into updating some state that more accurately reflects why you want to go to a different screen. Then, the LaunchedEffect
reads more like “I am currently showing this Composable
, and the state I am getting from the ViewModel
says Y. Therefore, I should navigate somewhere else, and maybe tell the ViewModel
I did so”Sean McQuillan [G]
07/25/2022, 6:45 PMParagraph
?
class MyParagraph: Paragraph {...}
If so, can you share a bit more about what you're doing and why you chose not to wrap it?
class MyParagraphWrapper(val paragraph: Paragraph)
Jasmin Fajkic
07/25/2022, 7:05 PMDaniel Rotenberg
07/25/2022, 8:59 PMzt
07/26/2022, 3:32 AMLazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 14.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
items(videoListItems) { video ->
if (video == null) return@items
VideoCard(
video = video,
onClick = { onClickVideo(video.id) },
onClickChannel = { onClickChannel(video.author!!.id) }
)
}
item {
videoListItems.loadState.apply {
when (append) {
is LoadState.Loading -> {
CircularProgressIndicator(modifier = Modifier.padding(4.dp))
}
is LoadState.Error -> {
(append as LoadState.Error).error.printStackTrace()
Text("An error has occurred")
}
else -> Unit
}
}
}
}
Colton Idle
07/26/2022, 4:53 AMBottomNavigation {
items.forEachIndexed { index, item ->
BottomNavigationItem(
icon = { Icon(Icons.Filled.Favorite, contentDescription = null) },
label = { Text(item) },
selected = selectedItem == index,
onClick = { selectedItem = index }
)}}
but on samsung devices (which are typically "zoomed in" out of the box) the text and icon overlap. If I try to increase the icon size (or add padding) then it grows larger than the bottomBar can support and so my icons are cut off. Surprisingly the BottomNavigationBar doesn't grow in height to support the larger text size or icon size. Is there any "right" way to fix this or should I look to implement an autosize text for the tab text?allan.conda
07/26/2022, 7:31 AMremeasure
instead. Is there an optimization happening somewhere for scrolling?Stylianos Gakis
07/26/2022, 9:46 AMvar width by remember { mutableStateOf(0f) } // 0f or 0 or 0.dp not sure what I need yet
var height by remember { mutableStateOf(0f) }
Canvas can get you a size but can only set it on the next frame to the local state as I understand.
Canvas(Modifier.fillMaxSize()) {
width = this.size.width
height = this.size.height
}
OnGloballyPositioned also on the next frame
.onGloballyPositioned { it.size.height | width }
BoxWithConstraints uses subcomposition.
My use case is trying to get the bounds of my Canvas in order to animate something that’s moving inside of it and make sure it’s not going outside.
What other options do I have? Or is getting it from canvas and saving it to a local state the way to go? Also what if I was not using a Canvas anyway, what other alternatives are there?Lukasz Kalnik
07/26/2022, 12:42 PMProgrammistich
07/26/2022, 3:44 PMcombinedClickable()
have onClick/onDouble/onLong but dont have onHoldLokik Soni
07/26/2022, 6:00 PMval isAlarmOn by viewModel.alarmBtnState.collectAsState()
In ViewModel
val alarmBtnState = isAlarmActivated(Unit).map {
it.successOr(DEF_VAL_ALARM_ACTIVATED)
}.stateIn(viewModelScope, WhileViewSubscribed, DEF_VAL_ALARM_ACTIVATED)
Chuck Stein
07/26/2022, 7:45 PMLazyList
is still under development, but what's the recommendation for animating insertions/deletions into a regular Column
or Row
?Raymond
07/26/2022, 8:09 PMdeviant
07/27/2022, 10:54 AMcompose.material
and compose.material3
in same project (same screen)?Arkadii Ivanov
07/27/2022, 10:55 AMJi Sungbin
07/27/2022, 1:18 PMliveLiterals
plugin option? When I try to apply it, I get this error: Multiple values are not allowed for plugin option androidx.compose.compiler.plugins.kotlin:liveLiterals.
freeCompilerArgs += [
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:liveLiterals=false"
]
jasu
07/27/2022, 1:35 PMcompose-hilt-navigation
and in one of the screens i’m using BackHandler(onBack = someCall). Somecall is not getting called any idea?
inshort: back handler is not workingRafs
07/27/2022, 5:16 PMFlowRow/Column
but they aren’t available anymore.Ale Stamato
07/27/2022, 5:17 PMBenjamin Deroche
07/27/2022, 7:21 PMArrowCircleLeft
and ArrowCircleRight
icons missing from Android Compose? I use all 4 of them (left, top, right, bottom) in my Kotlin Multiplatform app for Android and JVM. Android Studio show no error, the JVM app compile and run just fine, but the Android app fail to compile because I get an unresolved reference for left and right arrowsitnoles
07/27/2022, 8:02 PMHarold Scissors
07/27/2022, 8:28 PMrepeatOnLifecycle
removed from lifecycle-runtime-ktx
? I'm looking to solve an issue where we need link produceState
based on lifecycle events within a composable function.Harold Scissors
07/27/2022, 11:23 PMLifecycle.State.RESUMED
? I tried this which was posted before on similar threads but it seems because produceState
conflates value
, only the first value causes recomposition. So, on the first resume, we see the value, on the second (if it is the same) we see nothing. Ideally, we'd want to see it on every RESUMED
even if it is the same.oianmol
07/28/2022, 3:51 AMTin Tran
07/28/2022, 4:34 AMModalBottomSheetState
to ViewModel?Ali Khaleqi Yekta
07/28/2022, 5:46 AMKazik
07/28/2022, 6:23 AMLaunchedEffect(Unit) {
navController.currentBackStackEntryFlow
.filter { it.destination.route == parentRoute }
.collect { onClose() }
}
zt
07/28/2022, 6:36 AMArun Joseph
07/28/2022, 6:52 AMaccompanist-navigation-animation
and rotation, I observe that the obtained viewmodel
leaks when transitions between screens, when each screen forces certain orientation. Sample code in thread.Arun Joseph
07/28/2022, 6:52 AMaccompanist-navigation-animation
and rotation, I observe that the obtained viewmodel
leaks when transitions between screens, when each screen forces certain orientation. Sample code in thread.class AppActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
SampleNavHost()
}
}
}
@Composable
fun SampleNavHost() {
val navController = rememberAnimatedNavController()
AnimatedNavHost(
navController = navController,
startDestination = "ScreenA",
) {
composable("ScreenA") {
val viewModel: ScreenAViewModel = viewModel()
val context = LocalContext.current
LaunchedEffect(key1 = Unit) {
context.tryFindActivity()?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
}
Button(
onClick = {
navController.popBackStack()
navController.navigate("ScreenB")
},
content = {
Text("Navigate to ScreenB")
}
)
}
composable("ScreenB") {
val viewModel: ScreenBViewModel = viewModel()
val context = LocalContext.current
LaunchedEffect(key1 = Unit) {
context.tryFindActivity()?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
}
Button(
onClick = {
navController.popBackStack()
navController.navigate("ScreenA")
},
content = {
Text("Navigate to ScreenA")
}
)
}
}
}
class ScreenAViewModel : ViewModel() {
override fun onCleared() {
println("onCleared $this")
super.onCleared()
}
init {
println("onCreated $this")
}
}
class ScreenBViewModel : ViewModel() {
override fun onCleared() {
println("onCleared $this")
super.onCleared()
}
init {
println("onCreated $this")
}
}
fun Context.tryFindActivity(): Activity? {
var context = this
while (context is ContextWrapper) {
if (context is Activity) return context
context = context.baseContext
}
return null
}
NavHost
2022-07-28 08:38:22.523 14687-14687 System.out I onCreated com.tomtom.roadcaptain.home.presentation.ScreenAViewModel@30e43db
2022-07-28 08:38:25.694 14687-14687 System.out I onCreated com.tomtom.roadcaptain.home.presentation.ScreenBViewModel@7939130
2022-07-28 08:38:26.428 14687-14687 System.out I onCleared com.tomtom.roadcaptain.home.presentation.ScreenAViewModel@30e43db
2022-07-28 08:38:45.367 14687-14687 System.out I onCreated com.tomtom.roadcaptain.home.presentation.ScreenAViewModel@a2852cc
2022-07-28 08:38:46.084 14687-14687 System.out I onCleared com.tomtom.roadcaptain.home.presentation.ScreenBViewModel@7939130
AnimatedNavHost
2022-07-28 08:48:02.868 15669-15669 System.out I onCreated com.tomtom.roadcaptain.home.presentation.ScreenAViewModel@66faa0b
2022-07-28 08:48:05.696 15669-15669 System.out I onCreated com.tomtom.roadcaptain.home.presentation.ScreenBViewModel@5b834d9
2022-07-28 08:48:14.797 15669-15669 System.out I onCreated com.tomtom.roadcaptain.home.presentation.ScreenAViewModel@1ef23a5