Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite recomposition when state properties used in composition #147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kemalatli
Copy link

@kemalatli kemalatli commented Aug 21, 2022

Infinite recomposition occurs when state properties such as draggingItemTop and draggingItemLeft are called within composition. Usecase would be to subscribe on these values via LaunchedEffect to customize certain UI behavior like below.

val state = rememberReorderableLazyListState(onMove = vm::moveDog, canDragOver = vm::isDogDragEnabled)
LaunchedEffect(
        key1 = state.draggingItemKey,
        key2 = state.draggingItemTop,
        block = {
            Log.d("TAG", "NewVerticalReorderList: ${state.draggingItemTop}")
            if(state.draggingItemTop>50f){
                **// Do call custom logic in here... **
            }
        }
)
LazyColumn(
        state = state.listState,
        modifier = modifier
            .then(Modifier
                .reorderable(state)
                .detectReorderAfterLongPress(state))
)

Steps to reproduce this bug is to add the above LaunchedEffect in the sample project. This PR addresses the issue by simply checking the draggingItemKey existence. So that this value can only be fetched from draggingLayoutInfo only if there is an acitve dragged item.

Here is how hwui rendering looks like under infinite recomposition.

infinite-recomposition.mov

…ggingItemTop` values are used in composition
@bpappin
Copy link

bpappin commented Feb 2, 2024

I have cloned this PR into my own fork:
bpappin#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants