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

Added enableInnerScroll prop #105

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,18 @@ With respect to bugfixes and further developments, please check the [To Do](http

### Card props

| Props | type | description | required | default |
| :-------------- | :------------- | :------------------------------------------------------------------- | :------- | :------ |
| cards | array | array of data for the cards to be rendered | required |
| renderCard | func(cardData, cardIndex) | function to render the card based on the data | required |
| keyExtractor | func(cardData) | function to get the card's react key | | null |
| cardIndex | number | cardIndex to start with | | 0 |
| infinite | bool | keep swiping indefinitely | | false |
| horizontalSwipe | bool | enable/disable horizontal swiping | | true |
| verticalSwipe | bool | enable/disable vertical swiping | | true |
| showSecondCard | bool | enable/disable second card while swiping | | true |
| stackSize | number | number of underlaying cards to show (showSecondCard must be enabled) | | 1 |
| Props | type | description | required | default |
| :-----------------| :------------- | :------------------------------------------------------------------- | :------- | :------ |
| cards | array | array of data for the cards to be rendered | required |
| renderCard | func(cardData, cardIndex) | function to render the card based on the data | | required |
| keyExtractor | func(cardData) | function to get the card's react key | | null |
| cardIndex | number | cardIndex to start with | | 0 |
| infinite | bool | keep swiping indefinitely | | false |
| horizontalSwipe | bool | enable/disable horizontal swiping | | true |
| verticalSwipe | bool | enable/disable vertical swiping | | true |
| showSecondCard | bool | enable/disable second card while swiping | | true |
| enableInnerScroll | bool | enable/disable vertical scroll inside the card | | false |
| stackSize | number | number of underlaying cards to show (showSecondCard must be enabled) | | 1 |

### Event callbacks

Expand Down
20 changes: 18 additions & 2 deletions Swiper.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,12 +757,24 @@ class Swiper extends Component {
}

pushCardToStack = (renderedCards, index, position, key, firstCard) => {
const { cards } = this.props
const { cards, onCardScroll } = this.props
const stackCardZoomStyle = this.calculateStackCardZoomStyle(position)
const stackCard = this.props.renderCard(cards[index], index)
const swipableCardStyle = this.calculateSwipableCardStyle()
const renderOverlayLabel = this.renderOverlayLabel()
renderedCards.push(
const card = this.props.enableInnerScroll ? (
<Animated.ScrollView
key={key}
style={firstCard ? swipableCardStyle : stackCardZoomStyle}
{...this._panResponder.panHandlers}
showsVerticalScrollIndicator={false}
contentContainerStyle={{ paddingBottom: 50 }}
onScroll={onCardScroll}
>
{firstCard ? renderOverlayLabel : null}
{stackCard}
</Animated.ScrollView>
):(
<Animated.View
key={key}
style={firstCard ? swipableCardStyle : stackCardZoomStyle}
Expand All @@ -772,6 +784,7 @@ class Swiper extends Component {
{stackCard}
</Animated.View>
)
renderedCards.push(card)
}

renderStack = () => {
Expand Down Expand Up @@ -875,6 +888,7 @@ Swiper.propTypes = {
disableLeftSwipe: PropTypes.bool,
disableRightSwipe: PropTypes.bool,
disableTopSwipe: PropTypes.bool,
enableInnerScroll: PropTypes.bool,
goBackToPreviousCardOnSwipeBottom: PropTypes.bool,
goBackToPreviousCardOnSwipeLeft: PropTypes.bool,
goBackToPreviousCardOnSwipeRight: PropTypes.bool,
Expand All @@ -891,6 +905,7 @@ Swiper.propTypes = {
keyExtractor: PropTypes.func,
marginBottom: PropTypes.number,
marginTop: PropTypes.number,
onCardScroll: PropTypes.func,
onSwiped: PropTypes.func,
onSwipedAborted: PropTypes.func,
onSwipedAll: PropTypes.func,
Expand Down Expand Up @@ -948,6 +963,7 @@ Swiper.defaultProps = {
disableLeftSwipe: false,
disableRightSwipe: false,
disableTopSwipe: false,
enableInnerScroll: false,
horizontalSwipe: true,
horizontalThreshold: width / 4,
goBackToPreviousCardOnSwipeBottom: false,
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare module 'react-native-deck-swiper' {
disableLeftSwipe?: boolean;
disableRightSwipe?: boolean;
disableTopSwipe?: boolean;
enableInnerScroll?: boolean;
horizontalSwipe?: boolean;
horizontalThreshold?: number;
goBackToPreviousCardOnSwipeBottom?: boolean;
Expand All @@ -31,6 +32,7 @@ declare module 'react-native-deck-swiper' {
keyExtractor?: (cardData: T) => string;
marginBottom?: number;
marginTop?: number;
onCardScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
onSwiped?: (cardIndex: number) => void;
onSwipedAborted?: () => void;
onSwipedAll?: () => void;
Expand Down