Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(props) {
super(props);
if (process.env.NODE_ENV !== 'production') {
checkIndexBounds(props);
}
this.state = {
indexLatest: props.index,
// Set to true as soon as the component is swiping.
// It's the state counter part of this.isSwiping.
isDragging: false,
// Help with SSR logic and lazy loading logic.
renderOnlyActive: !props.disableLazyLoading,
heightLatest: 0,
// Let the render method that we are going to display the same slide than previously.
displaySameSlide: true,
};
this.setIndexCurrent(props.index);
}
componentWillReceiveProps(nextProps) {
const { index, animateTransitions } = nextProps;
if (typeof index === 'number' && index !== this.props.index) {
if (process.env.NODE_ENV !== 'production') {
checkIndexBounds(nextProps);
}
// If true, we are going to change the children. We shoudn't animate it.
const displaySameSlide = getDisplaySameSlide(this.props, nextProps);
if (animateTransitions && !displaySameSlide) {
this.setState(
{
indexLatest: index,
},
() => {
this.animateIndexCurrent(index);
},
);
} else {
this.setState({
UNSAFE_componentWillReceiveProps(nextProps) {
const { index } = nextProps;
if (typeof index === 'number' && index !== this.props.index) {
if (process.env.NODE_ENV !== 'production') {
checkIndexBounds(nextProps);
}
this.setIndexCurrent(index);
this.setState({
// If true, we are going to change the children. We shoudn't animate it.
displaySameSlide: getDisplaySameSlide(this.props, nextProps),
indexLatest: index,
});
}
}
componentWillReceiveProps(nextProps) {
const { index } = nextProps;
if (typeof index === 'number' && index !== this.props.index) {
if (process.env.NODE_ENV !== 'production') {
checkIndexBounds(nextProps);
}
// If true, we are going to change the children. We shoudn't animate it.
const displaySameSlide = getDisplaySameSlide(this.props, nextProps);
this.setState(
{
displaySameSlide,
indexLatest: index,
},
() => {
if (this.scrollViewNode) {
this.scrollViewNode.scrollTo({
x: this.state.viewWidth * index,
y: 0,
animated: this.props.animateTransitions && !displaySameSlide,
componentWillMount() {
if (process.env.NODE_ENV !== 'production') {
checkIndexBounds(this.props);
}
const { index = 0 } = this.props;
this.setState({
indexLatest: index,
indexCurrent: new Animated.Value(index),
viewLength: Dimensions.get('window').width,
});
this.panResponder = PanResponder.create({
// So it's working inside a Modal
onStartShouldSetPanResponder: () => true,
// Claim responder if it's a horizontal pan
onMoveShouldSetPanResponder: (event, gestureState) => {
const dx = Math.abs(gestureState.dx);
componentWillReceiveProps(nextProps) {
const { index } = nextProps;
if (typeof index === 'number' && index !== this.props.index) {
if (process.env.NODE_ENV !== 'production') {
checkIndexBounds(nextProps);
}
this.setIndexCurrent(index);
this.setState({
// If true, we are going to change the children. We shoudn't animate it.
displaySameSlide: getDisplaySameSlide(this.props, nextProps),
indexLatest: index,
});
}
}
componentWillMount() {
if (process.env.NODE_ENV !== 'production') {
checkIndexBounds(this.props);
}
const { index = 0 } = this.props;
this.setState({
indexLatest: index,
viewWidth: windowWidth,
offset: {
x: windowWidth * index,
y: 0,
},
});
if (this.props.animateHeight !== undefined) {
console.warn('react-swipeable-view-native: The animateHeight property is not implement yet.')
}