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

swipeDirectionCallback is not a function error #155 #156

Merged
merged 4 commits into from
May 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Exemples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"prop-types": "^15.5.10",
"react": "^16.2.0",
"react-native": "^0.49.5",
"react-native-deck-swiper": "^1.5.12"
"react-native-deck-swiper": "^1.5.13"
},
"devDependencies": {
"babel-jest": "19.0.0",
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,23 @@ const styles = StyleSheet.create({
}
});
```

## Updating props on card content? (dynamic card content)

Card properties may change, including on already swiped cards, which would yield no effects to users as the cards would no longer be displayed [based on [initial issue](https://github.com/alexbrillant/react-native-deck-swiper/issues/153)].

A possible fix for the situation is setting the _cardIndex_ on the parent component whenever deck re-renders are needed.

```
const { cardIndex } = this.props;
return (<Swiper
ref={swiper => {
{...customSwiperProps}
cardIndex={cardIndex}
}}
/>
```

Passing along the _cardIndex_ to the swiper will allow external changes on the property, thus triggering a re-render of the deck of cards. All _onSwipe_ callbacks return the _cardIndex_ that can be used to push the updated _cardIndex_ to app state (redux or something else).

By making sure that external changes on the cardIndex match those the swiper performs (increment on swipes, decrement on swipeBack) one can ensure no re-renders occur when not needed.
4 changes: 3 additions & 1 deletion Swiper.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,9 @@ class Swiper extends Component {
const previousCardIndex = this.state.firstCardIndex
this.props.onSwiped(previousCardIndex)

swipeDirectionCallback(previousCardIndex)
if (swipeDirectionCallback) {
swipeDirectionCallback(previousCardIndex)
}
if (swipedAllCards) {
this.props.onSwipedAll()
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-deck-swiper",
"version": "1.5.12",
"version": "1.5.13",
"description": "Awesome tinder like card swiper for react-native. Highly Customizable!",
"main": "index.js",
"scripts": {
Expand Down