Sam
10/26/2022, 8:50 PMursus
10/26/2022, 8:57 PMonX
colors have some sort of weird tint when used implcitly?
I have a parent surface whose color is set to MaterialTheme.colors.primary
, and then just a simple Text
where its inferred text color should be onPrimary
and it some off-white, when it should be pure white
If I have another Text
on top of it which color explicitly set to onPrimary
then it is white as it should.
compose version 1.2.1
Snippet in the thread
PHondogo
10/26/2022, 9:03 PMRyan Smith
10/27/2022, 2:03 AMFlow
and Compose
? One of the predominant lessons I've been learning is "make your composables stateless by hoisting". I'm trying to adhere to this by exposing as much state as makes sense through properties on my view models.
For example, my data layer has an in-memory Repository that exposes a collection of items through a Flow
. My view model is meant to collect
that flow as state, and expose that state to my Table
composable to be displayed on the screen. But since collectAsState
is marked as @Composable
I can't call it from my view model. As I see it I could either pass the Flow
directly through my view model to my Table
composable or stick with mutableStateOf
and collect the Flow
internally to the view model and just expose the MutableState
to my Table
.
More generally, though, it feels like the two ideas "state through the view model" and "collectAsState is Composable-only" are at odds here, which makes me think there's "the way" to do this sort of thing that I'm not seeing right now.zt
10/27/2022, 3:18 AMzt
10/27/2022, 3:23 AMZoltan Demant
10/27/2022, 5:17 AMFontFamily.Resolver.preload(...)
and only showing my content after the call finishes.
Is this a really bad idea? Considering cases where the user has no/bad connectivity, etc. Would I potentially be blocking them from accessing my app for a long time? And if thats the case, is there an alternative?dambakk
10/27/2022, 5:41 AMHasan Nagizade
10/27/2022, 5:45 AMsvenjacobs
10/27/2022, 7:29 AMenum class BackgroundState { Normal, Highlighted }
@Composable
fun Item() {
var backgroundState by remember { mutableStateOf(BackgroundState.Normal) }
val backgroundColor by animateColorAsState(
targetValue = when (backgroundState) {
BackgroundState.Normal -> Color.Transparent
BackgroundState.Highlighted -> Color.Yellow
},
animationSpec = tween(),
)
LaunchedEffect(Unit) {
delay(250)
backgroundState = BackgroundState.Highlighted
delay(250)
backgroundState = BackgroundState.Normal
delay(250)
backgroundState = BackgroundState.Highlighted
delay(250)
backgroundState = BackgroundState.Normal
}
Box(modifier = Modifier.background(backgroundColor)) {
Text("Hello World")
}
}
Thanks for your help!rcd27
10/27/2022, 9:36 AMJasmin Fajkic
10/27/2022, 9:42 AMHassaan
10/27/2022, 11:26 AMText(
text = "Hello world!",
fontSize = 44.sp, // ist time
style = TextStyle(
fontSize = 24.sp, // ist time
shadow = Shadow(
color = Color.Magenta,
offset = offset,
blurRadius = 3f
)
)
)
dambakk
10/27/2022, 1:11 PMandrew
10/27/2022, 2:20 PMPedro Alberto
10/27/2022, 2:29 PMLuis Daivid
10/27/2022, 2:51 PMJasmin Fajkic
10/27/2022, 3:36 PMzt
10/27/2022, 5:01 PMefemoney
10/27/2022, 8:09 PMLazyListState.animateScrollToItem
and making _modifications_™️ but that method will take me a ‘minute’ to understand enough to update.chatterInDaSkull
10/27/2022, 10:41 PMxxfast
10/27/2022, 11:50 PMRecyclerView
within a @Composable
like this
@Composable
fun ComposeRecyclerView(items: Items) {
val adapter: RecyclerView.Adapter by remember { mutableStateOf( RecyclerView.Adapter()) }
AndroidView(
modifier = Modifier.fillMaxSize(),
factory = { context -> RecyclerView(context) },
update = { recyclerView ->
if (recyclerView.adapter == null) {
recyclerView.adapter = adapter
recyclerView.adapter?.stateRestorationPolicy =
RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY
}
adapter.set(animatedState.items)
}
)
}
This doesn't seem to work. Is this the right way to use a legacy RecyclerView
within Compose? Google is failing me because it keep showing me LazyColumn
APIs which is not what I'm trying to achieve here 😅zt
10/28/2022, 4:54 AMKenneth Leong
10/28/2022, 9:12 AMremember
in a composable which observes a mutableState from a viewModel?
e.g.
val state = remember { viewModel.someState }
PHondogo
10/28/2022, 9:58 AMDaniele Segato
10/28/2022, 12:58 PMfun Modifier.layoutVertically() =
rotate(-90f).layout { measurable, constraints ->
val swappedConstraints = constraints.copy(
minWidth = constraints.minHeight,
maxWidth = constraints.maxHeight,
minHeight = constraints.minWidth,
maxHeight = constraints.maxWidth,
)
val placeable = measurable.measure(swappedConstraints)
layout(placeable.height, placeable.width) {
placeable.place(
x = -(placeable.width / 2 - placeable.height / 2),
y = -(placeable.height / 2 - placeable.width / 2)
)
}
}
If I have a layout with this modifier inside I can't use Intrinsic sizing, I get this error:
java.lang.IllegalArgumentException: Can't represent a size of 2147483515 in Constraints
Luis Daivid
10/28/2022, 2:40 PMorangy
10/28/2022, 2:57 PMigor.wojda
10/28/2022, 6:25 PMMaterial You Dynamic Colors
(Material You) across whole app. They are working for the BottomNavBar
(in the Activity) but not for the Fragments content inside this Activity (see attached image) 🤔
I did:
DynamicColors.applyToActivitiesIfAvailable(this)
inside custom Application class onCreate
method
This is the Fragment code
class FavouriteFragment : BaseFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return ComposeView(requireContext()).apply {
setContent {
FavouriteScreen()
}
}
}
}
Here is my android-showcase project demonstrating this issue.
Any idea why this may be happening? What am I missing here?Rafs
10/28/2022, 7:13 PMRafs
10/28/2022, 7:13 PM/**
* This icon fades in and out after a delay whenever [icon] is changed
* but disappears immediately [icon] is replaced in the middle of an animation
*/
@Composable
private fun DisappearingIcon(
icon: ImageVector,
modifier: Modifier = Modifier,
contentDescription: String,
delay: Long
) {
val alpha = Animatable(0f)
val animationSpec = tween<Float>(500)
LaunchedEffect(icon) {
alpha.animateTo(1f, animationSpec = animationSpec)
delay(delay)
alpha.animateTo(0f, animationSpec = animationSpec)
}
Icon(
imageVector = icon,
modifier = modifier
.graphicsLayer {
this.alpha = alpha.value
},
contentDescription = contentDescription
)
}
Francesc
10/28/2022, 7:30 PMCrossfade
https://foso.github.io/Jetpack-Compose-Playground/animation/crossfade/Rafs
10/28/2022, 7:39 PMmattinger
10/29/2022, 2:56 AMvar alpha by remember { mutableStateOf(0f) }
LaunchedEffect(icon) {
animate(
initialValue = 0f,
targetValue = 1f,
animationSpec = tween(500)
) { value: Float, _: Float ->
alpha = value
}
delay(delay)
animate(
initialValue = 1f,
targetValue = 0f,
animationSpec = tween(500)
) { value: Float, _: Float ->
alpha = value
}
}
But if you're going to use Animatable, you should probably put it in a remember.Rafs
10/29/2022, 7:09 AManimate
function new cos I’ve never seen it before. It looks very clean, I’ll try that out