AmrJyniat
11/24/2021, 12:24 PMIcons.Default
?joadar
11/24/2021, 1:21 PMZhelyazko Atanasov
11/24/2021, 3:10 PMModifier
argument and then add .height()
internally. The negative side is that there won't be a way to change the composable's height.
@Composable
fun MyComposable(
modifier: Modifier = Modifier
) {
Surface(modifier = modifier.height(24.dp)
}
2. Have a default value of the modifier
argument that specifies the height. The downside is that if you want to pass a modifier to the composable, you'd have to add the height
one as well:
@Composable
fun MyComposable(
modifier: Modifier = Modifier.height(24.dp)
) {
Surface(modifier = modifier
}
In my particular case the composable will always be displayed in the default height, but I'm asking what's the generally preferred way to do this for composables that may vary in size, but we still want to have some default/min heightjannis
11/24/2021, 3:45 PMTextField
without using the BasicTextField
? It doesn't bother me that much, but if the TextField
scrolls you get a white gap at the top/bottom of the TextField
😅Tgo1014
11/24/2021, 4:03 PMContentLoadinProgressBar
in compose?Alexa_Gal
11/24/2021, 4:20 PMback
button has been pressed? i tried with all the KeyboardActions
but none of them are triggered when i press that button 😕 (using BasicTextField)Stylianos Gakis
11/24/2021, 5:02 PM<androidx.compose.ui.platform.ComposeView>
not showing its contents specifically in Android 9 (API 28) until I put my finger down in its area and then the items show. More details and a video 🎥 in thread 🧵Filip Wiesner
11/24/2021, 5:13 PMHachemi Hamadi
11/24/2021, 5:34 PMBrian Donovan
11/24/2021, 6:08 PMescodro
11/24/2021, 6:47 PMTextField
similar to Extract UI Mode (fullscreen) for EditText
?
I have a screen with some EditText
and it does not look work well when the device is on landscape.
Any ideas?
Thanks a lot!Stylianos Gakis
11/24/2021, 10:51 PMandroidx.compose.ui.platform.ComposeView
in xml (in a fragment, with ConstraintLayout being the parent), I am getting a crash Cannot add views to ComposeView; only Compose content is supported
error when I am trying to work with having an exit transition on the fragment that contains said ComposeView. The code that breaks this is something like:
supportFragmentManager
.findFragmentByTag("someTag")
?.exitTransition = MaterialSharedAxis(SHARED_AXIS, true)
Full stack trace in thread🧵Colton Idle
11/24/2021, 11:54 PMlesincs
11/25/2021, 12:03 AMitem
of LazyColumn
fill the reset of the height? See thread.rsktash
11/25/2021, 1:54 AMColton Idle
11/25/2021, 3:38 AM// Test rules and transitive dependencies:
androidTestImplementation("androidx.compose.ui:ui-test-junit4:$compose_version")
// Needed for createComposeRule, but not createAndroidComposeRule:
debugImplementation("androidx.compose.ui:ui-test-manifest:$compose_version")
Should the debugImpl
actually be androidTestImpl
?Tim Malseed
11/25/2021, 3:48 AMjava.lang.NullPointerException
at androidx.compose.ui.layout.SubcomposeLayoutState.disposeCurrentNodes$ui_release(SubcomposeLayout.kt:386)
...
Alex C
11/25/2021, 4:33 AM@Composable
fun TestClick() {
Box(modifier = Modifier
.background(Color.Red)
.padding(40.dp)
) {
Column(
modifier = Modifier
.background(Color.Green)
.clickable { Log.d("Test", "Column onClick") }
.padding(40.dp)
) {
Button(onClick = { Log.d("Test", "Button onClick") }) {
Text(text = "Click", fontSize = 24.sp)
}
}
}
}
Zoltan Demant
11/25/2021, 4:56 AMClament John
11/25/2021, 5:46 AMRow
that take up equal widths?
Row(
modifier = Modifier.fillMaxWidth()
) {
Button(
onClick = { /*TODO*/ },
) {
Text("SELECT ADDRESS")
}
Spacer(modifier = Modifier.width(12.dp))
Button(
onClick = { /*TODO*/ }
) {
Text("ADD ADDRESS")
}
}
Demo image in the threadSteffen Funke
11/25/2021, 6:40 AMState<T>
AND a StateFlow<T>
, backed by the same changing data, at the same time from an Android ViewModel? I have some View based UI which consumes the data as StateFlow
, and some Compose UI, which would need State
. And ideally I don’t want to rewrite the Compose part to collectAsState()
, rather just have it consume State directly from ViewModel (e.g. hide the implementation details inside ViewModel):
Inside ViewModel:
// is consumed by View based UI
protected val _itemsFlow = MutableStateFlow<List<Item>>(emptyList())
val itemsFlow = _itemsFlow.asStateFlow()
// should be consumed by Compose UI
val items: State<List<Item>> = itemsFlow.collectAsState() // not working bc. of missing @Composable scope
val items: State<List<Item>> = itemsFlow.collectAsState(emptyList()) // also not working
rajesh
11/25/2021, 10:33 AMProfileViewModel
) that has a function that fetch posts (paging data) of given user. I've 2 composables namely ProfileView
and DetailedPostView
I need to use same function to load posts with cached value in viewmodel, but when I navigate to detailed screen, it re-fetch the data instead of cached value. How to avoid it? code is in thread.Napa Ram
11/25/2021, 12:15 PMZoltan Demant
11/25/2021, 1:22 PMCicero
11/25/2021, 1:57 PMallan.conda
11/25/2021, 2:41 PMLukasz Kalnik
11/25/2021, 3:39 PMdata class NameDialogState(val show: Boolean, val nameFieldValue: TextFieldValue)
val nameDialogState: StateFlow<NameDialogState>
The composable has a parameter for its UI state:
@Composable
fun NameDialog(uiState: State<NameDialogState>) {
if (uiState.value.show) {
AlertDialog(
// ...
text = TextField(value = uiState.value.nameFieldValue)
)
// ...
}
}
Inside the Fragment, the composable for the dialog takes the flow with collectAsState()
val uiState = viewModel.nameDialogState.collectAsState()
setContent {
NameDialog(uiState = uiState)
}
This works, but I wonder if it is possible to get rid of the State<*>
in the composable and use NameDialogState
directly, like this:
@Composable
fun NameDialog(uiState: NameDialogState)
All Google examples recommend injecting viewmodel directly into composable, which doesn't seem good architecture... I would like to keep the composables as "stupid" as possible.Lukasz Kalnik
11/25/2021, 3:45 PM@Preview
@Composable
fun NameDialogPreview() {
val uiState = mutableStateOf(
NameDialogState(
show = true,
nameFieldValue = TextFieldValue(text = "My name")
)
)
NameDialog(uiState = uiState)
}
But it doesn't show anything.YASAN
11/25/2021, 4:20 PMnavigation-compose
past 2.4.0-alpha10
. All versions after that crash for me and the log isn't clear. 2.4.0-beta02
throws this:
java.lang.ClassCastException: java.util.LinkedHashSet cannot be cast to java.util.List
at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost$lambda-3(AnimatedNavHost.kt:388)
at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost(AnimatedNavHost.kt:165)
at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost(AnimatedNavHost.kt:91)
at yasan.space.mnml.ai.launcher.ui.navigation.NavGraphKt$NavGraph$1.invoke(NavGraph.kt:76)
at yasan.space.mnml.ai.launcher.ui.navigation.NavGraphKt$NavGraph$1.invoke(NavGraph.kt:75)
Zoltan Demant
11/25/2021, 4:37 PMtransition.AnimatedContent
block sometimes takes 500-1000 ms to execute. Is this a bug, or am I doing something wrong? 🧵👀Zoltan Demant
11/25/2021, 4:37 PMtransition.AnimatedContent
block sometimes takes 500-1000 ms to execute. Is this a bug, or am I doing something wrong? 🧵👀AnimatedContent
itself which is super-slow, and it happens when the content passed in has a lot of data, e.g. in this case a list with ~300 items.
val transition = stack
.last()
.let { top ->
updateTransition(
targetState = BackStackState(
key = Compatible.findKey(top),
content = top,
size = size
),
label = null
)
}
transition.AnimatedContent(
contentKey = BackStackState::key,
transitionSpec = {
contentTransform(
difference = targetState.size - initialState.size
)
},
content = { state ->
stateKeeper.SavedState(
key = state.key,
content = {
Render(state.content)
}
)
}
)
private fun contentTransform(
difference: Int
): ContentTransform {
return when {
difference >= 0 -> {
ContentTransform(
targetContentEnter = slideInVertically(
initialOffsetY = { height -> height },
animationSpec = SlideSpec
),
initialContentExit = fadeOut(
animationSpec = FadeSpec
),
targetContentZIndex = 1f
)
}
else -> {
ContentTransform(
targetContentEnter = fadeIn(
animationSpec = FadeSpec
),
initialContentExit = slideOutVertically(
targetOffsetY = { height -> height },
animationSpec = SlideSpec,
)
)
}
}
}
@Immutable
private data class BackStackState(
val content: Any,
val key: String,
val size: Int
)
content
from targetState fixes it, but how am I then to know which content to render in the content block of AnimatedContent?Zach Klippenstein (he/him) [MOD]
11/25/2021, 7:53 PMZoltan Demant
11/26/2021, 6:31 AM() -> Any
block. Not sure if thats a good idea in practice, or is it? Im really looking to transition screens from A -> B, rather than animate whenever A/B themselves change.