YASAN
04/25/2021, 4:05 PMColor
? It is val so cannot be modified. To change it I had to create my custom extension function:
fun Color.updateAlpha(newAlpha: Float) =
Color(red = red, blue = blue, green = green, colorSpace = colorSpace, alpha = newAlpha)
Olivier Patry
04/25/2021, 4:10 PMupdateTransition
(doc) without a lot of success so far…Nat Strangerweather
04/25/2021, 4:49 PM.fillMaxWidth
modifier. In that box, I have another box and I want it to be the width of the parent box divided by 7. How can I get the width of the parent Box, or that .fillMaxWidth
value?Ahmed Mourad
04/25/2021, 5:05 PM@Composable
fun SomeRangeBar(
lower: Float,
upper: Float,
onLowerChanged: (Float) -> Unit,
onUpperChanged: (Float) -> Unit,
range: ClosedRange<Float>,
modifier: Modifier = Modifier
) {
Canvas(modifier = modifier.pointerInput(Unit) {
detectHorizontalDragGestures {
if (headToMove == Head.LOWER) {
onLowerChanged(
newValue.coerceIn(range.start, upper)
)
} else {
onUpperChanged(
newValue.coerceIn(lower, range.endInclusive)
)
}
}
}) {
// drawing...
}
}
@Composable
fun UseSomeRangeBar() {
val lower by remember { mutableStateOf(25f) }
val upper by remember { mutableStateOf(100f) }
SomeRangeBar(
lower = lower,
upper = upper,
onLowerChanged = { lower = it },
onUpperChanged = { upper = it },
)
}
The problem would be that, since the pointerInput
closure survives recomposition and since it also captures the values of lower
and upper
then the values of lower
and upper
passed to coerceIn
are always the initial lower and upper values, all subsequent values of lower
and upper
never make it to the lambda.
A simple solution to this is to pass MutableState<Float>
instead of Float
as lower
and upper
and since MutableState
is mutable lol, then updates to lower
and upper
make it to the closure:
@Composable
fun SomeRangeBar(
lower: State<Float>,
upper: State<Float>,
//...
) {
//...
}
@Composable
fun UseSomeRangeBar() {
val lower = remember { mutableStateOf(25f) }
val upper = remember { mutableStateOf(100f) }
SomeRangeBar(
lower = lower,
upper = upper,
onLowerChanged = { lower.value = it },
onUpperChanged = { upper.value = it },
)
}
But I haven't seen anything like this in the available composables, what's the convention in such a situation?loloof64
04/25/2021, 5:15 PMConstraintLayout
. More on threadloloof64
04/25/2021, 5:58 PMConstraintLayout
for portrait and landscape, but it does not apply any layout at all. More on threadorangy
04/25/2021, 6:41 PMcontent: @Composable () -> Unit
but then will wrap each child into another component?Slackbot
04/25/2021, 6:53 PMAlexander Karkossa
04/25/2021, 10:05 PMrobnik
04/26/2021, 12:56 AMxxfast
04/26/2021, 7:00 AMandroidMain
source sets of a kotlin multi-platform project?Samir Basnet
04/26/2021, 7:12 AMChachako
04/26/2021, 8:24 AMText
beginning is .
and maxLines
is 2
, it is inconsistent with the display effect of Android. Is this intentional?
As you can see, Annex 1 is the effect displayed by Android (expected), and Annex 2 is Compose.allan.conda
04/26/2021, 9:47 AMImageVector
?
Currently our design system are all Painter
loaded from the vector drawables.Shivam Sethi
04/26/2021, 10:49 AMPaul Woitaschek
04/26/2021, 12:28 PMjulioromano
04/26/2021, 1:17 PMDropdownMenu
(i.e. have `DropdownMenuItem`s open a sub-DropdownMenu
) ?Paul Woitaschek
04/26/2021, 1:37 PMloloof64
04/26/2021, 1:48 PMloloof64
04/26/2021, 3:22 PM@Composable
, I know which part of code is responsible, but don't know exactly how to fix the issue. More on threadDenis Ismailaj
04/26/2021, 3:32 PMNat Strangerweather
04/26/2021, 5:59 PMModifier.fillMaxWidth
. The small Box has a width of Modifier.fillMaxWidth(1 / 7f)
. Elsewhere in my code outside my Composable I am defining an animation. There, I need the offset of my small Box to be the same as its width. Is there any way to use Modifier.fillMaxWidth
as a variable? If not, how can I get the right width for my offset?Arkadii Ivanov
04/26/2021, 6:01 PMDenis Ismailaj
04/26/2021, 6:12 PMDoris Liu
04/26/2021, 7:10 PMrobnik
04/26/2021, 8:32 PMColton Idle
04/26/2021, 8:34 PMJustin Tullgren
04/26/2021, 8:53 PMColton Idle
04/26/2021, 9:22 PMraenardev
04/26/2021, 10:09 PMprefix
- to create phone prefix for input field.
Since i needed only visual part, and didn’t need to modify resulting string -> i ended up making it work with VisualTransformation
But what if i need to filter out some characters or modify resulting string in some way?raenardev
04/26/2021, 10:09 PMprefix
- to create phone prefix for input field.
Since i needed only visual part, and didn’t need to modify resulting string -> i ended up making it work with VisualTransformation
But what if i need to filter out some characters or modify resulting string in some way?Siyamed
04/26/2021, 10:11 PMraenardev
04/26/2021, 10:27 PMval fixedPhone = phone.filterNot { it in 'a'..'z' }
I guess i can do that higher up, while forming a state for input, since we don’t store state in it anymore.
But what happens with that - is cursor jumps to next character everytime i input a letter instead of number.
IIRC with InputFilter i didn’t move cursor in such case - pressing invalid character just did nothing.Siyamed
04/26/2021, 10:31 PMraenardev
04/26/2021, 10:40 PMInputFilter api didnt look applicable to TextField because of the state hoistingYeah, i agree
putting the cursor back where it should be, becomes an app concernIs there an API for that available now? Say i have made changes to phone string. I would pass modified string to PhoneInput to render. But what about cursor position?
@Composable
fun PhoneInput(phone: String, onPhoneChanged: (String) -> Unit) {
BasicTextField(value = phone, onValueChange = onPhoneChanged)
}
Siyamed
04/26/2021, 10:41 PMraenardev
04/26/2021, 10:50 PMonValueChange
Seems like i have everything i need for now, will try it out tomorrow.
Thank you 🙂TextFieldValue.selection
) somewhere in the docs:
https://developer.android.com/jetpack/compose/text#enter-modify-text
I searched for this for a while, before coming to slack.
Again, tnx for your quick response 🙂Siyamed
04/26/2021, 10:53 PM