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

fix: ViewPropType is depreciated #943

Open
wants to merge 2 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"author": "Meliorence <contact@meliorence.com> (github.com/meliorence)",
"license": "BSD-3-Clause",
"dependencies": {
"deprecated-react-native-prop-types": "^2.3.0",
"prop-types": "^15.6.1",
"react-addons-shallow-compare": "15.6.2"
},
Expand Down
72 changes: 34 additions & 38 deletions src/carousel/Carousel.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import React, { Component } from 'react';
import { Animated, Easing, FlatList, I18nManager, Platform, ScrollView, View, ViewPropTypes } from 'react-native';
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import shallowCompare from 'react-addons-shallow-compare';
import { Animated, Easing, FlatList, I18nManager, Platform, ScrollView, View } from 'react-native';
import {
defaultScrollInterpolator,
stackScrollInterpolator,
tinderScrollInterpolator,
defaultAnimatedStyles,
shiftAnimatedStyles,
stackAnimatedStyles,
tinderAnimatedStyles
defaultAnimatedStyles, defaultScrollInterpolator, shiftAnimatedStyles,
stackAnimatedStyles, stackScrollInterpolator, tinderAnimatedStyles, tinderScrollInterpolator
} from '../utils/animations';

const IS_IOS = Platform.OS === 'ios';
Expand Down Expand Up @@ -263,7 +259,7 @@ export default class Carousel extends Component {
}

if (this.props.onScroll !== prevProps.onScroll) {
this._setScrollHandler(this.props);
this._setScrollHandler(this.props);
}
}

Expand Down Expand Up @@ -291,34 +287,34 @@ export default class Carousel extends Component {
return this._currentContentOffset;
}

