SHISME / react-native-draggable-grid

A draggable and sortable grid of react-native
320 stars 95 forks source link

Long press and not dragging makes the item stay selected #14

Open pedromartins-tk opened 5 years ago

pedromartins-tk commented 5 years ago

When i long press then item the animation goes on, but if i remove the touch and do not drag it, it does not return to the same place, in other words, it stays selected.

example

SHISME commented 5 years ago

You need an other way to drag or need keep the item selected after long press?

pedromartins-tk commented 5 years ago

The dragging is amazing. I need the item to return to place if, after a long press, i dont move it.

Those circles are taps on the screen showing that i removed the long press and drag action. It just stays there selected when i remove the finger/click

SHISME commented 5 years ago

ok, i know, could you show me your critical code

pedromartins-tk commented 5 years ago

I just copied the version you have on the README file

SHISME commented 5 years ago

sorry, i can't repeat the problem, could you try to set the onDragRelease, and check to see if it can trigger

jqn commented 5 years ago

@SHISME this issue happens mostly in android and the ios emulator. If you test it in an iOS device is not obvious. I'm thinking we need a way to figure out if the block wasn't dragged then reset back to its original place and position. I just haven't been able to figure that part out

UI-Animation-Chen commented 4 years ago

I really kown your issue, it occurs to me. I solved it by adding onPressOut callback in Block.

file block.tsx

export const Block: FunctionComponent = ({ style, dragStartAnimationStyle, onPress, onLongPress, onPressOut, children, panHandlers, }) => { return ( <Animated.View style={[styles.blockContainer, style, dragStartAnimationStyle]} {...panHandlers}>

{children} ) } file draggable-grid.tsx **_let dragStarted = false;_** function onStartDrag(nativeEvent: GestureResponderEvent, gestureState: PanResponderGestureState) { const activeItem = getActiveItem() if (!activeItem) return false **_dragStarted = true;_** props.onDragStart && props.onDragStart(activeItem.itemData) const { x0, y0, moveX, moveY } = gestureState const activeOrigin = blockPositions[orderMap[activeItem.key].order] const x = activeOrigin.x - x0 const y = activeOrigin.y - y0 activeItem.currentPosition.setOffset({ x, y, }) activeBlockOffset = { x, y, } activeItem.currentPosition.setValue({ x: moveX, y: moveY, }) } function setActiveBlock(itemIndex: number, item: DataType) { if (item.disabledDrag) return **_dragStarted = false;_** setPanResponderCapture(true) props.onDragWillStart && props.onDragWillStart(item); // added this line setActiveItemIndex(itemIndex) } const itemList = items.map((item, itemIndex) => { return ( { if (!dragStarted) { onHandRelease(); } }}_** panHandlers={panResponder.panHandlers} style={getBlockStyle(itemIndex)} dragStartAnimationStyle={getDragStartAnimation(itemIndex)} key={item.key}> {props.renderItem(item.itemData, orderMap[item.key].order)} ) })
lyseiha commented 4 years ago

anything update?

decpk commented 1 year ago

onPressOut={() => { if (!dragStarted) { onHandRelease(); } }}

This really helped me Thanks