react-native-draggable-grid icon indicating copy to clipboard operation
react-native-draggable-grid copied to clipboard

Long press and not dragging makes the item stay selected

Open pedromartins-tk opened this issue 4 years ago • 9 comments

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

pedromartins-tk avatar Jul 30 '19 11:07 pedromartins-tk

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

SHISME avatar Jul 31 '19 02:07 SHISME

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

pedromartins-tk avatar Jul 31 '19 08:07 pedromartins-tk

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

SHISME avatar Aug 01 '19 01:08 SHISME

I just copied the version you have on the README file

pedromartins-tk avatar Aug 01 '19 09:08 pedromartins-tk

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

SHISME avatar Aug 05 '19 02:08 SHISME

@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

jqn avatar Sep 06 '19 09:09 jqn

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<BlockProps> = ({ style, dragStartAnimationStyle, onPress, onLongPress, onPressOut, children, panHandlers, }) => { return ( <Animated.View style={[styles.blockContainer, style, dragStartAnimationStyle]} {...panHandlers}> <Animated.View> <TouchableWithoutFeedback onPress={onPress} onLongPress={onLongPress} onPressOut={onPressOut}> {children} </TouchableWithoutFeedback> </Animated.View> </Animated.View> ) }

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 ( <Block onPress={onBlockPress.bind(null, itemIndex)} onLongPress={setActiveBlock.bind(null, itemIndex, item.itemData)} onPressOut={() => { if (!dragStarted) { onHandRelease(); } }} panHandlers={panResponder.panHandlers} style={getBlockStyle(itemIndex)} dragStartAnimationStyle={getDragStartAnimation(itemIndex)} key={item.key}> {props.renderItem(item.itemData, orderMap[item.key].order)} </Block> ) })

UI-Animation-Chen avatar May 20 '20 07:05 UI-Animation-Chen

anything update?

lyseiha avatar Sep 04 '20 04:09 lyseiha

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

This really helped me Thanks

decpk avatar Nov 25 '23 08:11 decpk