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

Feature request: Haptic feedback (vibration) #226

Open
elad-nanit opened this issue Feb 27, 2023 · 10 comments
Open

Feature request: Haptic feedback (vibration) #226

elad-nanit opened this issue Feb 27, 2023 · 10 comments

Comments

@elad-nanit
Copy link

Please add a haptic feedback (vibration) when item is long pressed and ready to be dragged.

@ShayDeeJay
Copy link

Please add a haptic feedback (vibration) when item is long pressed and ready to be dragged.

im sure you probably already know this, but you can add this feature manually.

@CiprianGabor
Copy link

CiprianGabor commented Mar 5, 2023

Where I can add the haptic feedback?

LazyColumn(
        state = state.listState,
        modifier = Modifier
            .reorderable(state)
            .detectReorderAfterLongPress(state)
    ) {
        items(data.value.size, { data.value[it] }) { item ->
            ReorderableItem(state, key = item) { isDragging ->
                val elevation = animateDpAsState(if (isDragging) 46.dp else 0.dp)
                Column(
                    modifier = Modifier
                        .shadow(elevation.value)
                        .background(MaterialTheme.colorScheme.surface)
                ) {
                    ShowCategoryDivider(data.value[item])
                }
            }
        }
    }

@ShayDeeJay
Copy link

ShayDeeJay commented Mar 7, 2023

ReorderableItem(state, key = items.key) { isDragging ->
if (isDragging) haptic.performHapticFeedback(
HapticFeedbackType.LongPress
)

@CiprianGabor
Copy link

CiprianGabor commented Mar 7, 2023

It does not work. isDragging is always false

@ShayDeeJay
Copy link

add detect reorder to the column

@CiprianGabor
Copy link

Like this?

LazyColumn(
        state = state.listState,
        modifier = Modifier
            .reorderable(state)
            .detectReorderAfterLongPress(state)
    ) {
        items(data.value.size, { data.value[it] }) { item ->
            ReorderableItem(state, key = item) {  isDragging ->
                if (isDragging) haptic.performHapticFeedback(
                    HapticFeedbackType.LongPress
                )
                val elevation = animateDpAsState(if (isDragging) 46.dp else 0.dp)
                Column(
                    modifier = Modifier
                        .shadow(elevation.value)
                        .background(MaterialTheme.colorScheme.surface)
                        .detectReorderAfterLongPress(state)
                ) {
                    ShowCategoryDivider(data.value[item])
                }
            }
        }
    }

@ShayDeeJay
Copy link

ShayDeeJay commented Mar 7, 2023

yes, and remove from lazy column

@CiprianGabor
Copy link

Like this? It wont work

LazyColumn(
        state = state.listState,
        modifier = Modifier
            .reorderable(state)
    ) {
        items(data.value.size, { data.value[it] }) { item ->
            ReorderableItem(state, key = item) { isDragging ->
                if (isDragging) haptic.performHapticFeedback(
                    HapticFeedbackType.LongPress
                )
                val elevation = animateDpAsState(if (isDragging) 46.dp else 0.dp)
                Column(
                    modifier = Modifier
                        .shadow(elevation.value)
                        .background(MaterialTheme.colorScheme.surface)
                        .detectReorderAfterLongPress(state)
                        .animateItemPlacement( animationSpec = tween( durationMillis = 100, easing = FastOutSlowInEasing ) )
                ) {
                    ShowCategoryDivider(data.value[item])
                }
            }
        }
    }

@CiprianGabor
Copy link

@aclassen @shadyeejay @warting Any idea?
Have a nice day!

@CiprianGabor
Copy link

CiprianGabor commented Mar 16, 2023

The problem was with the items(size) function, you have to use items(list) in order to work.

this will work:

LazyColumn(
        state = state.listState,
        modifier = Modifier
            .reorderable(state)
            .detectReorderAfterLongPress(state)
    ) {
        items(data.value, { it }) { item ->
            ReorderableItem(state, key = item) { isDragging ->
                if (isDragging) haptic.performHapticFeedback(
                    HapticFeedbackType.LongPress
                )
                val elevation = animateDpAsState(if (isDragging) 50.dp else 0.dp)
                Column(
                    modifier = Modifier
                        .shadow(elevation.value)
                        .background(MaterialTheme.colorScheme.surface)
                ) {
                    ShowCategoryDivider(item)
                }
            }
        }
    }

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

No branches or pull requests

3 participants