forked from i6mi6/react-native-parallax-scroll-view
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Talks.js
183 lines (171 loc) · 4.73 KB
/
Talks.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* This example demonstrates how to use ParallaxScrollView within a ScrollView component.
*/
import React, { Component } from 'react';
import {
Dimensions,
Image,
ListView,
PixelRatio,
StyleSheet,
Text,
View,
} from 'react-native';
import ParallaxScrollView from 'react-native-parallax-scroll-view';
class Talks extends Component {
constructor(props) {
super(props);
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2
}).cloneWithRows([
'Simplicity Matters',
'Hammock Driven Development',
'Value of Values',
'Are We There Yet?',
'The Language of the System',
'Design, Composition, and Performance',
'Clojure core.async',
'The Functional Database',
'Deconstructing the Database',
'Hammock Driven Development',
'Value of Values'
])
};
}
render() {
const { onScroll = () => {} } = this.props;
return (
<ListView
ref="ListView"
style={styles.container}
dataSource={ this.state.dataSource }
renderRow={(rowData) => (
<View key={rowData} style={ styles.row }>
<Text style={ styles.rowText }>
{ rowData }
</Text>
</View>
)}
renderScrollComponent={props => (
<ParallaxScrollView
onScroll={onScroll}
headerBackgroundColor="#333"
stickyHeaderHeight={ STICKY_HEADER_HEIGHT }
parallaxHeaderHeight={ PARALLAX_HEADER_HEIGHT }
backgroundSpeed={10}
renderBackground={() => (
<View key="background">
<Image source={{uri: 'https://i.ytimg.com/vi/P-NZei5ANaQ/maxresdefault.jpg',
width: window.width,
height: PARALLAX_HEADER_HEIGHT}}/>
<View style={{position: 'absolute',
top: 0,
width: window.width,
backgroundColor: 'rgba(0,0,0,.4)',
height: PARALLAX_HEADER_HEIGHT}}/>
</View>
)}
renderForeground={() => (
<View key="parallax-header" style={ styles.parallaxHeader }>
<Image style={ styles.avatar } source={{
uri: 'https://pbs.twimg.com/profile_images/2694242404/5b0619220a92d391534b0cd89bf5adc1_400x400.jpeg',
width: AVATAR_SIZE,
height: AVATAR_SIZE
}}/>
<Text style={ styles.sectionSpeakerText }>
Talks by Rich Hickey
</Text>
<Text style={ styles.sectionTitleText }>
CTO of Cognitec, Creator of Clojure
</Text>
</View>
)}
renderStickyHeader={() => (
<View key="sticky-header" style={styles.stickySection}>
<Text style={styles.stickySectionText}>Rich Hickey Talks</Text>
</View>
)}
renderFixedHeader={() => (
<View key="fixed-header" style={styles.fixedSection}>
<Text style={styles.fixedSectionText}
onPress={() => this.refs.ListView.scrollTo({ x: 0, y: 0 })}>
Scroll to top
</Text>
</View>
)}/>
)}
/>
);
}
}
const window = Dimensions.get('window');
const AVATAR_SIZE = 120;
const ROW_HEIGHT = 60;
const PARALLAX_HEADER_HEIGHT = 350;
const STICKY_HEADER_HEIGHT = 70;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'black'
},
background: {
position: 'absolute',
top: 0,
left: 0,
width: window.width,
height: PARALLAX_HEADER_HEIGHT
},
stickySection: {
height: STICKY_HEADER_HEIGHT,
width: 300,
justifyContent: 'flex-end'
},
stickySectionText: {
color: 'white',
fontSize: 20,
margin: 10
},
fixedSection: {
position: 'absolute',
bottom: 10,
right: 10
},
fixedSectionText: {
color: '#999',
fontSize: 20
},
parallaxHeader: {
alignItems: 'center',
flex: 1,
flexDirection: 'column',
paddingTop: 100
},
avatar: {
marginBottom: 10,
borderRadius: AVATAR_SIZE / 2
},
sectionSpeakerText: {
color: 'white',
fontSize: 24,
paddingVertical: 5
},
sectionTitleText: {
color: 'white',
fontSize: 18,
paddingVertical: 5
},
row: {
overflow: 'hidden',
paddingHorizontal: 10,
height: ROW_HEIGHT,
backgroundColor: 'white',
borderColor: '#ccc',
borderBottomWidth: 1,
justifyContent: 'center'
},
rowText: {
fontSize: 20
}
});
export default Talks;