David Dupraz
06/02/2021, 8:25 PMBig Chungus
06/02/2021, 8:32 PMolonho
06/02/2021, 9:09 PMplease debug my code
) are not really the intended usage of this channel. Please localize your problem and if you believe it’s CfD bug - file an issue on https://github.com/JetBrains/compose-jb/issuesDavid Dupraz
06/03/2021, 7:50 AMIgor Demin
06/03/2021, 8:01 AM.pointerInput(key1 = null)
captures lambdas from the old recomposition (onDragEndUp/onDragEndDown)
It is a common mistake.
To fix it there two ways:
1. use rememberUpdatedState and use currentOnDragEndUp/currentOnDragEndDown instead of onDragEndUp/onDragEndDown
onDragEndUp: () -> Unit,
onDragEndDown: () -> Unit
) {
val currentOnDragEndUp by rememberUpdatedState(onDragEndUp)
val currentOnDragEndDown by rememberUpdatedState(onDragEndUp)
...
}
2. restart coroutine every time onDragEndUp/onDragEndDown changes (don't recommend, your loose state stored in coroutine)
.pointerInput(onDragEndUp, onDragEndDown ) {
detectDragGestures(
onDrag
...
Igor Demin
06/03/2021, 8:01 AMlocalize my problemIt is always difficult to the others to read not their own code, especially if the code is big. The most robust method to localize any issue in code - is to cut surrounding code / change data to stubs / remove unnecessary fancy decorations until the issue reproduces. If your code is small, then people would read it and can help. But if code is big then people usually will ignore it because it will take so much time to debug/find the issue.
David Dupraz
06/03/2021, 8:36 AMTo fix it there two ways:
1. use rememberUpdatedState
2. restart coroutine every time onDragEndUp/onDragEndDown changesThank you for the answer, but neither of these solutions solved my issue 😭 I edited the main file to make it a bit shorter.
olonho
06/03/2021, 9:00 AMDavid Dupraz
06/04/2021, 9:37 AMIgor Demin
06/04/2021, 9:52 AM@Composable
fun DisplayCard(
modifier: Modifier = Modifier,
card: PlayCard,
onDragEndUp: () -> Unit,
onDragEndDown: () -> Unit
) = key(card) {
When Compose recomposes its content after we change order of the cards, it thinks that some other card in the bottom row is the same card that was dragged.
To tell Compose that it isn't the same card we should use key
David Dupraz
06/04/2021, 10:54 AMDavid Dupraz
06/04/2021, 9:03 PM