dazza5000
12/20/2022, 3:41 PMziv kesten
12/20/2022, 3:42 PMComposeView
in it.
When i try to measure this view i get
IllegalStateException: Cannot locate windowRecomposer; View androidx.compose.ui.platform.ComposeView{6542dd8 V.E...... ......I. 0,0-0,0 #7f0a0206 app:id/composeView} is not attached to a window
If i dont try to measure the view everything works fine.
It crashes even if i dont invoke setContent
What can be the problem?zt
12/21/2022, 4:58 AM.clickable {
coroutineScope.launch {
viewModel.selectSuggestion(suggestion)
focusManager.clearFocus()
}
}
TextField(
value = viewModel.textFieldValue,
onValueChange = viewModel::textFieldValueChange
)
var textFieldValue by mutableStateOf(TextFieldValue())
private set
fun selectSuggestion(suggestion: String) {
textFieldValue = TextFieldValue(
text = suggestion,
selection = TextRange(suggestion.length)
)
}
fun textFieldValueChange(value: TextFieldValue) {
textFieldValue = value
}
Dmitry Fabrichny
12/21/2022, 5:06 AMPaddingValue
which is then passed to LazyColumn(contentPadding = ...)
doesn't actually use the new padding inside of the rememberLazyListMeasurePolicy
. The bottom padding is updated with the keyboard height everytime it appears/disappears. I'm placing two breakpoints 1. Inside of the internal fun LazyList(...)
function on state.placementAnimator = placementAnimator
line. 2. Inside of the private fun rememberLazyListMeasurePolicy()
function on checkScrollableContainerConstraints()
line. Then I'm clicking a textfield to make the keyboard appear. Once the first breakpoint is hit I first check that the bottom padding is the value I'm expecting to see (~300dp) then I place a new breakpoint inside of PaddingValuesImpl.equals()
method. Then I resume the app, PaddingValuesImpl.equals()
is getting called a couple of times but it's called not from the place I'm expecting it to get called from. I'm expecting a call from remember<LazyLayoutMeasureScope.(Constraints) -> MeasureResult>() { ... }
line which is in rememberLazyListMeasurePolicy()
method but it never gets called from that method. Then the second breakpoint which is on checkScrollableContainerConstraints()
line is getting hit and when I check the contentPadding I'm seeing the old value (24dp). So I'm assuming that the remember<LazyLayoutMeasureScope.(Constraints) -> MeasureResult>() { ... }
doesn't work for some reason in this situation so the lambda is not re-remebered in other words it's the previous lambda that captured the previous contentPadding. I would really like to see what's going on inside remember<LazyLayoutMeasureScope.(Constraints) -> MeasureResult>() { ... }
but I can't place a breakpoint there because it tells me to download the sourse code and when I click download it can't find it. I tried installing the compose-runtime
dependency but it still won't show me the source code of that remember<LazyLayoutMeasureScope.(Constraints) -> MeasureResult>() { ... }
function. This feels like a bug in that one remember function. However I also tried to create a new project and copy some of the code to try and reproduce the issue but it works just fine there (same compose version). So I'm kinda lost now. I'm not sure I should report this on the issue tracker because I have no MRE and it also works in a new test project but doesn't work in the main project. The app I'm developing is open-source so I can provide the whole project if needed.Vinay Gaba
12/21/2022, 5:09 AMEko Prasetyo
12/21/2022, 8:18 AMfloatingActionButton = {
AnimatedVisibility(
visible = !sheetState.isVisible,
enter = fadeIn(),
exit = fadeOut(),
) {
FloatingActionButton(
onClick = {
...
}
) {
Icon(imageVector = Icons.Rounded.Edit, contentDescription = null)
}
}
},
I'm trying to add visibility animation using AnimatedVisibility
on my FAB, but when the animation is running, the FAB shadow change into weird box shape. How can I fix this? Thanks in advance.Abdul Hafeez Sajid
12/21/2022, 10:00 AMsomeComposable()
with a BasicTextField
, Text
and LaunchedEffect
but its showing weird behaviour. When I call someComposable()
, onFocusChanged
event occurs first and then LaunchedEffect
is called and hence Text does not show. But during testing, LaunchedEffect
is called first and then onFocusChanged
is called and Text shows up. I can’t figure out why the order is different in simple calling and in testing. Kindly guide me if someone has any idea what is going on. Code attached in the thread.gts13
12/21/2022, 10:19 AMclass MainActivity : FragmentActivity() { // I use the FragmentActivity because of biometrics
private val viewModel: MainViewModel by viewModels()
MyAppTheme {
val state by viewModel.state.collectAsStateWithLifecycle()
val incomingEvent = viewModel.incomingEvent
MyApp(
isUserRegistered = state.isUserRegistered,
hasUserProfile = state.hasUserProfile,
incomingEvent = incomingEvent
)
}
}
@Composable
fun MyApp(
isUserRegistered: Boolean,
hasUserProfile: Boolean,
incomingEvent = incomingEvent
) {
val navController = rememberAnimatedNavController()
if (isUserRegistered) {
NavigationHost(
Screen.OnboardingDestination.route,
navController
)
} else {
NavigationHost(
Screen.MainBashboard.route,
navController
)
}
when (incomingEvent) {
is profileEvent -> {
navController.navigateToProfileScreen(incomingEvent.getSomeArgs)
}
is settingsEvent -> {
navController.navigateToSettingsScreen(incomingEvent.getSomeArgs)
}
...
}
}
Now I need to access the MainViewModel
from other composable screens that are in the NavigationHost.
The reason is that I need to show a specific screen based on an incoming event that I collect from a flow in the MainViewModel
. The MainVIewModel
holds some data in memory that I need to access them only from other composables.arekolek
12/21/2022, 12:56 PMdependencies {
implementation "com.android.tools.build:gradle:7.3.1"
}
I'm getting an error when trying to build a module that uses compose:
> Task :app:compileDebugKotlin FAILED
e: org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
...
(more in snippet)
I have no idea why should the implementation
dependency of buildSrc
affect app
module in such a way 😮 any ideas?oday
12/21/2022, 1:20 PMJhonatan Sabadi
12/21/2022, 5:32 PMLucas Kivi
12/21/2022, 8:56 PMSpannableString
you get this behavior in XML.mattinger
12/21/2022, 9:15 PMcomposeRule.onNodeWithTag("input2")
.performTextReplacement("5558675309")
And this causes the following error
offset(14) should be less than line limit(0)
java.lang.IndexOutOfBoundsException: offset(14) should be less than line limit(0)
at android.text.TextLine.measure(TextLine.java:383)
at android.text.Layout.getHorizontal(Layout.java:1214)
at android.text.Layout.getHorizontal(Layout.java:1191)
at android.text.Layout.getPrimaryHorizontal(Layout.java:1161)
at android.text.Layout.getPrimaryHorizontal(Layout.java:1150)
at androidx.compose.ui.text.android.LayoutHelper.getDownstreamHorizontal(LayoutHelper.kt:344)
at androidx.compose.ui.text.android.LayoutHelper.getHorizontalPosition(LayoutHelper.kt:226)
at androidx.compose.ui.text.android.TextLayout.getPrimaryHorizontal(TextLayout.kt:330)
at androidx.compose.ui.text.android.TextLayout.getPrimaryHorizontal$default(TextLayout.kt:329)
at androidx.compose.ui.text.platform.AndroidParagraph.getCursorRect(AndroidParagraph.android.kt:328)
I’m guessing this is due to the use of the visual transformation. Anyone have any ideas?Sri
12/22/2022, 4:59 AMMutableState
using snapshotFlow
and turbine.
A simplified version of the class looks like like this
class Foo(scope: CoroutineScope) {
val bar = mutableStateOf(1)
init {
scope.launch {
delay(1000)
bar.value = 2
}
}
}
The test method looks like this
@Test
fun test() {
val testScope = TestScope(StandardTestDispatcher())
testScope.runTest {
val foo = Foo(testScope)
snapshotFlow { foo.bar.value }
.test {
val item1 = awaitItem()
println(item1)
val item2 = awaitItem()
println(item2)
}
}
}
My expectation was that it would print 1
followed by 2
. This test always fails with timeout after printing 1
. When using snapshotFlow
outside of the test environment it works as expected. I am unclear on what I am doing wrong and was looking for some guidance. Thank you.darkmoon_uk
12/22/2022, 11:04 AMA
, B
, C
If I add a view D
to the end of the list to make A
, B
, C
,D
then D
is merely added and A
, B
, C
are not recomposed.
However if I add it to the head of the list D
, A
, B
, C
then all are recomposed, I do not want this!
I tried setting layoutId
as a hint to Compose/Column that A
, B
, C
remain the same elements, but this didn't work.
Is there some mechanism I'm missing?AloneWalker
12/22/2022, 11:21 AMRow {
Text(text = "2")
Text(text = "3")
Text(text = "1")
}
Giang
12/22/2022, 12:42 PMElement functions MUST accept a parameter of typeand. This parameter MUST be named “`modifier`” and MUST appear as the first optional parameter in the element function's parameter listModifier
Layout functions SHOULD use the name “`content`” for afunction parameter if they accept only one@Composable
function parameter.@Composable
Layout functions SHOULD use the name “`content`” for their primary or most commonfunction parameter if they accept more than one@Composable
function parameter.@Composable
Layout functions SHOULD place their primary or most commonSo an example of the combination would befunction parameter in the last parameter position to permit the use of Kotlin's trailing lambda syntax for that parameter.@Composable
@Composable
fun FancyButton(
text: String,
modifier: Modifier = Modifier,
content: @Composable () -> Unit,
) {
What if my Composable accepts a modifier and a lambda? Should the lambda appears after or before modifier (given that it's not optional parameter)?
My thinking is that I should move the lambda to the bottom of parameter list to leverage trailing lambda like:
@Composable
fun FancyButton(
text: String,
modifier: Modifier = Modifier,
onClick: () -> Unit,
) {
But in the guideline page, I often see
@Composable
fun FancyButton(
text: String,
onClick: () -> Unit,
modifier: Modifier = Modifier
) {
Can anyone explain the reason of having the lambda before the modifier?Vsevolod Ganin
12/22/2022, 12:57 PMGuilherme Delgado
12/22/2022, 3:49 PMsecondaryContainer
is the property used to change active item color. But, apparently, it completely ignores the alpha channel. Any Idea why?
@Composable
fun NavigationBarTheme(content: @Composable () -> Unit) {
MaterialTheme(
colorScheme = lightColorScheme(
secondaryContainer = orange.copy(alpha = 0.3f) //val orange = Color(0xFFFF5704)
),
...
)
}
Othman El Jazouli
12/22/2022, 4:49 PMbottomSheet(route = "") {
content()
}
I tried having a card with rounded corners as root, also setting bg to transparent just gives white bg
thanks!darkmoon_uk
12/23/2022, 1:32 AMprintln
) console output from code executing in the context of a Compose Interactive Preview?mattinger
12/23/2022, 5:37 AMGuilherme Delgado
12/23/2022, 12:06 PMOn surface variant
. But the implementation we have:
package androidx.compose.material3
@Composable
fun Tab(
...
selectedContentColor: Color = LocalContentColor.current,
unselectedContentColor: Color = selectedContentColor,
)
Forcing me to do this:
Tab(
...
unselectedContentColor = MaterialTheme.colorScheme.onSurfaceVariant
)
Shouldn’t this be default value and use an approach similar to the one Switch
uses: colors: SwitchColors = SwitchDefaults.colors()
?Colton Idle
12/23/2022, 3:05 PM@HiltViewModel
class MyViewModel @Inject constructor(val appState: AppStateHolder) : ViewModel() {
val searchText = MutableStateFlow("")
init { viewModelScope.launch { searchText.debounce(1000).collectLatest { doSearch(it) } } }
fun updateSearchText(text: String) { searchText.update { text } }
fun doSearch() {...}
}
BasicTextField(value = searchText, onValueChange = { viewModel.updateSearchText(it) } ...
Hasan Nagizade
12/23/2022, 9:55 PM"product/{productId}?picture={productPicture}&name={prodName}&prodType={chatType}&groupId={groupId}&amount={prodAvailable}"
nuhkoca
12/24/2022, 1:20 AMCLOVIS
12/24/2022, 5:14 PMDismissableDrawerSheet
in material3
ursus
12/25/2022, 12:27 AMText
which is the only thing in the logical row, is there some performance to be gained (as it was with Views) by setting its width to fillMaxWidth
? (match_parent was said to be cheaper than wrap_content width)ursus
12/25/2022, 2:11 AMursus
12/25/2022, 2:11 AMThomas Richtsfeld
12/25/2022, 9:23 AMMaterialTheme
has a parameter called shapes
. If you want to have the same shape for all your cards, you can just define your own shape for each of the sizes (medium in case of card) and pass it to MaterialTheme
. That is exactly what is done here.
For elevation
I think it is hardcoded, so you would need to overwrite for each card.
What we do in our company is that we have custom compose functions for each of the basic material components like button, checkbox, progress indicator,… Under the hood we use the material versions of the components. Let’s take the button as an example. We have:
• CompanyButton
• CompanyIconButton
To answer your question, I would say yes. Create your own composable functions for each of those variations and wrap the material component into those or an enum which you pass in to the composable. It depends what you need and it is not much effort to crate those.
It is also a good practice to create your own themed variants of different theme values:
MaterialTheme(colorScheme = DefaultColors, shapes = replyShapes) {
CompositionLocalProvider(
LocalCompanyColors provides colors,
LocalCompanyTypography provides LocalCompanyTypography.current
) {
scope.content()
}
}