Exploring MovableContentOf in Jetpack Compose | by sinasamaki | Mar, 2022

Say goodbye to recomposing views in Android

...
var isRow by keep in mind
mutableStateOf(true)

Column(
horizontalAlignment = Alignment.CenterHorizontally
)
Button(onClick = isRow = !isRow )
Textual content(textual content = "Swap")

if (isRow)
Row(
Modifier.weight(1f),
verticalAlignment = Alignment.CenterVertically
)
LetterBox(letter = 'A')
LetterBox(letter = 'B')

else
Column(
Modifier.weight(1f),
verticalArrangement = Association.Middle
)
LetterBox(letter = 'A')
LetterBox(letter = 'B')



...

...
val bins = keep in mind
movableContentOf
LetterBox(letter = 'A')
LetterBox(letter = 'B')

Column(
horizontalAlignment = Alignment.CenterHorizontally
)
Button(onClick = isRow = !isRow )
Textual content(textual content = "Swap")

if (isRow)
Row(
Modifier.weight(1f),
verticalAlignment = Alignment.CenterVertically
)
bins()

else
Column(
Modifier.weight(1f),
verticalArrangement = Association.Middle
)
bins()



...

@Composable  
enjoyable ColumnExample()
val checklist = keep in mind
mutableStateListOf<String>().apply
for (i in 0..20) add("Counter $'A' + i")

Column
Button(onClick =
checklist.removeFirstOrNull()
)
Textual content(textual content = "Take away first")

Column(
modifier = Modifier
.verticalScroll(state = rememberScrollState())
.weight(1f)
)
checklist.forEach
Counter(textual content = it)



...
val listComposables = checklist.movable
Counter(textual content = it)

Column
Button(onClick =
checklist.removeFirstOrNull()
)
Textual content(textual content = "Take away first")

Column(
modifier = Modifier
.verticalScroll(state = rememberScrollState())
.weight(1f)
)
checklist.forEach
listComposables(it)



...

@Composable  
enjoyable <T> Record<T>.movable(
rework: @Composable (merchandise: T) -> Unit
): @Composable (merchandise: T) -> Unit
val composedItems = keep in mind(this) mutableMapOf<T, @Composable () -> Unit>()
return merchandise: T ->
composedItems.getOrPut(merchandise)
movableContentOf rework(merchandise)
.invoke()

More Posts