Brian G
10/18/2021, 10:07 PMval state = rememberScrollState()
LaunchedEffect(state) {
snapshotFlow { state.value }.collect {
Log.v(TAG, "$it") // This is never called?
}
}
Box(Modifier.fillMaxSize().verticalScroll(state)) {
// ... Lot of box contents
}
Tomasz Krakowiak
10/18/2021, 10:30 PMScott Kruse
10/18/2021, 10:37 PMmattinger
10/19/2021, 12:13 AMTash
10/19/2021, 12:16 AM// Using derivedStateOf
fun nameA(name: String): State<String> {
return derivedStateOf { "Hello $name" }
}
// Using rememberUpdatedState
@Composable
fun nameA(name: String): State<String> {
return rememberUpdatedState("Hello $name")
}
prudhvi reddy
10/19/2021, 12:48 AMfragment with ComposeView
Fatal Exception: java.lang.IllegalStateException
ViewTreeLifecycleOwner not found from androidx.constraintlayout.widget.ConstraintLayout{aace22b V.E...... ......ID 0,0-1080,2358 #7f0a114e app:id/root}
versions used
fragment - 1.3.1
compose - 1.0.2
Arjun Achatz
10/19/2021, 1:51 AMMyCustomComposeView : AbstractComposeView
, in the split view, even if a select Custom view, nothing shows upmingkangpan
10/19/2021, 8:54 AMIcon(
painter = painterResource(id = R.drawable.ic_baseline_delete_24),
modifier = Modifier.align(Alignment.TopEnd)
.size(40.dp)
.padding(8.dp)
)
Still there is not inner padding applied somehow…Matti MK
10/19/2021, 9:16 AMButtonColors
based on the enabled
property value?
I have a button for which I’ve defined the disabled and enabled colors as shown below. How can I animate the color change when the enabled
property changes?
colors = ButtonDefaults.buttonColors(
backgroundColor = colors.primaryVariant,
disabledBackgroundColor = colors.secondaryVariant
),
jannis
10/19/2021, 9:38 AMdimsuz
10/19/2021, 11:26 AMDaniele Segato
10/19/2021, 11:51 AMLayout
and SubcomposeLayout
? what changes in performances?
Why do we need a SubcomposeLayout
for BoxWithConstraints
?
A lot of the time all you want is the size (width / height) of the composable, which you can get with Modifier.onSizeChanged {}
or Modifier.onGloballyPositioned {}
but it is asynchronous: you need to wait for the first composition before you get a callback to that, which means if you need the size of the widget to do something on the UI you'll have a flickering.
Can someone give me an in-depth answer or a link with an in-depth answer to these things?
What I'm most interest in is what are the drawback of using subcompositions and what are all the options to get the layout constraints / why we need subcomposition to get them before composing (modifiers have access to them).
EDIT: for instance IntrinsicSize
stop working if a child has BoxWithConstraints
right?
ThanksNapa Ram
10/19/2021, 12:16 PMAshu
10/19/2021, 12:33 PMVivek Sharma
10/19/2021, 12:35 PMMarcello Galhardo
10/19/2021, 1:42 PMdimensionResource
returns a DP value and it looks like there is no support to SP at all in the docs: https://developer.android.com/jetpack/compose/resourcesAnton Shilov
10/19/2021, 2:31 PMTransition
on a more granular level rather than current/target state? I'm trying to use Transition.playTimeNanos
and Transition.totalDurationNanos
. But total duration is calculated only in seek mode, which as I assume is reserved for tooling.
cc @Doris LiuChris Fillmore
10/19/2021, 3:58 PMBasicTextField
, while still enforcing singleLine
? I don’t want newline characters, and I don’t want the user to have to horizontal scroll.Rick Regan
10/19/2021, 5:39 PMBoxWithConstraints
to compute the number of a particular UI element that can fit on the screen. Let’s say I want two elements when the width is “portrait” and three when it is “landscape”. These elements display editable state that I want retained across rotations, so that when the third element is rotated off screen and then back on, it displays its old data. (My state is “global”, so I’m not talking about rememberSaveable
.)
The composable I've written that detects the rotation puts out the appropriate number of elements and then uses a SideEffect
to tell the state what the number of elements is. This seems backwards, since it’s like the state change is reacting to the UI change. (Another detail that may be relevant: I have a button that “tabs through” the visible elements, so that button’s callback needs to check the state to know what’s on screen.)
Now I’m thinking that instead I should use a LaunchedEffect
(with key the number of elements) to update the state and then use the number of elements as recorded in the state (rather than in the local variable as above) to generate the elements. This seems more natural, almost like making configuration change a callback. In any case, I wanted to ask about best practices before I got too far off track. Thanks.Danish Ansari
10/19/2021, 7:24 PMLazyVerticalGrid
is experimental. Is there any workaround to create grid list using LazyColumn
?Aram Sheroyan
10/19/2021, 11:51 PM@Immutable
data class CustomTypography(
val title_s: TextStyle = TextStyle(fontSize = 32.sp, color = CustomTheme.colors.customPrymaryColor)
)
but it says that Composable invocations can only happen from the context of composable function
Colton Idle
10/20/2021, 2:19 AMSpikey Sanju
10/20/2021, 3:51 AMstickyHeader
to LazyVerticalGrid
?
Is there any workaround solution for this?Mohammad Jahidul Islam
10/20/2021, 5:36 AMcarbaj0
10/20/2021, 8:48 AMClament John
10/20/2021, 8:57 AMsetContent {
val navController = rememberNavController()
NavHost(navController = navController, startDestination = "home") {
navigation(startDestination = "username", route = "login") {
// FIXME: I get an error here
val viewModel: LoginViewModel = viewModel()
composable("username") { ... }
composable("password") { ... }
composable("registration") { ... }
}
}
}
I get an error
@Composable invocations can only happen from the context of a @Composable functionNeed • The viewmodel should only be active in the NavGraph Scope. • When I go to a different route and come back I should initialize a new viewmodel (this is why I'm calling it in the NavGraph) Almost similar solution 1. Answer by [Philip Dukhov](https://stackoverflow.com/users/3585796/philip-dukhov) for the question [How to share a viewmodel between two or more Jetpack composables inside a Compose NavGraph?](https://stackoverflow.com/a/68857871/5698740) a. But in this approach the viewmodel stays in the scope of the activity that launched it and so is never garbage collected.
Colton Idle
10/20/2021, 10:05 AMZoltan Demant
10/20/2021, 10:37 AMNoSuchMethodError
after making tweaks to composables in my design system - cleaning & rebuilding the project fixes it (the design system is in a separate module). Any ideas on what I can do to narrow the issue down before I post a bug-report? 🧵👀Mehdi Haghgoo
10/20/2021, 11:39 AMJonas Frid
10/20/2021, 12:07 PMJonas Frid
10/20/2021, 12:07 PMLazyColumn(modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.clip(RoundedCornerShape(OneAppTheme.cornerRadius.listItemRadius.dp))
.background(OneAppTheme.colors.listItemColor.toColor())
) {
items(countries) {
Text(it.name)
}
}
But that is not a container around the items that will scroll with the items, it is styling on the LazyColumn itself.martinsumera
10/20/2021, 12:22 PMLazyColumn {
items(countries) { country ->
Box(modifier = Modifier.whatever()) {
Text(country.name)
}
}
}
Is this what you had in the mind?Jonas Frid
10/20/2021, 2:31 PMcb
10/20/2021, 4:03 PMSurface { Column { ... } }
. You can't add arbitrary background containers to a group of items.Jonas Frid
10/20/2021, 5:07 PM