RayeW47
06/08/2022, 7:51 PMclass
to a @Composable fun
? I can't quite conceptualize it and for the most part I'm writing imperative UI with composefengdai
06/09/2022, 12:30 AMmovableContentOf
) from/to a SubcomposeLayout
, the AndroidView
within it will recreate its view.
// When rotate screen, AndroidView recreate its view
val content = remember {
movableContentOf { isLandscape: Boolean ->
AndroidView(factory = { context ->
Log.d("AndroidView", "create view")
TextView(context).apply {
layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
}
}) {
it.text = if (isLandscape) "Landscape" else "Portrait"
}
}
}
val isLandscape =
LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE
BoxWithConstraints {
if (!isLandscape) {
content(false)
}
}
if (isLandscape) {
content(true)
}
Is this expected?danprado
06/09/2022, 1:53 AMpointerInput
, but that only works when I interact outside of buttons.
Basically, what I need is a Compose version of the onUserInteraction()
Activity callback.Simon Stahl
06/09/2022, 1:59 AMpage/{pageName}
and then use pageName
to to render the correct data. I mostly wanted to use navigation because of the built in backstack
@Composable
fun NavigationTest() {
val navController = rememberNavController()
Scaffold(
bottomBar = { SimpleBottomNav(navController) }
) { innerPadding ->
NavHost(navController, startDestination = "page/{pageName}", Modifier.padding(innerPadding)) {
composable(
"page/{pageName}",
arguments = listOf(navArgument("pageName") { defaultValue = "profile" })
) { backStackEntry ->
val pageName = backStackEntry.arguments?.getString("pageName")
if (pageName != null) {
PageContent(name = pageName)
} else {
Text(text = "No page name")
}
}
}
}
}
See SimpleBottomNav
code in the comments. The main issues that I have is that 1. popUpTo()
does not seem to work properly when the startDestination has an argument in it and 2. the compose context seems to be shared between the different pages. E.g. when i use a LazyList in them, they all share the same scroll state. Did anyone ever have the same issues or has a working example for something similar?Stylianos Gakis
06/09/2022, 7:10 AMval item = remember(someKey) { ExpensiveConstructedThing() }
instead of val item by remember(someKey) { mutableStateOf(ExpensiveConstructedThing()) }
However after reading about this very informative article and some official docs, to my understanding when we use by
on the state object, we get the neat effect of not reading the value at that moment, but deferring the read to whenever we actually need it. Which sometimes comes with the nice side-effect or reading that state object in a “smaller” recomposition scope meaning that when it changes we don’t invalidate the wider recomposition scope that the above definition may be in.
So if we do not do this, but use simply val item = remember(someKey) { ExpensiveConstructedThing() }
do we lose this nice side effect? When someKey
does change, and the result of item
changes with it, will it invalidate the recomposition scope in which it is declared in as opposed to where it is actually read?krzysztof
06/09/2022, 9:03 AMmutableStateListOf
changes in effects?
Say, I have Parent
which has state remember { mutableStateListOf<Int>() }
which can be changed by one of its children. Parent
also has an effect (let’s say DisposableEffect
) reading changes to the list, like DisposableEffect(list){/* ... */}
. But that effect won’t be called more than once, because list
won’t change instance (SnapshotStateList
), even if items are added.Frank van der Laan
06/09/2022, 9:09 AMallan.conda
06/09/2022, 9:35 AMpointerInput
seems doesn’t have the pointer id to detect the number of pointers on screen. Anyone tried anything similar? We can’t find an open-source code or snippet available so far.Mehdi Haghgoo
06/09/2022, 10:51 AMste
06/09/2022, 1:18 PMLazyList
item so it doesn't get removed when it goes out of bounds? This would allow scrolling when reordering the items in a list (at least looking at my implementation).
I see there are PinnableParent
, PinnableParent.PinnedItemsHandle
, lazyListPinningModifier
, ModifierLocalPinnableParent
and so on, but I couldn't find any example.jasu
06/09/2022, 1:58 PMAaron Waller
06/09/2022, 3:52 PMprivate fun updateViews(value1: Int, value2: Int) = with(binding) {
timelineTextView.text = "$value1, $value2"
... A lot of other stuff
}
How is that possible when using the AndroidViewBinding Composable?
@Composable
fun MainScreen(){
AndroidViewBinding(ActivityPlayBinding::inflate) {
playButton.setOnClickListener {
updateViews(value1, value2)
}
playButton2.setOnClickListener {
updateViews(value1, value2)
}
}
}
How can I call that updateViews
function in Compose?
Simply putting the content of updateViews function where the function gets called feels really bad cause that causes a lot of duplicate code. But I cant seem to find the right way to do it…Esme
06/09/2022, 4:24 PMYann Badoual
06/09/2022, 4:36 PMTextField
?
Two ideas in mind:
• Using N TextField
• Drawing a canvas above the actual TextField
Wondering if there's no better way to do thisBilly Newman
06/09/2022, 4:59 PMViewModelStore should be set before setGraph call
Code in commentsJorge Domínguez
06/09/2022, 8:25 PMVisualTransformation
to ignore blank spaces, but when I tap the space bar multiple times and then I try to undo the typing it's counting all the blank spaces that were ignored, as seen in the video. Also, when I type two blank spaces it transforms them into a "." character. Any idea what I might be doing wrong?
val ignoreBlanksVisualTransformation = VisualTransformation { text ->
val blanksCount = text.text.count { it.toString().isBlank() }
val transformedText = text.text.filterNot { it.toString().isBlank() }
TransformedText(AnnotatedString(transformedText), object : OffsetMapping {
override fun originalToTransformed(offset: Int) = offset - blanksCount
override fun transformedToOriginal(offset: Int) = offset + blanksCount
})
}
farmerbb
06/09/2022, 10:02 PMeygraber
06/10/2022, 12:07 AMLaunchedEffect
as far as TestDispatcher
is concerned?
I'm trying to advanceTimeBy
past a delay
in a LaunchedEffect
but that isn't working because the dispatcher is a AndroidUiDispatcher
(or FlushCoroutineDispatcher
in desktop).
As far as I can tell, the only way around this is to create a new context (launch
, withContext
, etc...) that uses the TestDispatcher
. Is that correct, or am I missing something?Tomas Gordian
06/10/2022, 2:55 AMBottomSheetDialogFragment
. It looks like ime padding is not applying on APIs 29 and lower.julian
06/10/2022, 3:07 AMremember
-ing backCallback
in the following? In other words, why remember
backCallback
?
@Composable
fun BackButtonHandler(
enabled: Boolean = true,
onBackPressed: () -> Unit
) {
val dispatcher = localBackPressedDispatcher.current ?: return
val backCallback = remember { // <--- HERE
object : OnBackPressedCallback(enabled) {
override fun handleOnBackPressed() {
onBackPressed.invoke()
}
}
}
DisposableEffect(dispatcher) {
dispatcher.addCallback(backCallback)
onDispose {
backCallback.remove()
}
}
}
jasu
06/10/2022, 6:45 AMRajat Singh Jasrotia
06/10/2022, 6:49 AMNgọc Nguyên Nguyễn
06/10/2022, 8:48 AMMehdi Haghgoo
06/10/2022, 10:17 AMsuppressKotlinVersionCompatibilityCheck
but don't say I didn't warn you!).Ahmed Shehata
06/10/2022, 11:04 AMJonas
06/10/2022, 12:44 PMval value = "value"
val label = "label"
Column(modifier = Modifier.clearAndSetSemantics { contentDescription = "$label: $value" }) {
Text(value)
Text(label)
}
Programmistich
06/10/2022, 4:51 PMTash
06/10/2022, 6:15 PMorangy
06/10/2022, 8:33 PMBrush
object? At least for SolidColor
?Billy Newman
06/10/2022, 8:50 PMnavigation destination home?foo=bar is not a direct child of this NavGraph
Code in replyBilly Newman
06/10/2022, 8:50 PMnavigation destination home?foo=bar is not a direct child of this NavGraph
Code in replyNavHost(
navController = navController,
startDestination = "home"
) {
composable(
route = "home?foo={bar}",
arguments = listOf(navArgument("foo") { defaultValue = ""; })
) { backstackEntry ->
versions:
navigation-compose:2.4.2
compose-version:1.2.0-beta03
Ian Lake
06/10/2022, 9:04 PMBilly Newman
06/10/2022, 9:11 PMIan Lake
06/10/2022, 9:57 PMhome
because your route for your screen should be home
- arguments shouldn't be a part of it at allBilly Newman
06/10/2022, 10:49 PM