zt
03/24/2022, 8:10 PMallan.conda
03/24/2022, 8:49 PMfillMaxSize
is ignored if specified below verticalScroll
Modifier?Mehdi Haghgoo
03/25/2022, 9:24 AMritesh
03/25/2022, 9:46 AMstringResource
and maps from one object to another. I should be marking it as @ReadOnlyComposable
?
More in 🧵takahirom
03/25/2022, 11:03 AM@Composable
fun Composable1(articles: Articles) {
Text(text = "Hello $articles!")
}
@Stable
data class UiModel(val articles: Articles)
@Composable
fun Composable2(uiModel: UiModel) {
Text(text = "Hello $uiModel!")
uiModel.articles.articles.forEach {
Composable3(it)
}
}
@Composable
fun Composable3(article: Article) {
Text(text = "Hello $article!")
}
model module
data class Articles(val articles: List<Article>)
data class Article(val title: String)
app_release-composables.txt
restartable fun Composable1(
unstable articles: Articles
)
restartable skippable fun Composable2(
stable uiModel: UiModel
)
restartable fun Composable3(
unstable article: Article
)
source code
https://github.com/takahirom/compose-multi-module-stabilityaxehit
03/25/2022, 11:04 AMperformScrollToIndex
method in compose ui test library provided for scrolling an item to a particular index, scroll that item index to the very top position.
This behaviour is different from the recyclerView.scrollToPosition
method we have currently in the old view system which scrolls the item just enough to make that item visible at the bottom.
Can someone tell me is there an API for tests in compose to have that similar behaviour of scrolling the item just enough to make it visible at the bottom instead of at the top?Daniele Segato
03/25/2022, 2:42 PMTextStyle
?
Most designers see those as part of the text styling but in compose we are forced to handle them via code.
Is there any plan to include text transformations in text style so that we can manage them in themes?
In some project I created my own Text widgets to add this behavior, but I think it should be part of Compose handling of Texts.julioromano
03/25/2022, 3:09 PMLayout
but the algorithm to compute the placement of the children composables (i.e. to compute both the constraints of the measurables and the x,y of the placeables) turns out to be O(n^2).
Is it possible to handle this computation in a background coroutine or similar, but still while inside the composable Layout()
function? Are there any patterns in compose to help with such cases?Arkadii Ivanov
03/25/2022, 6:35 PM@Composable
fun Foo(content: @Composable () -> Unit) {
var enabled by remember { mutableStateOf(true) }
Box(
modifier = Modifier // Disable the sub-tree if not enabled
) {
content()
}
}
How can I disable the content
?
So far I discovered Modifier.pointerInteropFilter { true }
which seems working, but it is marked as experimental with level ERROR
.YASAN
03/25/2022, 9:18 PMLazyColumn
using Paging3 (with its compose library). I now show the paginated list by converting the PagingData
into a LazyPagigItems
object. My issue is that I cannot find a way to show any state other than the success state like showing the loading indicator or showing an error when the loading of a page fails. I have done this outside Compose using RecyclerViews but I cant find anything useful for it in Compose.Alexander Maryanovsky
03/25/2022, 9:38 PMModifier
that, when the element it modifies is “selected” (in a sense I define), it automatically makes it focused.
fun Modifier.focusedWhenSelected(): Modifier = this.then(FocusedWhenSelected)
object FocusedWhenSelected: Modifier.Element{
fun implementingModifier(modifier: Modifier, isSelected: Boolean): Modifier{
val hasFocusedWhenSelected = modifier.any { it == FocusedWhenSelected }
if (!hasFocusedWhenSelected)
return Modifier
return Modifier.composed {
val focusRequester = remember { FocusRequester() }
if (isSelected) {
LaunchedEffect(Unit) {
focusRequester.requestFocus()
}
}
Modifier
.focusRequester(focusRequester)
.focusable()
}
}
}
and then, in the code that actually defines isSelected
, I do:
Box(
modifier = FocusedWhenSelected.implementingModifier(modifier, isSelected)
){
...
}
Does this look right? I’m somewhat worried that I’m creating a new Modifier.composed
every time.robnik
03/25/2022, 11:48 PMImage(
painter = ..., contentDescription = null,
contentScale = ContentScale.Fit, // ???
modifier = Modifier.fillMaxWidth()
)
Alexander Black
03/26/2022, 1:29 AMoverlay = {
if (it.isSelected) {
Box(
Modifier
.size(if (it.rentalLength != null) 245.dp else 222.dp)
.alpha(0.6f)
.background(DownpourTheme.colors.primary)
)
}
}
)
but the size being hardcoded is obviously not ideal. Wondering if there’s an easy way to measure the size of the card my box is trying to overlay?Aaron Waller
03/26/2022, 7:03 AMLuis Daivid
03/26/2022, 1:01 PMAlexander Maryanovsky
03/26/2022, 1:32 PMColumn
where each row “knows” its index, like so:
@Composable
fun IndexedColumn(
content: @Composable IndexedColumnScope.() -> Unit
){
Column {
content.invoke(IndexedColumnScope())
}
}
class IndexedColumnScope{
var index = 0
@Composable
fun row(
rowContent: @Composable IndexedRowScope.() -> Unit
){
val rowIndex = remember { index++ }
rowContent.invoke(IndexedRowScope(rowIndex))
}
}
class IndexedRowScope(
val rowIndex: Int
)
@Composable
fun UseIndexedColumn(){
IndexedColumn{
repeat(5) {
row{
Text("Row $rowIndex")
}
}
}
}
The problem is with the var index
— when a row changes, row
is called again (not recomposition, but regular composition) and index
increases again. So if I had at the beginning
Row 0
Row 1
Row 2
Row 3
Row 4
and then row 2 changes from Text
to BasicTextField
, I’d have
Row 0
Row 1
Row 5 <-- BasicTextField
Row 3
Row 4
Tobias Gronbach
03/26/2022, 10:32 PMLong Tran
03/27/2022, 7:21 AMritesh
03/27/2022, 8:47 AMSide-effect
part?
More in 🧵Aaron Waller
03/27/2022, 8:48 AM.asImageBitmap()
.
But is there a way to convert ImageBitmaps to Bitmaps?
I want to save the ImageBitmap as a .png on the internal storage and/or upload it to my cloud storageRyosuke Yamada
03/27/2022, 10:43 AMSwipeRefresh
.
Simple example:
var isRefreshing by remember { mutableStateOf(false) }
var isLoaded by remember { mutableStateOf(false) }
SwipeRefresh(state = rememberSwipeRefreshState(isRefreshing),
onRefresh = { isRefreshing = true }) {
AndroidView(
factory = {
WebView(it).apply {
webViewClient = WebViewClient()
}
}
) { webView ->
if (!isLoaded) {
webView.loadUrl("<https://www.android.com/>")
isLoaded = true
}
if (isRefreshing) {
webView.reload()
isRefreshing = false
}
}
}
This does not work because SwipeRefresh
needs scrollable child. By adding verticalScroll
modifier to AndroidView, SwipeRefresh
works, but WebView gets infinite height and content does not rendered as expected.
Is there any way to notify legacy View's scroll events to parent Composable?Marcin Wisniowski
03/27/2022, 6:07 PMRow
? I'm looking for something like Modifier.offset(x = 8.dp)
, which correctly moves my item to overlap the next one, but does not modify the size of the outer Row
. I have two items in the Row
.Icyrockton
03/28/2022, 4:53 AMziv kesten
03/28/2022, 8:37 AM@Test
fun testSomeState() {
composeTestRule.setContent {
SomeComposable {
println("click $it")
}
}
composeTestRule.onNodeWithTag("Zivi")
.performClick()
.assertExists()
}
@Composable
fun SomeComposable(onClick: (Int) -> Unit) {
var someState by remember { mutableStateOf(0) }
Button(modifier = Modifier.testTag("Zivi").pointerInteropFilter {
someState = when (it.action) {
MotionEvent.ACTION_DOWN -> { 1 }
MotionEvent.ACTION_UP -> { 2 }
else -> { someState }
}
true
}, onClick = { }) {}
LaunchedEffect(someState) {
println("LaunchedEffect someState $someState") // prints "LaunchedEffect someState 0"
// and then "LaunchedEffect someState 2"
if (someState == 2) { onClick(someState) }
}
}
------------
This works well, however, if i change Button
to a Box
, like this:
------------
@Composable
fun SomeComposable(onClick: (Int) -> Unit) {
var someState by remember { mutableStateOf(0) }
Box(modifier = Modifier.testTag("Zivi").pointerInteropFilter {
someState = when (it.action) {
MotionEvent.ACTION_DOWN -> { 1 }
MotionEvent.ACTION_UP -> { 2 }
else -> { someState }
}
true
}) {}
LaunchedEffect(someState) {
println("LaunchedEffect someState $someState") // prints "LaunchedEffect someState 0"
if (someState == 2) { onClick(someState) }
}
}
Then the LaunchedEffect
is not called on performClick
, can anyone help me understand why?Stylianos Gakis
03/28/2022, 9:33 AMOutlinedButton
style having a transparent background. This doesn’t seem to be the case in the compose version as it defines the surface
color of the MaterialTheme
as its background instead.
I would love to hear more about what is the idea behind it? More often than not, when using an Outlined
button, one would like to have it show the text and the outline but blend in with whatever is in the background by basically having no background. That is since what’s behind it often is not a surface
. It could be for an image or some color close to surface not not quite the same.
My guess would be that this was done to ensure a proper pair of surface/onSurface color to ensure accessibility, so it this the reason? Anything else I’m missing?
We’re considering altering our design system’s outlined button to always have a transparent background (while still using onSurface for the content) and I would basically like to hear more about this to see why we may want/not want to do this. Assuming we’re taking care of making the content legible on a per-case basis of course.czuckie
03/28/2022, 10:28 AMComposeView
inside a Fragment
- it works well with our current navigation system, but we're noticing things like TextField
will not update consistently on text entry. The exact same composable in a ComponentActivity
works as expected. Is there some particular stuff I need to be wary of when using JC with Fragments?Tobias Gronbach
03/28/2022, 10:29 AMJohan Reitan
03/28/2022, 11:35 AMRow
component that has two slots for text. Both texts can be of varying length, and I’m having a hard time getting the component to balance the text’s width so that the longest text takes the rest of the available space, and also weigh them equally if both texts are long.
The closest I’ve been able to get is using equal values of Modifier.weight()
, but that does not solve the case where one text is longer than the other. The first image is using weight()
, and the second is what I’m trying to achieve.
Code and more examples in thread 🧵Rafael Costa
03/28/2022, 12:51 PMIcyrockton
03/28/2022, 2:05 PMaccompanist-swiperefresh
has a bug on it.Icyrockton
03/28/2022, 2:05 PMaccompanist-swiperefresh
has a bug on it.Kirill Grouchnikov
03/28/2022, 2:19 PMIcyrockton
03/28/2022, 2:50 PM