Mark
12/11/2024, 9:40 AMColumn
lays out its items such that a predefined composable (TextSelectionSeparator
) is inserted in between each one. Or perhaps modifying the ColumnScope
somehow?
SelectionContainer {
Column {
Text("111")
TextSelectionSeparator()
Text("222")
TextSelectionSeparator()
Text("333")
}
}
For use case see: https://issuetracker.google.com/issues/285036739marcinmoskala
12/11/2024, 10:31 AMKamilH
12/11/2024, 10:37 AMindex != last index
Stylianos Gakis
12/11/2024, 10:52 AMgmz
12/11/2024, 12:55 PMval composables = buildList<@Composable () -> Unit> {
if (whatever) {
add(
{
Text("Whatever")
}
)
}
// ...
}
for (composable in composables) {
// composable()
}
You can make it fancier and create a DSL similar to that of LazyList (which, not surprisingly, does something that resembles this)Mark
12/11/2024, 12:59 PMModifier
and ColumnScope
I thought it worth asking.Mark
12/11/2024, 1:27 PMclass SelectableColumnScope(columnScope: ColumnScope): ColumnScope by columnScope {
internal val items = mutableListOf<@Composable ColumnScope.() -> Unit>()
fun item(content: ColumnScope.() -> Unit) {
items.add(content)
}
}
@Composable
private fun TextSelectionSeparator(text: String = "\n") {
Text(
modifier = Modifier.sizeIn(maxWidth = 0.dp, maxHeight = 0.dp),
text = text
)
}
@Composable
fun SelectableColumn(
modifier: Modifier = Modifier,
verticalArrangement: Arrangement.Vertical = Arrangement.Top,
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
content: SelectableColumnScope.() -> Unit, // intentionally don't make composable
) {
SelectionContainer {
Column(
modifier = modifier,
verticalArrangement = verticalArrangement,
horizontalAlignment = horizontalAlignment,
) {
SelectableColumnScope(this).apply {
content()
items.forEachIndexed { index, item ->
if (index > 0) {
TextSelectionSeparator()
}
item()
}
}
}
}
}
@Preview
@Composable
fun ExampleColumnPreview(modifier: Modifier = Modifier) {
SelectableColumn {
item {
Text("111")
}
item {
Text("222")
}
item {
Text("333")
}
}
}
Halil Ozercan
12/11/2024, 1:49 PMLocalClipboardManager
and provide your own. Keep a reference to the existing one since you are going to delegate to it.
3. When ClipboardManager.setText
is called, find your annotations. Place the \n
where required. Then route the request to the original Clipboard
4. ...
5. Profit?Mark
12/12/2024, 7:05 AMHalil Ozercan
12/12/2024, 12:49 PMHalil Ozercan
12/12/2024, 12:50 PM