react-native-swipeable icon indicating copy to clipboard operation
react-native-swipeable copied to clipboard

When re-rendering a ListView of Swipeables after removing an item that is opened, the next item renders open

Open zznull opened this issue 8 years ago • 7 comments

I have a ListView where each item is a Swipeable. Each one has a leftButton that removes the item from the list. When the ListView is re-rendered, the following item starts open. The ListView is recreated in render(), triggered by state change from redux.

What could be causing this?

zznull avatar Sep 04 '17 12:09 zznull

Same issue with @zznull, not worked to set currentlyOpenSwipeable as null, and the ListView is re-rendered after deleted on item.

PanRu avatar Sep 25 '17 09:09 PanRu

@zznull Are you resolved this issue? I fixed it to use recenter() function.

For example as swipeable-example.js in current project, it not worked if you just set this.state.currentlyOpenSwipeable as null, but it worked to use this.state.currentlyOpenSwipeable.recenter();

PanRu avatar Sep 26 '17 07:09 PanRu

Same issue with @zznull. I also fixed it with a recenter function

tereshchenkoartyom94 avatar May 04 '18 15:05 tereshchenkoartyom94

@PanRu Thanks, I fixed this bug by your method here is my example:

_renderItem = () => {
    const { currentlyOpenSwipeable } = this.state;
    const rightButtons = [
      <TouchableOpacity onPress={() => 
          this.state.currentlyOpenSwipeable.recenter();
    }>
        <Text style={styles.delete}>delete</Text>
      </TouchableOpacity>
    ];

    const onOpen = (event, gestureState, swipeable) => {
      if (currentlyOpenSwipeable && currentlyOpenSwipeable !== swipeable) {
        currentlyOpenSwipeable.recenter();
      }

      this.setState({ currentlyOpenSwipeable: swipeable });
    };

    const onClose = () => currentlyOpenSwipeable.recenter();

    return (
      <View>
        <Swipeable
          rightButtons={rightButtons}
          onRightButtonsOpenRelease={onOpen}
          onRightButtonsCloseRelease={onClose}>
        </Swipeable>
      </View>
    )
}

by the way, English is not my first language :)

hankzhuo avatar Jun 25 '18 08:06 hankzhuo

+1 have the same issue

tomLadder avatar Sep 12 '18 08:09 tomLadder

just add key prop and it works.

for example:

return (
        <Swipeable
          key={id}
          rightButtons={rightButtons}
          onRightButtonsOpenRelease={onOpen}
          onRightButtonsCloseRelease={onClose}>
        </Swipeable>
    )

wilsonIs avatar Jul 04 '19 08:07 wilsonIs

@wilsonIs Comment helped a lot! Thank you

hraschan avatar Aug 02 '21 21:08 hraschan