Halil Ozercan
07/27/2020, 1:54 PMhttps://youtu.be/1Drhi5JM5Q4▾
brandonmcansh
07/27/2020, 3:36 PMFudge
07/27/2020, 3:53 PMHorv
07/27/2020, 4:02 PM1.4.0-dev-withExperimentalGoogleExtensions-20200720
kotlin-compiler available online anywhere?galex
07/27/2020, 4:12 PMromainguy
07/27/2020, 4:18 PMVinay Gaba
07/27/2020, 4:44 PMrawPressStartGestureFilter
to it. This actually works but it also ends up interfering with the scroll of the screen that these composables are on (this is expected as this is how you’d expect this gesture filter to work). Is there a better way to accomplish this? Just using tap
or clickable
on the parent composable still propagates the touch to the child composable so I need a better way to intercept the touch while keeping the scroll functionality intact.spierce7
07/27/2020, 5:51 PMModifier.margin
in compose. Is there a way to achieve something similar to margin?Fudge
07/27/2020, 7:05 PMBox(backgroundColor = Color.Blue) {
Text("Foo")
}
Without specifying any height or width constraints, the Box
will automatically size to be the size of the Text (picture 1).
Now, consider picture 2.
The text Foo
is not a child of the left box, or the right one. Therefore a possible implementation of that would use a Stack
.
Stack {
Row {
Box(Modifier.weight(1f).fillMaxWidth(), backgroundColor = Color.Blue)
Box(Modifier.weight(1f).fillMaxWidth(), backgroundColor = Color.Red)
}
Text(text = "foo", textAlign = TextAlign.Center, modifier = Modifier.fillMaxWidth())
}
The problem now though, is that Box
has no children, and would have a height of 0.
Here's another attempt using `ConstraintLayout`:
ConstraintLayout {
val (left,right,text) = createRefs()
Box(backgroundColor = Color.Blue, modifier = Modifier.weight(1f).constrainAs(left){
linkTo(start = parent.start, end = right.start)
})
Box(backgroundColor = Color.Red,modifier = Modifier.weight(1f).constrainAs(right){
linkTo(start = left.start, end = parent.end)
})
Text(text = "foo", modifier = Modifier.constrainAs(text){
linkTo(start = left.start, end = right.end, bottom = left.bottom, top = left.top)
})
}
This has the same reult as the Stack
approach, with the boxes not showing at all.
So how do I communicate to compose that the boxes should be at least the size of the text? The aim is to not hardcode constraints such as Modifier.height()
.Taras Koshkin
07/27/2020, 10:24 PMPreview
functions get stripped out during compile or does it just rely on r8/proguard to strip the unused code?Val Salamakha
07/28/2020, 3:49 AMMohamed Elfiky
07/28/2020, 7:15 AMDima Avdeev
07/28/2020, 10:10 AMplugins {
id("com.android.library")
kotlin("multiplatform")
}
instead of
plugins {
id("com.android.library")
id("kotlin-android")
}
Fudge
07/28/2020, 10:48 AMLazyColumnItems
lags the screen for like 0.5 seconds when displayed? Is this perhaps because this is a preview, or do I have some way of profiling where the device spends its time?Fudge
07/28/2020, 1:50 PMvar state by savedInstanceState{0}
Button(onClick ={state++}) {
Text(text = "Increase $state")
}
Am I right in thinking state
should be saved when I restart the app? Because it doesn't do thatDavid Mcrae Jr
07/28/2020, 1:58 PMclass UserViewModel : ViewModel() {
private val _username = MutableLiveData<String>()
val username: LiveData<String>
get() = _username
private val _password = MutableLiveData<String>()
val password: LiveData<String>
get() = _password
init {
setUsername("")
setPassword("")
}
fun setUsername(username: String) {
_username.value = username
}
fun setPassword(password: String) {
_password.value = password
}
}
@Composable
fun LoginView(userViewModel: UserViewModel) {
val context = ContextAmbient.current
Column(
modifier = Modifier.fillMaxWidth().padding(top = Dp(50.0F)),
horizontalGravity = Alignment.CenterHorizontally
) {
FilledTextField(
value = userViewModel.username.toString(),
onValueChange = { it: String ->
userViewModel.setUsername(it)
},
label = { Text(stringResource(id = R.string.username_label)) },
backgroundColor = Color.Transparent,
placeholder = { Text(stringResource(id = R.string.username_placeholder)) },
keyboardType = KeyboardType.Email,
activeColor = colorResource(id = R.color.mastery_main)
)
FilledTextField(
value = userViewModel.password.toString(),
onValueChange = { it: String ->
userViewModel.setPassword(it)
},
label = { Text(stringResource(id = R.string.password_label)) },
backgroundColor = Color.Transparent,
visualTransformation = PasswordVisualTransformation(),
keyboardType = KeyboardType.Password,
activeColor = colorResource(id = R.color.mastery_main)
)
}
}
I have something like this for my login view and believe I’m using the LiveData correctly but I am seeing the object reference in the field and not the string value of username or password, thoughts?Wajahat Karim
07/28/2020, 2:04 PMstate
in Compose dev15. So, if create a state like val numState by state { 0 }
, and use this in any composable like Text, it works good and fine. On doing numState++
, the Text updates. But, if I use some custom data class like this below code:
data class Point(val x:Int = 0, val y:Int = 0)
And using this class to create state like val pointState by state { Point(3,4) }
, and now if I update this like pointState.x++
, then the Composables using this state aren't recomposed and updated. I don't understand how am I supposed to use state?Horv
07/28/2020, 2:31 PMbrandonmcansh
07/28/2020, 2:42 PMBrett Best
07/28/2020, 3:03 PMFudge
07/28/2020, 7:45 PMstate
but it seems like it makes it so writes to the variable somehow get ignored, so I would change the value but after the recomposition the value is the same as it was before. I can’t really give a complete example since its in a middle of a lot of things and this only happens in exactly the second instance of this state variable. But the magical nature of remember {} and such make it impossible to debug. At this point it seems it would be easier to roll out my own implementation of state.Zach Klippenstein (he/him) [MOD]
07/28/2020, 9:23 PMsavedInstanceState
? Looks like it’s stuck around for now?Patrick Yin
07/29/2020, 12:03 AM@Preview
, will the @Preview marked method be removed (or changed) when assembling release build?Horv
07/29/2020, 4:08 PMButton(
onClick = {
Log.d("Login", "ButtonClicked!")
handleLoginButtonPress(loginFragment, context)
},
backgroundColor = Color.White,
padding = InnerPadding(8.dp)
) {
Image(
asset = imageResource(id = R.drawable.btn_google_light_normal_hdpi),
modifier = Modifier.height(40.dp)
.padding(0.dp)
.absolutePadding(0.dp, 0.dp, 0.dp, 0.dp)
.drawShadow(0.dp),
contentScale = ContentScale.Inside
)
Text(
"Sign in with Google",
color = Color(75, 75, 75),
fontFamily = fontFamily(listOf(font(R.font.roboto_medium))),
modifier = Modifier.padding(24.dp, 0.dp, 0.dp, 0.dp)
)
}
CLOVIS
07/29/2020, 5:36 PMlouiscad
07/29/2020, 5:39 PMModifier
the new LayoutParams
in a way?Vinay Gaba
07/29/2020, 5:58 PMFudge
07/29/2020, 7:07 PM@Preview
? I remember there was one but I can't find it.
Something like Something.isInPreview()
galex
07/29/2020, 7:28 PMromainguy
07/29/2020, 8:00 PMlaunchInComposition()
romainguy
07/29/2020, 8:00 PMlaunchInComposition()
galex
07/29/2020, 8:05 PMLeland Richardson [G]
07/29/2020, 8:58 PMrememberCoroutineScope
is what you wantAdam Powell
07/29/2020, 9:25 PMlaunchInComposition
. If you want to be able to launch jobs as a result of other events and have that scope managed/cleaned up for you, use rememberCoroutineScope
.