-
Notifications
You must be signed in to change notification settings - Fork 515
/
SnapTo.js
58 lines (56 loc) · 1.49 KB
/
SnapTo.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
import React, { Component } from 'react';
import { StyleSheet, View, Button } from 'react-native';
import Interactable from 'react-native-interactable';
export default class SnapTo extends Component {
constructor(props) {
super(props);
this.state = {
snapToIndex: 0
};
}
render() {
return (
<View style={styles.container}>
<Interactable.View
ref='headInstance'
snapPoints={[
{x: -140, y: -250},
{x: 140, y: -250},
{x: -140, y: -120},
{x: 140, y: -120},
{x: -140, y: 0},
{x: 140, y: 0},
{x: -140, y: 120},
{x: 140, y: 120},
{x: -140, y: 250},
{x: 140, y: 250}
]}
initialPosition={{x: 140, y: 250}}>
<View style={{width: 70, height: 70, backgroundColor: '#EE2C38', borderRadius: 35}} />
</Interactable.View>
<View style={styles.button}>
<Button title="Snap To Next" onPress={this.onButtonPress.bind(this)} color='white' />
</View>
</View>
);
}
onButtonPress() {
this.refs['headInstance'].snapTo({index: this.state.snapToIndex});
this.setState({
snapToIndex: (this.state.snapToIndex + 1)%10
});
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
},
button: {
position: 'absolute',
left: 110,
backgroundColor: '#459FED'
}
});