forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AttachmentCarousel: Add back "CarouselActions"
- Loading branch information
Showing
2 changed files
with
3 additions
and
77 deletions.
There are no files selected for viewing
78 changes: 1 addition & 77 deletions
78
src/components/AttachmentCarousel/CarouselActions/index.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,3 @@ | ||
import React, {Component} from 'react'; | ||
import {PanResponder, Dimensions, Animated} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '../../../styles/styles'; | ||
|
||
const propTypes = { | ||
/** Attachment that's rendered */ | ||
children: PropTypes.element.isRequired, | ||
|
||
/** Callback to fire when swiping left or right */ | ||
onCycleThroughAttachments: PropTypes.func.isRequired, | ||
|
||
/** Callback to handle a press event */ | ||
onPress: PropTypes.func.isRequired, | ||
|
||
/** Boolean to prevent a left swipe action */ | ||
canSwipeLeft: PropTypes.bool.isRequired, | ||
|
||
/** Boolean to prevent a right swipe action */ | ||
canSwipeRight: PropTypes.bool.isRequired, | ||
}; | ||
|
||
class Carousel extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.pan = new Animated.Value(0); | ||
|
||
this.panResponder = PanResponder.create({ | ||
onStartShouldSetPanResponder: () => true, | ||
|
||
onPanResponderMove: (event, gestureState) => Animated.event([null, { | ||
dx: this.pan, | ||
}], {useNativeDriver: false})(event, gestureState), | ||
|
||
onPanResponderRelease: (event, gestureState) => { | ||
if (gestureState.dx === 0 && gestureState.dy === 0) { | ||
return this.props.onPress(); | ||
} | ||
|
||
const deltaSlide = gestureState.dx > 0 ? 1 : -1; | ||
if (Math.abs(gestureState.vx) < 1 || (deltaSlide === 1 && !this.props.canSwipeLeft) || (deltaSlide === -1 && !this.props.canSwipeRight)) { | ||
return Animated.spring(this.pan, {useNativeDriver: false, toValue: 0}).start(); | ||
} | ||
|
||
const width = Dimensions.get('window').width; | ||
const slideLength = deltaSlide * (width * 1.1); | ||
Animated.timing(this.pan, {useNativeDriver: false, duration: 100, toValue: slideLength}).start(({finished}) => { | ||
if (!finished) { | ||
return; | ||
} | ||
|
||
this.props.onCycleThroughAttachments(-deltaSlide); | ||
this.pan.setValue(-slideLength); | ||
Animated.timing(this.pan, {useNativeDriver: false, duration: 100, toValue: 0}).start(); | ||
}); | ||
}, | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Animated.View | ||
style={[ | ||
styles.w100, | ||
styles.h100, | ||
{transform: [{translateX: this.pan}]}, | ||
]} | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...this.panResponder.panHandlers} | ||
> | ||
{this.props.children} | ||
</Animated.View> | ||
); | ||
} | ||
} | ||
|
||
Carousel.propTypes = propTypes; | ||
const Carousel = ({children}) => children; | ||
|
||
export default Carousel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters