-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathindex.js
206 lines (190 loc) · 8.18 KB
/
index.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import React, { Component } from 'react';
import { Platform, View, ScrollView, Text, StatusBar, SafeAreaView } from 'react-native';
import LinearGradient from 'react-native-linear-gradient';
import Carousel, { Pagination } from 'react-native-snap-carousel';
import { sliderWidth, itemWidth } from './styles/SliderEntry.style';
import SliderEntry from './components/SliderEntry';
import styles, { colors } from './styles/index.style';
import { ENTRIES1, ENTRIES2 } from './static/entries';
import { scrollInterpolators, animatedStyles } from './utils/animations';
const IS_ANDROID = Platform.OS === 'android';
const SLIDER_1_FIRST_ITEM = 1;
export default class example extends Component {
constructor (props) {
super(props);
this.state = {
slider1ActiveSlide: SLIDER_1_FIRST_ITEM
};
}
_renderItem ({item, index}) {
return <SliderEntry data={item} even={(index + 1) % 2 === 0} />;
}
_renderItemWithParallax ({item, index}, parallaxProps) {
return (
<SliderEntry
data={item}
even={(index + 1) % 2 === 0}
parallax={true}
parallaxProps={parallaxProps}
/>
);
}
_renderLightItem ({item, index}) {
return <SliderEntry data={item} even={false} />;
}
_renderDarkItem ({item, index}) {
return <SliderEntry data={item} even={true} />;
}
mainExample (number, title) {
const { slider1ActiveSlide } = this.state;
return (
<View style={styles.exampleContainer}>
<Text style={styles.title}>{`Example ${number}`}</Text>
<Text style={styles.subtitle}>{title}</Text>
<Carousel
ref={c => this._slider1Ref = c}
data={ENTRIES1}
renderItem={this._renderItemWithParallax}
sliderWidth={sliderWidth}
itemWidth={itemWidth}
hasParallaxImages={true}
firstItem={SLIDER_1_FIRST_ITEM}
inactiveSlideScale={0.94}
inactiveSlideOpacity={0.7}
// inactiveSlideShift={20}
containerCustomStyle={styles.slider}
contentContainerCustomStyle={styles.sliderContentContainer}
loop={true}
loopClonesPerSide={2}
autoplay={true}
autoplayDelay={500}
autoplayInterval={3000}
onSnapToItem={(index) => this.setState({ slider1ActiveSlide: index }) }
/>
<Pagination
dotsLength={ENTRIES1.length}
activeDotIndex={slider1ActiveSlide}
containerStyle={styles.paginationContainer}
dotColor={'rgba(255, 255, 255, 0.92)'}
dotStyle={styles.paginationDot}
inactiveDotColor={colors.black}
inactiveDotOpacity={0.4}
inactiveDotScale={0.6}
carouselRef={this._slider1Ref}
tappableDots={!!this._slider1Ref}
/>
</View>
);
}
momentumExample (number, title) {
return (
<View style={styles.exampleContainer}>
<Text style={styles.title}>{`Example ${number}`}</Text>
<Text style={styles.subtitle}>{title}</Text>
<Carousel
data={ENTRIES2}
renderItem={this._renderItem}
sliderWidth={sliderWidth}
itemWidth={itemWidth}
inactiveSlideScale={0.95}
inactiveSlideOpacity={1}
enableMomentum={true}
activeSlideAlignment={'start'}
containerCustomStyle={styles.slider}
contentContainerCustomStyle={styles.sliderContentContainer}
activeAnimationType={'spring'}
activeAnimationOptions={{
friction: 4,
tension: 40
}}
/>
</View>
);
}
layoutExample (number, title, type) {
const isTinder = type === 'tinder';
return (
<View style={[styles.exampleContainer, isTinder ? styles.exampleContainerDark : styles.exampleContainerLight]}>
<Text style={[styles.title, isTinder ? {} : styles.titleDark]}>{`Example ${number}`}</Text>
<Text style={[styles.subtitle, isTinder ? {} : styles.titleDark]}>{title}</Text>
<Carousel
data={isTinder ? ENTRIES2 : ENTRIES1}
renderItem={isTinder ? this._renderLightItem : this._renderItem}
sliderWidth={sliderWidth}
itemWidth={itemWidth}
containerCustomStyle={styles.slider}
contentContainerCustomStyle={styles.sliderContentContainer}
layout={type}
loop={true}
/>
</View>
);
}
customExample (number, title, refNumber, renderItemFunc) {
const isEven = refNumber % 2 === 0;
// Do not render examples on Android; because of the zIndex bug, they won't work as is
return !IS_ANDROID ? (
<View style={[styles.exampleContainer, isEven ? styles.exampleContainerDark : styles.exampleContainerLight]}>
<Text style={[styles.title, isEven ? {} : styles.titleDark]}>{`Example ${number}`}</Text>
<Text style={[styles.subtitle, isEven ? {} : styles.titleDark]}>{title}</Text>
<Carousel
data={isEven ? ENTRIES2 : ENTRIES1}
renderItem={renderItemFunc}
sliderWidth={sliderWidth}
itemWidth={itemWidth}
containerCustomStyle={styles.slider}
contentContainerCustomStyle={styles.sliderContentContainer}
scrollInterpolator={scrollInterpolators[`scrollInterpolator${refNumber}`]}
slideInterpolatedStyle={animatedStyles[`animatedStyles${refNumber}`]}
useScrollView={true}
/>
</View>
) : false;
}
get gradient () {
return (
<LinearGradient
colors={[colors.background1, colors.background2]}
startPoint={{ x: 1, y: 0 }}
endPoint={{ x: 0, y: 1 }}
style={styles.gradient}
/>
);
}
render () {
const example1 = this.mainExample(1, 'Default layout | Loop | Autoplay | Parallax | Scale | Opacity | Pagination with tappable dots');
const example2 = this.momentumExample(2, 'Momentum | Left-aligned | Active animation');
const example3 = this.layoutExample(3, '"Stack of cards" layout | Loop', 'stack');
const example4 = this.layoutExample(4, '"Tinder-like" layout | Loop', 'tinder');
const example5 = this.customExample(5, 'Custom animation 1', 1, this._renderItem);
const example6 = this.customExample(6, 'Custom animation 2', 2, this._renderLightItem);
const example7 = this.customExample(7, 'Custom animation 3', 3, this._renderDarkItem);
const example8 = this.customExample(8, 'Custom animation 4', 4, this._renderLightItem);
return (
<SafeAreaView style={styles.safeArea}>
<View style={styles.container}>
<StatusBar
translucent={true}
backgroundColor={'rgba(0, 0, 0, 0.3)'}
barStyle={'light-content'}
/>
{ this.gradient }
<ScrollView
style={styles.scrollview}
scrollEventThrottle={200}
directionalLockEnabled={true}
>
{ example1 }
{ example2 }
{ example3 }
{ example4 }
{ example5 }
{ example6 }
{ example7 }
{ example8 }
</ScrollView>
</View>
</SafeAreaView>
);
}
}