Skip to content

Commit 3407167

Browse files
committed
initial commit
0 parents  commit 3407167

File tree

14,440 files changed

+1379810
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

14,440 files changed

+1379810
-0
lines changed

Diff for: .babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["react-native"]
3+
}

Diff for: .buckconfig

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
[android]
3+
target = Google Inc.:Google APIs:23
4+
5+
[maven_repositories]
6+
central = https://repo1.maven.org/maven2

Diff for: .flowconfig

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[ignore]
2+
; We fork some components by platform
3+
.*/*[.]android.js
4+
5+
; Ignore "BUCK" generated dirs
6+
<PROJECT_ROOT>/\.buckd/
7+
8+
; Ignore unexpected extra "@providesModule"
9+
.*/node_modules/.*/node_modules/fbjs/.*
10+
11+
; Ignore duplicate module providers
12+
; For RN Apps installed via npm, "Libraries" folder is inside
13+
; "node_modules/react-native" but in the source repo it is in the root
14+
.*/Libraries/react-native/React.js
15+
.*/Libraries/react-native/ReactNative.js
16+
17+
[include]
18+
19+
[libs]
20+
node_modules/react-native/Libraries/react-native/react-native-interface.js
21+
node_modules/react-native/flow
22+
flow/
23+
24+
[options]
25+
emoji=true
26+
27+
module.system=haste
28+
29+
experimental.strict_type_args=true
30+
31+
munge_underscores=true
32+
33+
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
34+
35+
suppress_type=$FlowIssue
36+
suppress_type=$FlowFixMe
37+
suppress_type=$FixMe
38+
39+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(3[0-8]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
40+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(3[0-8]\\|1[0-9]\\|[1-2][0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
41+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
42+
43+
unsafe.enable_getters_and_setters=true
44+
45+
[version]
46+
^0.38.0

Diff for: .watchmanconfig

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

Diff for: Swiper.js

+241
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
import React from 'react';
2+
import {
3+
PanResponder,
4+
Slider,
5+
Text,
6+
View,
7+
Dimensions,
8+
Animated
9+
} from 'react-native'
10+
import styles, { circleSize } from './styles'
11+
const { height, width } = Dimensions.get('window')
12+
13+
class Swiper extends React.Component {
14+
constructor(props) {
15+
super(props)
16+
this.state = {
17+
pan: new Animated.ValueXY(),
18+
scale: new Animated.Value(props.secondCardZoom),
19+
firstCardIndex: props.cardIndex,
20+
secondCardIndex: props.cardIndex === props.cards.length - 1 ? 0 : props.cardIndex + 1,
21+
cards: props.cards,
22+
swipedAllCards: false
23+
}
24+
}
25+
26+
componentWillMount() {
27+
this._animatedValueX = 0;
28+
this._animatedValueY = 0;
29+
this.state.pan.x.addListener((value) => this._animatedValueX = value.value);
30+
this.state.pan.y.addListener((value) => this._animatedValueY = value.value);
31+
32+
this._panResponder = PanResponder.create({
33+
onMoveShouldSetResponderCapture: () => true,
34+
onMoveShouldSetPanResponderCapture: () => true,
35+
onPanResponderGrant: this.onPanResponderGrant,
36+
onPanResponderMove: Animated.event([
37+
null,
38+
{ dx: this.state.pan.x, dy: this.state.pan.y }
39+
]),
40+
onPanResponderRelease: this.onPanResponderRelease
41+
})
42+
}
43+
44+
onPanResponderGrant = (e, gestureState) => {
45+
this.state.pan.setOffset({
46+
x: this._animatedValueX,
47+
y: this._animatedValueY
48+
})
49+
this.state.pan.setValue({
50+
x: 0,
51+
y: 0
52+
})
53+
}
54+
55+
onPanResponderRelease = (e, gestureState) => {
56+
const { horizontalThreshold, verticalThreshold } = this.props
57+
let isSwipingRight = this._animatedValueX > horizontalThreshold || this._animatedValueY > verticalThreshold
58+
let isSwipingLeft = this._animatedValueX < -horizontalThreshold || this._animatedValueY < -verticalThreshold
59+
if (isSwipingLeft || isSwipingRight) {
60+
this.swipeCard1()
61+
} else {
62+
this.resetCard1()
63+
}
64+
}
65+
66+
resetCard1 = (cb) => {
67+
Animated.spring(
68+
this.state.pan, {
69+
toValue: 0
70+
}
71+
).start(cb)
72+
}
73+
74+
swipeCard1 = () => {
75+
Animated.timing(
76+
this.state.pan, {
77+
toValue: {
78+
x: this._animatedValueX * 4.5,
79+
y: this._animatedValueY * 4.5
80+
},
81+
duration: 350
82+
}
83+
).start(this.incrementCardIndex)
84+
Animated.spring(
85+
this.state.scale, {
86+
toValue: 1,
87+
duration: 100,
88+
}
89+
).start()
90+
}
91+
92+
incrementCardIndex = () => {
93+
this.setState((prevState) => {
94+
let swipedAllCards
95+
let newCardIndex = prevState.firstCardIndex + 1
96+
swipedAllCards = prevState.swipedAllCards
97+
if (newCardIndex > this.state.cards.length - 1) {
98+
newCardIndex = 0
99+
swipedAllCards = true
100+
this.props.onSwipedAll()
101+
}
102+
103+
this.props.onSwiped(newCardIndex)
104+
105+
return {
106+
...prevState,
107+
firstCardIndex: newCardIndex,
108+
secondCardIndex: newCardIndex === this.props.cards.length - 1 ? 0 : newCardIndex + 1,
109+
swipedAllCards: swipedAllCards
110+
}
111+
}, () => {
112+
this.state.pan.setValue({ x: 0, y: 0 });
113+
this.state.scale.setValue(this.props.secondCardZoom);
114+
})
115+
}
116+
117+
componentWillUnmount() {
118+
this.state.pan.x.removeAllListeners();
119+
this.state.pan.y.removeAllListeners();
120+
}
121+
122+
getCardStyles = () => {
123+
const { cardTopMargin, cardLeftMargin } = this.props
124+
let cardWidth = width - (cardLeftMargin * 2)
125+
let cardHeight = height - (cardTopMargin * 2)
126+
const cardStyle = {
127+
top: cardTopMargin,
128+
left: cardLeftMargin,
129+
width: cardWidth,
130+
height: cardHeight,
131+
position: 'absolute'
132+
}
133+
134+
const cardStyle1 = [
135+
styles.card,
136+
cardStyle,
137+
{
138+
zIndex: 2,
139+
transform: [{
140+
translateX: this.state.pan.x
141+
},
142+
{
143+
translateY: this.state.pan.y
144+
},
145+
{
146+
rotate: this.state.pan.x.interpolate({
147+
inputRange: this.props.inputRotationRange,
148+
outputRange: this.props.outputRotationRange
149+
})
150+
}
151+
]
152+
}
153+
]
154+
155+
const cardStyle2 = [
156+
styles.card,
157+
cardStyle,
158+
{
159+
zIndex: 1,
160+
transform: [{
161+
scale: this.state.scale
162+
}]
163+
}
164+
]
165+
166+
return [cardStyle1, cardStyle2]
167+
}
168+
169+
render() {
170+
const style1 = this.getCardStyles()[0]
171+
const style2 = this.getCardStyles()[1]
172+
const { cards, firstCardIndex, secondCardIndex } = this.state
173+
let firstCardContent = cards[firstCardIndex]
174+
let secondCardContent = cards[secondCardIndex]
175+
let firstCard = this.props.renderCard(firstCardContent)
176+
let secondCard = this.props.renderCard(secondCardContent)
177+
178+
if (!this.props.infinite) {
179+
if (secondCardIndex === 0) {
180+
secondCard = null
181+
}
182+
if (this.state.swipedAllCards) {
183+
firstCard = null
184+
secondCard = null
185+
}
186+
}
187+
188+
return (
189+
<View style = {
190+
[styles.container,
191+
{
192+
backgroundColor: this.props.backgroundColor
193+
}
194+
]}>
195+
<Animated.View
196+
style={style1}
197+
{...this._panResponder.panHandlers}>
198+
{firstCard}
199+
</Animated.View>
200+
<Animated.View
201+
style={style2}>
202+
{secondCard}
203+
</Animated.View>
204+
</View>
205+
)
206+
}
207+
}
208+
209+
Swiper.propTypes = {
210+
cards: React.PropTypes.array.isRequired,
211+
renderCard: React.PropTypes.func.isRequired,
212+
onSwipedAll: React.PropTypes.func,
213+
onSwiped: React.PropTypes.func,
214+
cardIndex: React.PropTypes.number,
215+
infinite: React.PropTypes.bool,
216+
verticalThreshold: React.PropTypes.number,
217+
horizontalThreshold: React.PropTypes.number,
218+
secondCardZoom: React.PropTypes.number,
219+
backgroundColor: React.PropTypes.string,
220+
outputRotationRange: React.PropTypes.array,
221+
inputRotationRange: React.PropTypes.array,
222+
cardTopMargin: React.PropTypes.number,
223+
cardLeftMargin: React.PropTypes.number,
224+
}
225+
226+
Swiper.defaultProps = {
227+
cardIndex: 0,
228+
onSwiped: (cardIndex) => { console.log(cardIndex) },
229+
onSwipedAll: () => { console.log('onSwipedAll') },
230+
infinite: false,
231+
verticalThreshold: height / 5,
232+
horizontalThreshold: width / 4,
233+
secondCardZoom: 0.97,
234+
backgroundColor: '#4FD0E9',
235+
cardTopMargin: 60,
236+
cardLeftMargin: 20,
237+
outputRotationRange: ["-10deg", "0deg", "10deg"],
238+
inputRotationRange: [-width / 2, 0, width / 2]
239+
}
240+
241+
export default Swiper

Diff for: index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Swiper from './Swiper'
2+
export default Swiper

Diff for: node_modules/.bin/acorn

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/babylon

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/cdl

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/errno

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/escodegen

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/esgenerate

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/esparse

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/esvalidate

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/handlebars

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/image-size

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/jest

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/jest-runtime

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/js-yaml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/jsesc

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/json5

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/loose-envify

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/marked

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/mime

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/mkdirp

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/notify

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/pegjs

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/react-native

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/regjsparser

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/rimraf

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/sane

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/semver

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/sshpk-conv

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/sshpk-sign

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/sshpk-verify

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/uglifyjs

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/uuid

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)