-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
94 lines (89 loc) · 1.99 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React, { Component } from 'react'
import {
Animated,
StyleSheet,
View,
ListView,
Dimensions,
} from 'react-native'
import Card from './Card'
import cards from './mocks'
const AnimatedListView = Animated.createAnimatedComponent(ListView)
class App extends Component {
constructor(props) {
super(props)
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2})
this.state = {
dataSource: ds.cloneWithRows(cards),
bigMode: false
}
}
getListViewStyle = () => {
const cardsToFit = this.state.bigMode ? 1 : 2
const scale = 1 / cardsToFit
return [
styles.container,
{
width: Dimensions.get('window').width * cardsToFit
},
{
transform: [
{
scale
}
],
}
];
}
toggleBigMode = index => {
const bigMode = !this.state.bigMode
const windowWidth = Dimensions.get('window').width
const position =
!bigMode
? index <= 1
? 0
: (index % 2) !== 0
? (index - 1) * windowWidth
: index * windowWidth
: index * windowWidth
this.setState({
bigMode
}, () => {
this.refs.scrollView._component.scrollTo({x: position})
})
}
render() {
return (
<View style={styles.box}>
<AnimatedListView
key={this.state.bigMode}
horizontal={true}
pagingEnabled={true}
ref="scrollView"
style={this.getListViewStyle()}
dataSource={this.state.dataSource}
renderRow={(rowData, key, index) =>
<Card
bigMode={this.state.bigMode}
onPress={this.toggleBigMode}
key={key}
index={index}
data={rowData}
/>
}
/>
</View>
);
}
}
const styles = StyleSheet.create({
box: {
flex: 1,
backgroundColor: '#0F1419',
alignItems:'center',
},
container: {
flex: 1,
},
});
export default App