RE
03/19/2023, 6:06 AMBox {
content()
top()
}
Lee Chun Hoe
03/19/2023, 8:17 AMModifier.pointerInput(Unit) {
detectTapGestures(
onPress = { onClick() },
onLongPress = { onClick() }
)
}
anshulnigam111
03/20/2023, 6:12 AMLaurynas Mykolaitis
03/20/2023, 6:37 AMNacho Ruiz Martin
03/20/2023, 8:27 AMStateFlow<String>
. This flow is collected inside a Composable with .collectAsState(Dispatchers.Main.immediate)
.
The string inside is used as the value of a BasicTextField
and the ViewModel has a function to update this value in the state.
All goes as expected if the user is the one typing on the keyboard 👍 but, if a button is pressed on the interface, the value of the text field should be cleared a new value should be added as some kind of prefix (editable by the user, just as a helper). When I add this value in the ViewModel, the cursor of the text field stays at the beginning instead of moving to the end of the text.
I have read this article: https://medium.com/androiddevelopers/effective-state-management-for-textfield-in-compose-d6e5b070fbe5. But I thought with Dispatchers.Main.immediate
it should be all good?
Thanks for the help.Alexander Maryanovsky
03/20/2023, 9:26 AM@Composable
private fun MyLayout(){
Box(Modifier.fillMaxSize().background(Color.Yellow)){
Box(modifier = Modifier
.background(Color.DarkGray)
.sizeIn(minWidth = 200.dp, minHeight = 200.dp)
) {
Text("BOX", modifier = Modifier.align(Alignment.Center))
}
}
}
Qamar Khan
03/20/2023, 12:19 PMval isAppInstalled = try {
packageManager.getApplicationInfo(appPackageName, 0)
true
} catch (e: PackageManager.NameNotFoundException) {
false
}
if (isAppInstalled) {
val launchIntent = packageManager.getLaunchIntentForPackage(appPackageName)
startActivity(launchIntent)
} else {
val playStoreIntent = Intent(
Intent.ACTION_VIEW,
Uri.parse(playStoreLink)
)
startActivity(playStoreIntent)
}
Tgo1014
03/20/2023, 12:31 PMdetectDragGestures
on the Red circle but I'm not sure I can detect when the blue one touched. I've tried pointerInteropFilter
but it doesn't give me any events from the blue ones. Any suggestions? 🙂Yacov Rosenberg
03/20/2023, 1:26 PMvide
03/20/2023, 8:16 PMTim Malseed
03/21/2023, 12:04 AMLaunchedEffect
to perform one-off navigation events, based on state. So, for example, if the current viewState
is Unauthorized
, I might use a LaunchedEffect
to call navigateToLoginScreen()
But, let’s say there are two of these launched effects, with two possible navigation destinations. I’ve noticed an issue where, if the viewState
updates and triggers a navigation event - the viewState
can again update before that navigation transition is complete - triggering yet another navigation event. This means my navigation can end up in an unexpected state.
Is there a way to ensure a LaunchedEffect is cancelled before the composition leaves the tree (like, during a navigation transition)?PHondogo
03/21/2023, 8:37 AMColton Idle
03/21/2023, 3:17 PMOmkar Amberkar
03/21/2023, 5:35 PMPrateek Kumar
03/21/2023, 5:53 PMvide
03/21/2023, 5:55 PMvide
03/21/2023, 8:53 PMjava.lang.IllegalStateException: Event can't be processed because we do not have an active focus target.
at androidx.compose.ui.focus.FocusOwnerImpl.dispatchKeyEvent-ZmokQxo(FocusOwnerImpl.kt:171)
EDIT: I have a hypothesis on why this is happening. I think it's a compose bug. Will write explanation in 🧵
EDIT 2: Debugged the root cause and created a minimal repro and recorded a demo of the crashundermark5
03/21/2023, 9:02 PM@Composable
fun MySectionedLazyList(viewModel: SectionedListViewModel) {
LazyColumn(modifier = Modifier.fillMaxSize()) {
viewModel.section1?.let {
items(items = it.items, key ={it.key}) {
Item1(it.data)
}
}
viewModel.section2?.let {
items(items = it.items, key ={it.key}) {
Item2(it.data)
}
}
viewModel.section3?.let {
items(items = it.items, key ={it.key}) {
Item3(it.data)
}
}
}
}
and I would like to scroll to the 5th item in section3
, but I don’t know it’s index, only it’s key, how would I accomplish such a task? Everything I’m seeing requires use of the item index, which while I could compute, it would be much easier if there was a way to scroll to an item with a specific key rather than just based off index.
Is this just functionality that I’d have to implement myself?xxfast
03/22/2023, 12:02 AMWindowInsets
via a CompositionLocal
?Justin Xu
03/22/2023, 1:28 AMNone of the following candidates is applicable because of receiver type mismatch
error in my Android Activity code, even though it builds and runs without issues. I've posted pictures of the exact errors below.
These are my imports for those two functions:
import androidx.activity.compose.setContent
import androidx.activity.viewModels
These are my gradle imports:
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.core:core-ktx:1.9.0")
// Lifecycle
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1")
Laurence Muller
03/22/2023, 1:35 AMLazyVerticalGrid
where the items are 2 x N
, is it possible for a given row to set both items to the max height of either row? My use case is that I have a tile where a title can wrap 1 or 2 rows. But I like the bottom divider and user image to be aligned at the bottom of the tile. I can’t set a fixed height because if both tiles have a title of 1 line or both have 2 lines, no adjustment is needed. Only when the left tile and right tile have a different number of lines, I would like to add a spacer or some way to push the divider + user image/details to the bottomchanjungskim
03/22/2023, 8:14 AMColton Idle
03/22/2023, 4:51 PM@Preview(uiMode = UI_MODE_NIGHT_YES)
@Composable
fun HelloWorldPreview() {
MaterialTheme() { Surface { Text("Hello kotlinglang") } }
}
Stylianos Gakis
03/22/2023, 6:06 PMColumnScope.AnimatedVisibility
gives this annoying problem of having to do double check for the state, since the content lambda does not give the current state. Like:
AnimatedVisibility(model != null) {
if (model != null) {
ActualComposable(model)
Spacer(Modifier.height(20.dp))
}
}
Since I am not sure if doing !!
in there is safe, as the old content may still be animating out, and it will call !!
on the null item to try and render the item as it’s leaving.
What do you folks usually do for this? Do I just have to do this double null check or is there something I can do instead, some API I may be missing?Tolriq
03/22/2023, 7:13 PMjava.lang.NoSuchMethodError: No static method AnimatedContent(Ljava/lang/Object;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Alignment;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)V in class Landroidx/compose/animation/AnimatedContentKt; or its super classes (declaration of 'androidx.compose.animation.AnimatedContentKt'
Caused by libraires compiled with previous versions is there a way to workaround without forking those libraries?John O'Reilly
03/22/2023, 8:02 PMFlowRow
to one in core Compose....this is what I had previously. From https://android-developers.googleblog.com/2023/03/whats-new-in-jetpack-compose-march-23-release.html, it seems equivalent is now horizontalArrangement = Arrangement.spacedBy(8.dp)
but with that I'm not see any vertical spacing.
FlowRow(crossAxisSpacing = 8.dp) {
session.tags.forEach { tag ->
Chip(tag)
}
}
andrew
03/22/2023, 8:20 PMBen Trengrove [G]
03/22/2023, 9:36 PMStylianos Gakis
03/22/2023, 10:40 PMresources()
marked as internal in androidx.compose.ui.res ?
I am in a place where I need to decide on a string to be used inside my ViewModel. As described here, I am only exposing the StringRes Int from there, and I need to then resolve that string inside my composable. Specifically, I am outside of a composable context since I am resolving it inside a lambda, so I can’t just use the stringResource()
function which uses this function internally.
So it turns out I need to do what stringResource()
does interally myself, which is
LocalConfiguration.current
return LocalContext.current.resources
So that I make sure I read LocalConfig in order to make sure I do not grab stale data.
resources()
already exists and does this exact thing, but it’s marked as internal, shouldn’t that just be a public function?jayjiang
03/23/2023, 8:08 AM