_setScrollHandler(props) {
// Native driver for scroll events
const scrollEventConfig = {
listener: this._onScroll,
useNativeDriver: true,
};
this._scrollPos = new Animated.Value(0);
const argMapping = props.vertical
? [{ nativeEvent: { contentOffset: { y: this._scrollPos } } }]
: [{ nativeEvent: { contentOffset: { x: this._scrollPos } } }];
_setScrollHandler (props) {
// Native driver for scroll events
const scrollEventConfig = {
listener: this._onScroll,
useNativeDriver: true
};
this._scrollPos = new Animated.Value(0);
const argMapping = props.vertical ?
[{ nativeEvent: { contentOffset: { y: this._scrollPos } } }] :
[{ nativeEvent: { contentOffset: { x: this._scrollPos } } }];

if (props.onScroll && Array.isArray(props.onScroll._argMapping)) {
if (props.onScroll && Array.isArray(props.onScroll._argMapping)) {
// Because of a react-native issue https://github.com/facebook/react-native/issues/13294
argMapping.pop();
const [ argMap ] = props.onScroll._argMapping;
if (argMap && argMap.nativeEvent && argMap.nativeEvent.contentOffset) {
// Shares the same animated value passed in props
this._scrollPos =
argMapping.pop();
const [ argMap ] = props.onScroll._argMapping;
if (argMap && argMap.nativeEvent && argMap.nativeEvent.contentOffset) {
// Shares the same animated value passed in props
this._scrollPos =
argMap.nativeEvent.contentOffset.x ||
argMap.nativeEvent.contentOffset.y ||
this._scrollPos;
}
argMapping.push(...props.onScroll._argMapping);
}
argMapping.push(...props.onScroll._argMapping);
}
this._onScrollHandler = Animated.event(
argMapping,
scrollEventConfig
);
this._onScrollHandler = Animated.event(
argMapping,
scrollEventConfig
);
}

_needsScrollView () {
Expand Down Expand Up @@ -822,7 +818,7 @@ export default class Carousel extends Component {
this._repositionScroll(nextActiveItem);
}

if (typeof onScroll === "function" && event) {
if (typeof onScroll === 'function' && event) {
onScroll(event);
}
}
Expand All @@ -838,28 +834,28 @@ export default class Carousel extends Component {
}

_onTouchStart () {
const { onTouchStart } = this.props
const { onTouchStart } = this.props;

// `onTouchStart` is fired even when `scrollEnabled` is set to `false`
if (this._getScrollEnabled() !== false && this._autoplaying) {
this.pauseAutoPlay();
}

if (onTouchStart) {
onTouchStart()
onTouchStart();
}
}

_onTouchEnd () {
const { onTouchEnd } = this.props
const { onTouchEnd } = this.props;

if (this._getScrollEnabled() !== false && this._autoplay && !this._autoplaying) {
// This event is buggy on Android, so a fallback is provided in _onScrollEnd()
this.startAutoplay();
}

if (onTouchEnd) {
onTouchEnd()
onTouchEnd();
}
}

Expand Down Expand Up @@ -1354,7 +1350,7 @@ export default class Carousel extends Component {
...this._getComponentStaticProps()
};

const ScrollViewComponent = typeof useScrollView === 'function' ? useScrollView : AnimatedScrollView
const ScrollViewComponent = typeof useScrollView === 'function' ? useScrollView : AnimatedScrollView;

return this._needsScrollView() ? (
<ScrollViewComponent {...props}>
Expand Down
13 changes: 7 additions & 6 deletions src/pagination/Pagination.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { PureComponent } from 'react';
import { I18nManager, Platform, View, ViewPropTypes } from 'react-native';
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
import PropTypes from 'prop-types';
import PaginationDot from './PaginationDot';
import React, { PureComponent } from 'react';
import { I18nManager, Platform, View } from 'react-native';
import styles from './Pagination.style';
import PaginationDot from './PaginationDot';

const IS_IOS = Platform.OS === 'ios';
const IS_RTL = I18nManager.isRTL;
Expand Down Expand Up @@ -31,7 +32,7 @@ export default class Pagination extends PureComponent {
animatedDuration: PropTypes.number,
animatedFriction: PropTypes.number,
animatedTension: PropTypes.number,
delayPressInDot: PropTypes.number,
delayPressInDot: PropTypes.number
};

static defaultProps = {
Expand All @@ -42,7 +43,7 @@ export default class Pagination extends PureComponent {
animatedDuration: 250,
animatedFriction: 4,
animatedTension: 50,
delayPressInDot: 0,
delayPressInDot: 0
}

constructor (props) {
Expand Down Expand Up @@ -98,7 +99,7 @@ export default class Pagination extends PureComponent {
animatedDuration,
animatedFriction,
animatedTension,
delayPressInDot,
delayPressInDot
} = this.props;

if (renderDots) {
Expand Down
7 changes: 4 additions & 3 deletions src/pagination/PaginationDot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { PureComponent } from 'react';
import { View, Animated, Easing, TouchableOpacity, ViewPropTypes } from 'react-native';
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';
import { Animated, Easing, TouchableOpacity, View } from 'react-native';
import styles from './Pagination.style';

export default class PaginationDot extends PureComponent {
Expand Down Expand Up @@ -43,7 +44,7 @@ export default class PaginationDot extends PureComponent {

_animate (toValue = 0) {
const { animColor, animOpacity, animTransform } = this.state;
const { animatedDuration, animatedFriction, animatedTension } = this.props
const { animatedDuration, animatedFriction, animatedTension } = this.props;

const commonProperties = {
toValue,
Expand Down
5 changes: 3 additions & 2 deletions src/parallaximage/ParallaxImage.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Parallax effect inspired by https://github.com/oblador/react-native-parallax/

import React, { Component } from 'react';
import { View, ViewPropTypes, Image, Animated, Easing, ActivityIndicator, findNodeHandle } from 'react-native';
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { ActivityIndicator, Animated, Easing, findNodeHandle, Image, View } from 'react-native';
import styles from './ParallaxImage.style';

export default class ParallaxImage extends Component {
Expand Down