Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Moved decelerationRate to props
  • Loading branch information
AdityaPahilwani committed Jul 4, 2021
commit 89fc9e3d69f43b7edbe36d77d0d497188f1248a0
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ declare module 'react-native-swiper' {
adjacentViewsWidth?: number
// It works like margin between the adjacent-view
adjacentViewsPadding?: number

decelerationRate?: 'fast' | 'normal' | number;
}

export default class Swiper extends Component<SwiperProps, SwiperState> {
Expand Down
18 changes: 10 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ const styles = {
// missing `module.exports = exports['default'];` with babel6
// export default React.createClass({

const decelerationRate = 0.7

export default class extends Component {
/**
* Props Validation
Expand Down Expand Up @@ -153,7 +151,11 @@ export default class extends Component {

showAdjacentViews: PropTypes.bool,
adjacentViewsWidth: PropTypes.number,
adjacentViewsPadding: PropTypes.number
adjacentViewsPadding: PropTypes.number,
decelerationRate: PropTypes.oneOfType([
PropTypes.number,
PropTypes.oneOf(['fast', 'normal'])
])
}

/**
Expand Down Expand Up @@ -185,7 +187,8 @@ export default class extends Component {

showAdjacentViews: false,
adjacentViewsWidth: 8,
adjacentViewsPadding: 4
adjacentViewsPadding: 4,
decelerationRate: 'normal'
}

/**
Expand Down Expand Up @@ -260,7 +263,7 @@ export default class extends Component {

// Support Optional render page
initState.children = Array.isArray(props.children)
? props.children.filter(child => child)
? props.children.filter((child) => child)
: props.children

initState.total = initState.children ? initState.children.length || 1 : 0
Expand Down Expand Up @@ -311,8 +314,8 @@ export default class extends Component {
let loopVal = this.props.loop ? 2 : 0
initState.offset[initState.dir] =
initState.dir === 'y'
? initState.height * (props.index + loopVal)
: initState.width * (props.index + loopVal);
? initState.height * (props.index + loopVal)
: initState.width * (props.index + loopVal)

this.internals = {
...this.internals,
Expand Down Expand Up @@ -896,7 +899,6 @@ export default class extends Component {
style={this.props.scrollViewStyle}
snapToOffsets={pages.map((x, i) => i * step - snappDiff)}
snapToAlignment={'center'}
decelerationRate={decelerationRate}
>
{pages}
</ScrollView>
Expand Down