jemise111 / react-native-swipe-list-view

A React Native ListView component with rows that swipe open and closed
https://www.npmjs.com/package/react-native-swipe-list-view
MIT License
2.78k stars 528 forks source link

onPreview prop #535

Closed psdewar closed 3 years ago

psdewar commented 3 years ago

I would like to update state after a preview has occurred. Is there an easy way to do this (i.e. with a callback)?

jemise111 commented 3 years ago

Hey @psdewar2 a preview swipe is the same as a user generated swipe so you can use any of the regular callbacks (i.e. onRowDidClose, onRowClose, etc) see more here https://github.com/jemise111/react-native-swipe-list-view/blob/master/docs/SwipeListView.md

psdewar commented 3 years ago

Hey @jemise111 thanks for the info. Thinking about it further, the above scenario I described was a bit oversimplified. I want to update state meant to persist across sessions. In other words:

  1. A user who updates the app should see the preview
  2. When user closes the previewed row, this is an acknowledgement of the app update
  3. Some toggle (boolean state) is flipped so that a preview never happens again in any future sessions, since the app update has already been acknowledged from the user action of closing the row.

onRowDidClose, for example, would be called every time a user closes a row, which is not exactly ideal. I would have used previewFirstRow to take care of this, but it is deprecated. I could still use a toggle which would determine what the previewOpenValue would be (a non-zero value the first time, then zero all other times after that), but do you have any alternative suggestions?

psdewar commented 3 years ago

Also, none of these work as I expected when a preview occurs, but work perfectly when a swipe is done manually.

Is this by design?

jemise111 commented 3 years ago

@psdewar2 Oh man idk what happened the first time around but you're 100% right. Those props are not supported on a preview. I added a new prop that will hopefully take care of your issue called onPreviewEnd in v3.2.6. Here it is in action:

const onPreviewEnd = () => {
    console.log('onPreviewEnd');
};

return (
    <View style={styles.container}>
        <SwipeListView
            data={listData}
            renderItem={renderItem}
            renderHiddenItem={renderHiddenItem}
            leftOpenValue={75}
            rightOpenValue={-150}
            previewRowKey={'0'}
            previewOpenValue={-40}
            previewOpenDelay={3000}
            onRowDidOpen={onRowDidOpen}
            onPreviewEnd={onPreviewEnd}
        />
    </View>
);

https://user-images.githubusercontent.com/4265163/105635127-fd843400-5e26-11eb-848b-81d704e293ce.mov

psdewar commented 3 years ago

thanks man, this is exactly what I was looking for!

psdewar commented 3 years ago

@jemise111 could you add the prop to types for TypeScript support?