-
Notifications
You must be signed in to change notification settings - Fork 23
/
App.js
79 lines (70 loc) · 1.58 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React from 'react';
import {
StyleSheet,
View,
TouchableWithoutFeedback
} from 'react-native';
import CircleTransition from './CircleTransition';
import Swipe from './Swipe';
const screens = [{
id: 0,
bgcolor: '#698FB2'
}, {
id: 1,
bgcolor: '#68B0B3'
}, {
id: 2,
bgcolor: '#9B91BA'
}]
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
_counter: 0,
currentbg: screens[0].bgcolor
};
}
onSwipeLeft() {
const { _counter } = this.state;
let newCounter = _counter < screens.length - 1 ? _counter + 1 : 0;
this.swipeTo(newCounter);
}
onSwipeRight() {
const { _counter } = this.state;
let newCounter = _counter === 0 ? screens.length - 1 : _counter - 1;
this.swipeTo(newCounter);
}
swipeTo(counter) {
const newColor = screens[counter].bgcolor;
this.setState({
_counter: counter
}, () => {
this.circleTransition.start(newColor, this.changeColor.bind(this, newColor));
});
}
changeColor(newColor) {
this.setState({
currentbg: newColor,
});
}
render() {
return (
<Swipe
style={[styles.container, {backgroundColor: this.state.currentbg}]}
onSwipeLeft={this.onSwipeLeft.bind(this)}
onSwipeRight={this.onSwipeRight.bind(this)}
>
<CircleTransition
ref={(circle) => { this.circleTransition = circle }}
/>
</Swipe>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});