compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

Desktop: Issue with SelectionContainer

Open SaiNageswarS opened this issue 4 years ago • 1 comments

Error: Another selectable with the id has already subscribed.

I have a scrollable layout of cards. Each card has a SelectionContainer. When a new card is added, sometimes above error comes up.

Repo: https://github.com/SaiNageswarS/Omnishell https://github.com/SaiNageswarS/Omnishell/commit/7cd08d7bd9af67f092628c68f8073ff2b5df4364#diff-28887f92513afa6e17d8df16d0d200dffd5683d6d72764631bd850c85cfbee4dR19

Steps to reproduce:

  1. Run project using "gradle run"
  2. Enter date
  3. Enter ls
  4. Enter "npm init"
  5. After package.json is created, enter another command say "ls"

SaiNageswarS avatar May 08 '21 07:05 SaiNageswarS

I also encountered this issue in version 1.4.0-alpha01-dev1003. I added SelectionContainer to each item in LazyColumn.

exception stack

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Another selectable with the id: androidx.compose.foundation.text.selection.MultiWidgetSelectionDelegate@1040bc6d.selectableId has already subscribed.
	at androidx.compose.foundation.text.selection.SelectionRegistrarImpl.subscribe(SelectionRegistrarImpl.kt:105)
	at androidx.compose.foundation.text.TextController.onRemembered(CoreText.kt:501)
	at androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers(Composition.kt:1091)
	at androidx.compose.runtime.CompositionImpl.applyChangesInLocked(Composition.kt:818)
	at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:839)
	at androidx.compose.runtime.Recomposer.composeInitial$runtime(Recomposer.kt:978)
	at androidx.compose.runtime.ComposerImpl$CompositionContextImpl.composeInitial$runtime(Composer.kt:3848)
	at androidx.compose.runtime.ComposerImpl$CompositionContextImpl.composeInitial$runtime(Composer.kt:3848)
	at androidx.compose.runtime.ComposerImpl$CompositionContextImpl.composeInitial$runtime(Composer.kt:3848)
	at androidx.compose.runtime.ComposerImpl$CompositionContextImpl.composeInitial$runtime(Composer.kt:3848)
	at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:519)
	at androidx.compose.ui.layout.LayoutNodeSubcompositionsState.subcomposeInto(SubcomposeLayout.kt:468)
	at androidx.compose.ui.layout.LayoutNodeSubcompositionsState.subcompose(SubcomposeLayout.kt:441)
	at androidx.compose.ui.layout.LayoutNodeSubcompositionsState.subcompose(SubcomposeLayout.kt:432)
	at androidx.compose.ui.layout.LayoutNodeSubcompositionsState.subcompose(SubcomposeLayout.kt:421)
	at androidx.compose.ui.layout.LayoutNodeSubcompositionsState$Scope.subcompose(SubcomposeLayout.kt:733)
	at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1.invoke-0kLqBqw(BoxWithConstraints.kt:69)
	at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1.invoke(BoxWithConstraints.kt:67)
	at androidx.compose.ui.layout.LayoutNodeSubcompositionsState$createMeasurePolicy$1.measure-3p2s80s(SubcomposeLayout.kt:591)
	at androidx.compose.ui.node.InnerNodeCoordinator.measure-BRTryo0(InnerNodeCoordinator.kt:103)
	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasure$2.invoke(LayoutNodeLayoutDelegate.kt:1077)
	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasure$2.invoke(LayoutNodeLayoutDelegate.kt:1073)
	at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:2140)
	at androidx.compose.runtime.snapshots.SnapshotStateObserver$observeReads$1$1.invoke(SnapshotStateObserver.kt:134)
	at androidx.compose.runtime.snapshots.SnapshotStateObserver$observeReads$1$1.invoke(SnapshotStateObserver.kt:130)
	at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:341)
	at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(Unknown Source)
	at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:130)
	at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui(OwnerSnapshotObserver.kt:120)
	at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui(OwnerSnapshotObserver.kt:107)
	at androidx.compose.ui.node.LayoutNodeLayoutDelegate.performMeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:1073)
	at androidx.compose.ui.node.LayoutNodeLayoutDelegate.access$performMeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:36)
	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.remeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:341)
	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.measure-BRTryo0(LayoutNodeLayoutDelegate.kt:320)
	at androidx.compose.foundation.layout.RowColumnImplKt$rowColumnMeasurePolicy$1.measure-3p2s80s(RowColumnImpl.kt:89)
	at androidx.compose.ui.node.InnerNodeCoordinator.measure-BRTryo0(InnerNodeCoordinator.kt:103)
	at androidx.compose.foundation.layout.PaddingModifier.measure-3p2s80s(Padding.kt:364)
image

anye6488 avatar Apr 04 '23 01:04 anye6488

I also encountered this issue

jerryion avatar Jun 28 '23 07:06 jerryion

Compose 1.5.10-beta02. I encountered this but was able to fix it by wrapping only the individual widgets that needed to be selectable with SelectionContainer, rather than wrapping their parent container(s) with a single SelectionContainer.

wispborne avatar Oct 09 '23 03:10 wispborne

I've been running into this too, on iOS with 1.5.0-dev1357.

It looks like wrapping a SelectionContainer around a composable that has an AnimatedVisibility causes this to be thrown when the visibility changes.

zacharee avatar Jan 07 '24 01:01 zacharee

Also had the same error with SelectionContainer inside LazyColumn until the key for the items was specified correctly.

Example:

LazyColumn(modifier = Modifier.background(Color.White).fillMaxSize().padding(start = 5.dp, end = 12.dp), verticalArrangement = Arrangement.Bottom, state = chatHistoryListState) {
                val messageCardColor = Color(0xFFF7F4F4)
                val headerColor = Color(0xFF95C2F0)

                val contentLoaderCodec: Codec = contentLoaderCodec()

                items(clientStates.chatHistory, key = {it.id}) { message ->

                    Row(modifier = Modifier.fillMaxWidth())  {
                        //Adds items to the hierarchy of context menu items
                        ContextMenuDataProvider(items = { messageContextMenuItems(message, chatListUpdateScope) }) {
                            ChatIcon(encodedChatPhoto = message.senderPhoto, chatTitle = message.senderInfo, circleSize = 44.dp)
                            Spacer(Modifier.width(4.dp))
                            SelectionContainer {
                                Column {
                                    Text(text = message.senderInfo, fontWeight = FontWeight.Bold, fontSize = 12.sp, color = headerColor)
                                    Spacer(Modifier.height(4.dp))
                                    message.photoPreview?.let {
                                        MessagePhoto(it, contentLoaderCodec)
                                    }
                                    MessageTextCard(message, messageCardColor)
                                }
                            }
                        }
                    }

                    Spacer(modifier = Modifier.height(12.dp))

                }
            }

If I remove the key from the items and add the elements to the list, I get an error in some cases:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Another selectable with the id: androidx.compose.foundation.text.selection.MultiWidgetSelectionDelegate@1040bc6d.selectableId has already subscribed.

Hope it would be helpful. My compose-desktop version is 1.5.12.

p-vorobyev avatar Mar 23 '24 22:03 p-vorobyev