Noé Casas
01/20/2021, 7:35 AMMutableState
stored as a member of an object retrieved through an Ambient, like this:
data class ServiceX (
val whateverString: MutableState<String>("meow")
)
@Composable
fun Whatever() {
val serviceX = AmbientServiceX.current
Text(serviceX.whateverString)
}
Will the Composable function repaint when whateverString
changes? Are there any problems with this?Cyril Find
01/20/2021, 9:35 AM@Preview
@Composable
fun PostHeader_Preview() {
MyAppTheme {
PostHeader(Post.PLACEHOLDER)
}
}
that has a render problem that looks like this: java.lang.NoSuchMethodException: com.example.myapp.components.PostHeaderKt.PostHeader_Preview
(full stacktrace in thread 🧵 )
I have no idea how to fox that since the method actually exists, what can I do ?Ahmet Delibaş
01/20/2021, 1:53 PMvar current by remember { mutableStateOf(0) }
after any change on current value, AndroidView component does not recompose. Does anybody know the answer? How can I update the AndroidView() part?Vitor Prado
01/20/2021, 3:36 PMOussama Haff.
01/20/2021, 3:52 PMButton
Composable, the indication
modifier is set to .indication(interactionState, AmbientIndication.current())
or should I build my own Button to have control over the indication ?Shakil Karim
01/20/2021, 7:09 PMHallefy
01/20/2021, 7:36 PMLilly
01/20/2021, 8:25 PMLilly
01/20/2021, 8:33 PMTony Kazanjian
01/20/2021, 10:16 PMFocusRequester
. But perhaps FocusOrderModifier
is what this is for...anyone have an example of how to use that? Here's what I have working so far:
val firstNameFocus = remember { FocusRequester()}
val lastNameFocus = remember { FocusRequester() }
val emailFocus = remember { FocusRequester() }
val passwordFocus = remember{ FocusRequester() }
Column(Modifier.padding(16.dp)) {
onActive {
firstNameFocus.requestFocus()
}
CommonTextField(
value = firstName,
onTextChange = onFirstNameChange,
modifier = Modifier.padding(8.dp).fillMaxWidth().focusRequester(firstNameFocus),
label = { Text("First Name") },
onImeAction = {lastNameFocus.requestFocus()}
)
CommonTextField(
value = lastName,
onTextChange = onLastNameChange,
modifier = Modifier.padding(8.dp).fillMaxWidth().focusRequester(lastNameFocus),
label = { Text("Last Name") },
onImeAction = {emailFocus.requestFocus()}
)
CommonTextField(
value = email,
onTextChange = onEmailChange,
modifier = Modifier.padding(8.dp).fillMaxWidth().focusRequester(emailFocus),
label = { Text("Email") },
onImeAction = {passwordFocus.requestFocus()}
)
PasswordTextField(
value = password,
onTextChange = onPasswordChange,
modifier = Modifier.padding(8.dp).fillMaxWidth().focusRequester(passwordFocus),
label = { Text("Password") },
isPasswordVisible = remember { mutableStateOf(true) },
onImeAction = {viewModel.registerUser(firstName, lastName, email, password)}
)
Alexa_Gal
01/21/2021, 12:24 AMconst styles = StyleSheet.create({
contaienr: {
....
...
...
},
box: {
...
...
}
})
is there any good practice to do this with android compose?Lilly
01/21/2021, 1:18 AMIcon
can't be resized:
Icon(
imageVector = Icons.Default.SentimentVerySatisfied,
modifier = Modifier.size(40.dp) // has no effect
)
Image on the other hand works. It's a bit confusing when to use Icon
and when Image
. ImageVector
, ImageBitmap
Painter
makes it even more confusing. Can someone enlighten me here please?Lauren Yew
01/21/2021, 1:30 AMLazyColumn
, I want to hide things if I’ve scrolled on my list. I’ve tried LazyListState
, but nothing is jumping out to me. Do we have an API to do this?Lauren Yew
01/21/2021, 1:42 AMremember{…}
can work on a list of Bitmaps? I was trying to use it to remember the state of a Bitmap I loaded from Picasso for list items, but scrolling back and forth on a list, I still see the bitmaps having to reload. Following example here: https://stackoverflow.com/questions/58594262/how-do-i-load-url-into-image-into-drawimage-in-compose-ui-android-jetpack
val imageState = remember(id) { loadPicture(url = item.photoUrl) }
private fun loadPicture(url: String?): State<ImageState> {
val imageState: MutableState<ImageState> = mutableStateOf(ImageState.Empty)
... //Picasso
}
sealed class ImageState {
data class Success(val image: Bitmap) : ImageState()
object Failed : ImageState()
object Loading : ImageState()
object Empty : ImageState()
}
Fudge
01/21/2021, 6:11 AMNoé Casas
01/21/2021, 9:14 AMTobAppBar
from a Composable that does not have access to it? I am thinking in something like SwiftUI’s toolbar
and ToolbarItem
(e.g. see https://swiftwithmajid.com/2020/07/15/mastering-toolbars-in-swiftui/) . Also, is there a mechanism or pattern to set the `TopAppBar`’s title from somewhere else, like SwiftUI’s navigationTitle
?julioromano
01/21/2021, 12:42 PMdata class State(
val firstCounter: Int = 0,
val secondCounter: Int = 0
)
@Composable
fun MyScreen(
stateFlow: StateFlow<State>,
onClick1: () -> Unit,
onClick2: () -> Unit,
) {
val state by stateFlow.collectAsState()
Column {
Button(onClick = onClick1) {
Text(text = "One ${state.firstCounter}")
}
Button(onClick = onClick2) {
Text(text = "Two ${state.secondCounter}")
}
}
}
If only one field of the state
object changes will it trigger recomposition of only one (the one that’s reading that field) or both buttons ?
Can someone point to some docs or examples to learn a bit more how recomposition actually works?
🙏Jakub Ledwon
01/21/2021, 8:09 PMLongPressTimeout
, but can't find any example of it being used, have anyone tried it and could share some experience?Logan Knight
01/21/2021, 9:19 PMLilly
01/22/2021, 3:25 AMMaterialTheme
composable.
Another question would be if we can set the color of the system bar via compose or is it only via theme.xml possible?rnett
01/22/2021, 7:41 AMpawegio
01/22/2021, 8:49 AMonDispose()
are safe to perform such action or it’s rather considered as an anti-pattern/might lead to unexpected state (is there a risk of recomposition causing not intended navigation?). See example code below (where isInProgress
is a part of collected state false
by default):
if (isInProgress) {
CircularProgressIndicator()
onDispose {
navigateToDone()
}
}
allan.conda
01/22/2021, 9:59 AMCaused by: java.lang.ClassNotFoundException: Didn't find class "com.example.SomeScreen.SomeScreenKt$SectionTitle$1" on path: DexPathList[[zip
Ian Warwick
01/22/2021, 10:20 AMBox
in a Box
and I want to offset the inner box by x
dps from the left, I tried left padding and offset though nothing seems to work
Box(Modifier.background(Color.Red).width(128.dp).height(128.dp)) {
Box(Modifier.background(Color.Green).width(32.dp).height(128.dp)) {
}
}
I want the inner box to have some space on the left hand size that I can specify hope that makes sensevipulasri
01/22/2021, 11:56 AMVivek Sharma
01/22/2021, 12:55 PMLogan Knight
01/22/2021, 1:47 PMSurface
dec:
Elevation: Surface elevates its children on the Z axis by elevation pixels, and draws the appropriate shadow.
Does that mean that the Surface
sets the Modifier.zIndex()
value of all it's children?Jason Ankers
01/22/2021, 1:54 PMPablo Costa
01/22/2021, 2:45 PMModifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp)
And want to keep the fillMaxWidth
down the chain but remove the padding, is that possible?
Thanks!!!alorma
01/22/2021, 3:52 PM