Naing Aung Luu
11/11/2022, 9:03 AMkotlin reflect
related codes in your composables?
I’m trying to use a form validation library for compose which uses kotlin reflect under the hood and it makes the preview builds to be fail ☹️
I get the following stack trace from preview issues panel
java.lang.ClassCastException: class _layoutlib_._internal_.kotlin.jvm.internal.ClassReference cannot be cast to class _layoutlib_._internal_.kotlin.reflect.jvm.internal.KClassImpl (_layoutlib_._internal_.kotlin.jvm.internal.ClassReference and _layoutlib_._internal_.kotlin.reflect.jvm.internal.KClassImpl are in unnamed module of loader org.jetbrains.android.uipreview.ModuleClassLoader @447dcf4d)
at _layoutlib_._internal_.kotlin.reflect.full.KClasses.getPrimaryConstructor(KClasses.kt:36)
at me.naingaungluu.formconductor.FormImpl.constructorRequirementSatisfied(FormImpl.kt:135)
at me.naingaungluu.formconductor.FormImpl.<init>(FormImpl.kt:46)
at me.naingaungluu.formconductor.composeui.FormComposablesKt.form(FormComposables.kt:36)
at com.memoto.mobileapp.feature.booking.checkin.guests.ComposableSingletons$CheckInGuestFormScreenKt$lambda-2$1.invoke(CheckInGuestFormScreen.kt:44)
at com.memoto.mobileapp.feature.booking.checkin.guests.ComposableSingletons$CheckInGuestFormScreenKt$lambda-2$1.invoke(CheckInGuestFormScreen.kt:43)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:116)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.foundation.lazy.LazyListScopeImpl$item$3.invoke(LazyListScopeImpl.kt:54)
at androidx.compose.foundation.lazy.LazyListScopeImpl$item$3.invoke(LazyListScopeImpl.kt:54)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:135)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.foundation.lazy.LazyListItemsSnapshot.Item(LazyListItemProviderImpl.kt:99)
at androidx.compose.foundation.lazy.LazyListItemProviderImpl.Item(LazyListItemProviderImpl.kt:126)
at ......
K Merle
11/11/2022, 11:55 AMColton Idle
11/11/2022, 2:36 PMModifier.onlyShowIfTheresEnoughSpace
mattinger
11/11/2022, 3:35 PMDone
, but the actual callback does nothing? I would have expected the default behavior to at least close the keyboard. I’m writing a wrapper to configure a visual transformation for phone numbers, but i can’t even fill in the onDone action because closing the keyboard requires getting the software keyboard controller, which is in a composition local, and can’t be accessed in the parameter list:
keyboardActions: KeyboardActions = KeyboardActions(onDone = { …. } )
Tolriq
11/11/2022, 7:09 PMArjan van Wieringen
11/12/2022, 7:30 AMthe great warrior
11/12/2022, 8:34 AMval descriptionListState = remember{ mutableStateListOf("") }
LaunchedEffect(descriptionListState.toList()) {
alarmViewModel.changeCreateAlarmState(
createAlarmState.copy(description = descriptionListState.joinToString(" "))
)
}
PHondogo
11/12/2022, 9:37 AMJiri Bruchanov
11/12/2022, 10:12 AMAbdelilah El Aissaoui
11/12/2022, 12:40 PMSelectionContainer {
LazyColumn {
items(100) {
Text("Line number $it")
}
}
}
The "copy" button also jumps around in the same situation. Seems like a compose bug but not completly sure.
A normal column works without any issues (expected since everything is composed unlike the LazyColumn).Slackbot
11/12/2022, 1:13 PMTower Guidev2
11/12/2022, 1:56 PMColton Idle
11/12/2022, 3:07 PMExposedDropdownMenu
has a field called onDismissRequest
but it gets called even when I'm typing on the keyboard which makes implementing an AutocompleteTextView-esque composable impossible.
Am I missing something here?Darryl Pierce
11/12/2022, 7:25 PMDarryl Pierce
11/12/2022, 7:26 PMGonzalo Renedo
11/13/2022, 12:21 AMRyan Smith
11/13/2022, 3:23 PMSam Stone
11/13/2022, 10:48 PMGonzalo Renedo
11/14/2022, 1:33 AMZoltan Demant
11/14/2022, 9:43 AM1.4.0-alpha02
, you may run into issues if youre using value ?: return
in your composables. Ive reported it already, just sharing this since I didnt manage to detect the issue myself until it was too late!abbic
11/14/2022, 10:28 AMPedro Alberto
11/14/2022, 11:51 AMJrichards1408
11/14/2022, 12:23 PMbodo
11/14/2022, 12:58 PMdimensionResource(...)
. At the moment i am setting a custom LocalDensity if the device has a certain width. The reason I am setting a custom density is to achieve the autoscaling of composables, e.g. when an image has a size in COMPACT mode from 50.dp (e.g. =150px) it should be bigger in MEDIUM mode (e.g. =150px * 1.2 = 180px)
val density = LocalDensity.current.density
val fontScale = LocalDensity.current.fontScale
val scaleFactor = if (windowSizeClass == MEDIUM) 1.2F else 1.0F
CompositionLocalProvider(
LocalDensity provides Density(density = scaleFactor * density, fontScale = fontScale)
) {
val dpDirectly = 130.dp
val dpViaResources = dimensionResource(id = R.dimen.dimen_130)
// windowSizeClass == COMPACT
// dpDirectly = 130.dp
// dpViaResources = 130.dp
// windowSizeClass == MEDIUM
// dpDirectly = 130.dp
// dpViaResources = 108.33333.dp -> WRONG VALUE!!!!
}
The problem is the dimensionResource function, because here the displayMetrics are used and they have a different density than the LocalDensity:
fun dimensionResource(@DimenRes id: Int): Dp {
val context = LocalContext.current
val density = LocalDensity.current
val pxValue = context.resources.getDimension(id) // this returns the wrong value because here the DisplayMetrics are used
return Dp(pxValue / density.density) -> this tries to get the correct value by dividing through the LocalDensity
}
The main problem is the LocalDensity and DisplayMetrics have different density values.
Two questions:
1. Can it be done like this
2. If not what is the best way to achieve autoscaling of dp and sp values?dimsuz
11/14/2022, 1:04 PMLazyColumn
? I need only to detect this fact and not interfere with the gesture itself in any way. Should I use lower level gesture detection modifiers?Tower Guidev2
11/14/2022, 2:45 PMdebounce
for clickables and have this Modifier
extension...abbic
11/14/2022, 2:55 PMLaunchedEffect(key1 = event) {
when (event) {
ManualPaymentEvent.LoadingError -> {
scaffoldState.snackbarHostState.showSnackbar(
message = snackbarMessage,
actionLabel = snackbarAction,
duration = SnackbarDuration.Indefinite
)
viewModel.onSnackBarDismissClicked()
}
ManualPaymentEvent.NavigateBack ->
navigateUp()
is ManualPaymentEvent.NavigateWithCards ->
navigateToSelectCard(event.amount, event.cards)
is ManualPaymentEvent.NavigateWithoutCards ->
navigateToAddCard(event.amount)
null -> Unit
}
viewModel.eventConsumed()
}
viewModel.eventConsumed()
sets the event to null again, to show it has been consumed. onSnackbarDismissClicked
updates the uiState with uiState = uiState.copy(event = ManualPaymentEvent.NavigateBack)
. the intent here is that the NavigateBack event triggers the navigateUp()
function but this never happens.
The issue appears to be that the event is first set to NavigateBack. then before this LaunchedEvent can trigger, the event is first set to null, and this NavigateBack event is ignored.
What should i be doing? would this be resolved if i was holding my state in a Flow of some kind?nuhkoca
11/14/2022, 3:20 PMhttps://miro.medium.com/max/1200/1*CE9Szh6jkPZA3jcnC4xBsQ.gif▾
rishabhsinghbisht
11/14/2022, 5:04 PMAndroidView
inside LazyList
. And the list started janking when scrolled fast. Profiled and noticed that android view is inflating the view every-time a new item comes becomes visible.
Is there a way to make them recycle views? have added key and content type to list items but that doesn’t help.chiq
11/14/2022, 8:26 PMTextButton(onClick = { /*TODO*/ },
elevation = null,
modifier = Modifier.indication(
interactionSource = MutableInteractionSource(),
indication = null
),
) {
Text(text = "Default")
}
chiq
11/14/2022, 8:26 PMTextButton(onClick = { /*TODO*/ },
elevation = null,
modifier = Modifier.indication(
interactionSource = MutableInteractionSource(),
indication = null
),
) {
Text(text = "Default")
}
Casey Brooks
11/14/2022, 8:39 PMSurface
with styling around Text()
, so you might just want to set your text style/color and use Modifier.clickable
on a Text()
instead of TextButton()
.
You can see the source of Button and TextButton, which may help you in getting the right fonts/sizing to create your own custom text button with only the things you wantChris Fillmore
11/14/2022, 8:51 PMbuttonColors
?
I’m not actually sure this solves the problem of background color in pressed state, but take a look.
https://developer.android.com/reference/kotlin/androidx/compose/material/ButtonColorschiq
11/14/2022, 8:57 PMChris Fillmore
11/14/2022, 8:58 PMchiq
11/14/2022, 8:59 PMChris Fillmore
11/14/2022, 9:00 PMpressed state not have backgroundMaybe I misunderstood
Color.Transparent
. And I think you can do this via a local themechiq
11/14/2022, 9:03 PMTextButton
and make a custom one 🙂 But thanks y'allChris Fillmore
11/14/2022, 9:05 PM@Composable
fun ProvideSecondaryRippleTheme(content: @Composable () -> Unit) {
CompositionLocalProvider(
LocalRippleTheme provides SecondaryRippleTheme,
content = content,
)
}
@Immutable
private object SecondaryRippleTheme : RippleTheme {
@Composable
override fun defaultColor(): Color {
return RippleTheme.defaultRippleColor(
// Use whatever colors you want here
contentColor = MaterialTheme.colors.onSurface,
lightTheme = MaterialTheme.colors.isLight,
)
}
@Composable
override fun rippleAlpha(): RippleAlpha {
return RippleTheme.defaultRippleAlpha(
// Use whatever colors you want here
contentColor = MaterialTheme.colors.onSurface,
lightTheme = MaterialTheme.colors.isLight,
)
}
}
And use it like this:
@Composable
fun SecondaryTextButton(
onClick: () -> Unit,
content: @Composable RowScope.() -> Unit,
) {
ProvideSecondaryRippleTheme {
TextButton(
...
)
}
}