Vitor Prado
02/22/2021, 7:00 PMTheMrCodes
02/22/2021, 7:08 PMeygraber
02/22/2021, 7:38 PMChris Grigg
02/22/2021, 9:58 PMColton Idle
02/22/2021, 11:23 PMprivate val Lato = FontFamily(
Font(R.font.lato_regular, FontWeight.Normal),
Font(R.font.lato_bold, FontWeight.Bold),
)
object MyTypeSystem {
val head = TextStyle(
fontFamily = Lato,
fontSize = 18.sp,
fontWeight = FontWeight.Normal
)
val body = TextStyle(
fontFamily = Lato,
fontSize = 12.sp,
fontWeight = FontWeight.Bold
)
...
}
eygraber
02/23/2021, 6:48 AMremember
something mutable, but not cause a recomposition when it is mutated?krzysztof
02/23/2021, 8:13 AMDieter Holz
02/23/2021, 8:50 AMShakil Karim
02/23/2021, 9:53 AMpopUpTo(Destination.OnboardingWelcomeScreen.route) { inclusive = true }
But it giving me error because it's expecting int instead of String.Kevin Aude
02/23/2021, 10:57 AMKevin Aude
02/23/2021, 10:58 AMDeepak Gahlot
02/23/2021, 10:59 AMDeepak Gahlot
02/23/2021, 11:00 AMYuri Drigin
02/23/2021, 12:13 PMonCommit
crashed with Composition re quires an active composition context
?
@Composable
fun NetworkImage(
modifier: Modifier,
url: String?,
placeholder: Int
) {
var image by remember { mutableStateOf<ImageBitmap?>(null) }
onCommit {
val picasso = Picasso.get()
Archie
02/23/2021, 1:00 PMTransition
?
I'd like to do an action after the new state have been reached something like:
val transitionState = remember {
MutableTransitionState(false)
}
val transition = updateTransition(transitionState)
val scale by transition.animateFloat(
transitionSpec = { spring(dampingRatio = Spring.DampingRatioMediumBouncy) }
) {
when (it) {
true -> 1f
false -> 0f
}
}
LaunchedEffect(viewModel, navController) {
delay(1000)
transitionState.targetState = true
// Then I want to do an action after the animation finished
// but I can't find a way to attached a listener to Transition.
}
Sergey Y.
02/23/2021, 1:50 PMFreetype Harfbazz
library to render individual glyphs as a sequence of vector paths.
Now I'm looking for an option how this can be integrated into the pipeline of the standard android input system, and with the Compose(I'm considering CoreTextField).
In the case of working with a regular EditText
, it seems to me that I will need to rewrite everything from scratch(cursor, line break, context menu, text selection, etc.).
But since the Compose has platform(android, desktop) implementations of text input, that means it uses abstractions around working with text. Which means it is should be possible to change implementation.
I found an abstraction like Paragraph and its platform implementation for Android AndroidParagraph, which under the hood uses the TextLayout wrapper for StaticLayout class.
And a MultiParagraph class that uses the above Paragraph.
I would like to replace the implementation for the AndroidParagraph
with my own but it seems that I do not see how this could be done. I would be apprecited any help.
Thanks.Mehdi Haghgoo
02/23/2021, 2:18 PMDaniele B
02/23/2021, 6:18 PMMikołaj Kąkol
02/23/2021, 7:25 PMrememberSaveableStateHolder
is broken in somehow in alpha12. Consider example from here: https://github.com/androidx/androidx/blob/androidx-main/compose/runtime/runtime-sa[…]/compose/runtime/saveable/samples/SaveableStateHolderSamples.kt
and change
Box(modifier) {
restorableStateHolder.SaveableStateProvider(currentScreen) {
content(currentScreen)
}
}
to
Box(modifier) {
restorableStateHolder.SaveableStateProvider(currentScreen) {
Crossfade(targetState = currentScreen) {
content(it)
}
}
}
you will notice that animation doesn’t work.
If you will remove that state holder:
Box(modifier) {
Crossfade(targetState = currentScreen) {
content(it)
}
}
crossfade works.
So either stateholder
is broken or crossfade
. From what I unsderstand problem is that Crossfade implementation uses remember
to store items to render during transition.
What I wanted to achieve is some nice animation between screens. What to do? 🤔 🙀utikeev
02/23/2021, 7:36 PMDragObserver
got deprecated, but I didn't manage to properly migrate my implementation to new API.
Using two draggable
modifiers prevents from dragging simultaneously in both directions and zooming at the same time, while using pointerInput
lacks was kind of tricky:
• detectDragGestures
lack onStart
and velocity
parameter in onEnd
callback
• drag
function seems to allow more fine-grained setting up, but judging by detectDragGestures
is also quite hard to handle. Also velocity
has to be calculated somehow (isn't really clear)
I'll attach deprecated snippet, which I currently use, and would be glad to know several directions on how it can be implemented with new API with the similar amount of code.Ky
02/23/2021, 11:05 PMadjustPan
are not behaving properly after the first focus. The first click, the composable is properly moved up but if you close the keyboard and click back into the field, it is now partially obscured by the keyboard. Has anyone run into this?itnoles
02/24/2021, 1:51 AMitems
for LazyColumn
?nanodeath
02/24/2021, 5:07 AMChachako
02/24/2021, 7:23 AMremember { mutableStateOf(...) }
will be reorganized immediately after each setValue
, but I just want to update the variable, and then manually reorganize and remember this variable at some point. what should I do?rsktash
02/24/2021, 8:49 AMeygraber
02/24/2021, 9:23 AMImmutable
are all of its subclasses considered Immutable
as well?Smorg
02/24/2021, 10:12 AMKarthick
02/24/2021, 10:15 AMRahul Sainani
02/24/2021, 10:50 AMManu Eder
02/24/2021, 11:30 AMstate: T, onChange: (T) -> Unit
) instead of a single parameter (stateD: MutableState<T>
). E.g. why is the Checkbox2
-example below promoted over Checkbox1
. (I know the two are subtly different in when the state that the modification is based on is read.)
More generally, I think what I was expecting to find, but haven't seen yet is some standard way to handle what I expect to be a common case of creating some "widget" whose entire state can be described by some (immutable data) class and where "subwidgets" modify part of that state. I.e. I guess I'm looking for a blessed function:
(MutableState<T>, Lens<T, S>) -> MutableState<S>
or, with automatic creation of Lenses (https://www.reddit.com/r/Kotlin/comments/4i5wsp/lenses_for_kotlin/):
(MutableState<T>, KProperty1<T, S>) -> MutableState<S>
.
Does something like this exist? Is there a good reason why it shouldn't?
Checkbox1
and Checkbox2
-example:
@Composable
fun Checkbox1(stateD: MutableState<Boolean>) {
var state by stateD
Button(onClick = {state = !state}) {
Text( if (state) "on" else "off")
}
}
@Preview
@Composable
fun UseCheckbox1() {
val stateD = remember { mutableStateOf(false) }
Checkbox1(stateD)
}
@Composable
fun Checkbox2(stateVal: Boolean, stateChanger: (Boolean) -> Unit ) {
Button(onClick = {stateChanger(!stateVal)}) {
Text( if (stateVal) "on" else "off")
}
}
@Preview
@Composable
fun UseCheckbox2() {
val stateD = remember { mutableStateOf(false) }
var state by stateD
Checkbox2(stateVal = state, stateChanger = {state = it} )
}
Manu Eder
02/24/2021, 11:30 AMstate: T, onChange: (T) -> Unit
) instead of a single parameter (stateD: MutableState<T>
). E.g. why is the Checkbox2
-example below promoted over Checkbox1
. (I know the two are subtly different in when the state that the modification is based on is read.)
More generally, I think what I was expecting to find, but haven't seen yet is some standard way to handle what I expect to be a common case of creating some "widget" whose entire state can be described by some (immutable data) class and where "subwidgets" modify part of that state. I.e. I guess I'm looking for a blessed function:
(MutableState<T>, Lens<T, S>) -> MutableState<S>
or, with automatic creation of Lenses (https://www.reddit.com/r/Kotlin/comments/4i5wsp/lenses_for_kotlin/):
(MutableState<T>, KProperty1<T, S>) -> MutableState<S>
.
Does something like this exist? Is there a good reason why it shouldn't?
Checkbox1
and Checkbox2
-example:
@Composable
fun Checkbox1(stateD: MutableState<Boolean>) {
var state by stateD
Button(onClick = {state = !state}) {
Text( if (state) "on" else "off")
}
}
@Preview
@Composable
fun UseCheckbox1() {
val stateD = remember { mutableStateOf(false) }
Checkbox1(stateD)
}
@Composable
fun Checkbox2(stateVal: Boolean, stateChanger: (Boolean) -> Unit ) {
Button(onClick = {stateChanger(!stateVal)}) {
Text( if (stateVal) "on" else "off")
}
}
@Preview
@Composable
fun UseCheckbox2() {
val stateD = remember { mutableStateOf(false) }
var state by stateD
Checkbox2(stateVal = state, stateChanger = {state = it} )
}
allan.conda
02/24/2021, 12:11 PMManu Eder
02/24/2021, 12:32 PMremember { mutableStateOf( ... ) }
), but instead will want to pass it down.
The documentation promotes passing down a value and a setter (which is very similar to a getter and a setter).
I would like to be able to just say "use this field of this variable that I already have" (which was probably passed down to me, and might again be a field of some other variable), without having to write getters and setters all the time.
So, I'd like to be able to have something like
data class TwoBools( val one: Boolean, val two: Boolean )
@Composable fun TwoCheckboxes( state: GetSet<TwoBools> ) {
Checkbox( state.field(TwoBools::one) )
Checkbox( state.field(TwoBools::two) )
}
@Composable fun Checkbox( state: GetSet<Boolean> ) {
...
}
field
would be a member/extension function of GetSet<T>. And GetSet<T>
might or might not be equal to MutableState<T>
.field
would be the aforementioned
(GetSet<T>).(KProperty1<T, S>) -> GetSet<S>
field
. This just seems like such an obvious pattern that I felt it should probably exist somewhere already. Also, I don't understand the internals of compose and don't know what kind of performance implications the different ways of doing this might have.
Should GetSet<T>
be an interface (i.e. = MutableState<T>
?), should it be
data class GetSet<T>(get: () -> T, set: (T) -> Unit)
, should it be
data class GetSet<T>(get: T, set: (T) -> Unit)
,
etc...?TwoCheckboxes
code above would look like this:
data class TwoBools( val one: Boolean, val two: Boolean )
@Composable fun TwoCheckboxes( state: TwoBools, stateSetter: (TwoBools) -> Unit ) {
Checkbox( state.one, { stateSetter(state.copy(one=it)) } )
Checkbox( state.two, { stateSetter(state.copy(two=it)) } )
}
@Composable fun Checkbox( state: Boolean, stateSetter: (Boolean) -> Unit ) {
...
}
, which isn't a lot longer, but does get kinda repetitive, and the field name is referenced twice instead of once...)Albert Chang
02/24/2021, 2:13 PMMutableState
or something like that. LazyListState
is a good example. It is essentially a mutable state.Manu Eder
02/24/2021, 3:25 PMMutableState<T>
is an interface. Anything that you can do with currentValue
and lambdaFun
you can do with `MutableState<T>`:
object : MutableState<Boolean> {
override operator fun component1() = currentValue
override operator fun component2() = lambdaFun
override var value : Boolean
get() = currentValue
set(newVal) = lambdaFun(newVal)
}
(And you can make this less verbose if you plan to do it a lot.)
I noticed LazyListState as one of the few examples where both getter and setter are passed as one variable. I was just wondering why it wasn't using something like MutableState<ImmutableLazyListState>
, i.e. why there wasn't some kind of standardized way of doing what LazyListState does.Albert Chang
02/25/2021, 1:21 AMMutableState
is an interface, it is the SnapshotMutableStateImpl
class that actually enables the Recomposer
to subscribe to changes of the value (the subscription relies on the Snapshot
mechanism). You own implementation of MutableState
won't have this ability thus automatic recomposition will not work. You can verify this yourself.
Besides LazyListState
, essentially the return types of all remember*State()
functions are mutable states, such as ScaffoldState
, ScrollState
, etc. They contain relatively complex logics and provide the user with extra methods.